Skip to content

Commit

Permalink
Update lastUpdated field along with embedded fields. #5
Browse files Browse the repository at this point in the history
  • Loading branch information
ankit-agrawal11 committed Mar 27, 2018
1 parent b9b2e8b commit a9dc52b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,11 @@ class EmbeddedInstanceQueueService {

Map embeddedMap = sourceDomainInstance.embeddedInstance.toMap()

boolean hasLastUpdatedField = classToUpdate.declaredFields?.name?.contains('lastUpdated')

Map query = [(fieldToMatch): sourceDomainInstance.id]
Map updateOperation = [(MongoConstants.SET_OPERATOR): [(fieldToUpdate): embeddedMap]]
Map updateOperation = [(MongoConstants.SET_OPERATOR): hasLastUpdatedField ?
[(fieldToUpdate): embeddedMap, 'lastUpdated': new Date()] : [(fieldToUpdate): embeddedMap]]

log.debug "Match query: $query, Update operation: $updateOperation and update data: $embeddedMap"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class EmbeddedInstanceQueueServiceSpec extends Specification implements BaseTest
testDomainBInstance.refresh().testDomainA.testField1 == 'Update test field 1'
}

@ConfineMetaClassChanges([TestDomainB])
@ConfineMetaClassChanges([TestDomainB, TestDomainC])
void 'test for marking EmbeddedQueueInstance status as FAILED when 3 attempts fails to update it'() {
given: 'An instance of TestDomainA'
TestDomainA testDomainAInstance = createTestDomainA()
Expand All @@ -165,7 +165,13 @@ class EmbeddedInstanceQueueServiceSpec extends Specification implements BaseTest

and: 'Mocked lower level update call to throw exception'
TestDomainB.metaClass.'static'.getCollection = {
return ['update': { Map query, Map update, Map options ->
return ['updateMany': { Map query, Map update, Map options ->
throw new IllegalArgumentException()
} ]
}

TestDomainC.metaClass.'static'.getCollection = {
return ['updateMany': { Map query, Map update, Map options ->
throw new IllegalArgumentException()
} ]
}
Expand Down

0 comments on commit a9dc52b

Please sign in to comment.