Skip to content

Commit fc7205c

Browse files
ankpshahtjleing
andauthored
fix(datastore): Update Model Class Check in getMutationForModelId() from using ModelSchema class name to mutatedItem modelName (#2637)
Co-authored-by: Thomas Leing <[email protected]>
1 parent ebd8565 commit fc7205c

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

aws-datastore/src/main/java/com/amplifyframework/datastore/syncengine/Merger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ <T extends Model> Completable merge(
103103
.flatMapCompletable(shouldMerge -> {
104104
Completable firstStep;
105105
if (mutationOutbox.hasPendingMutation(model.getPrimaryKeyString(),
106-
model.getClass().getName())) {
106+
model.getModelName())) {
107107
LOG.info("Mutation outbox has pending mutation for Model: " +
108108
model.getModelName() + " with primary key: " + model.resolveIdentifier()
109109
+ ". Saving the metadata, but not model itself.");

aws-datastore/src/main/java/com/amplifyframework/datastore/syncengine/PersistentMutationOutbox.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ PendingMutation<? extends Model> getMutationForModelId(@NonNull String modelId,
9999
try {
100100
PendingMutation.PersistentRecord persistentRecord = results.next();
101101
PendingMutation<?> pendingMutation = converter.fromRecord(persistentRecord);
102-
if (pendingMutation.getModelSchema().getModelClass().getName().equals(modelClass)) {
102+
if (pendingMutation.getModelSchema().getName().equals(modelClass)) {
103103
mutationResult.set(pendingMutation);
104104
}
105105
} catch (Throwable throwable) {
@@ -153,7 +153,7 @@ public <T extends Model> Completable enqueue(@NonNull PendingMutation<T> incomin
153153
// If there is no existing mutation for the model, then just apply the incoming
154154
// mutation, and be done with this.
155155
String modelId = incomingMutation.getMutatedItem().getPrimaryKeyString();
156-
String modelClass = incomingMutation.getModelSchema().getModelClass().getName();
156+
String modelClass = incomingMutation.getMutatedItem().getModelName();
157157
@SuppressWarnings("unchecked")
158158
PendingMutation<T> existingMutation = (PendingMutation<T>) getMutationForModelId(modelId, modelClass);
159159
if (existingMutation == null || inFlightMutations.contains(existingMutation.getMutationId())) {

aws-datastore/src/test/java/com/amplifyframework/datastore/syncengine/MutationProcessorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public void canDrainMutationOutbox() throws DataStoreException {
178178

179179
// And that it is no longer in the outbox.
180180
assertFalse(mutationOutbox.hasPendingMutation(tony.getPrimaryKeyString(),
181-
tony.getClass().getName()));
181+
tony.getClass().getSimpleName()));
182182

183183
// And that it was passed to AppSync for publication.
184184
verify(appSync).create(eq(tony), any(), any(), any());

aws-datastore/src/test/java/com/amplifyframework/datastore/syncengine/PersistentMutationOutboxTest.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public void enqueuePersistsMutationAndNotifiesObserver() throws DataStoreExcepti
147147
Collections.singletonList(converter.toRecord(createJameson)),
148148
storage.query(PersistentRecord.class)
149149
);
150-
assertTrue(mutationOutbox.hasPendingMutation(jameson.getId(), jameson.getClass().getName()));
150+
assertTrue(mutationOutbox.hasPendingMutation(jameson.getId(), jameson.getClass().getSimpleName()));
151151
assertEquals(createJameson, mutationOutbox.peek());
152152
}
153153

@@ -208,8 +208,8 @@ public void loadPreparesOutbox() throws DataStoreException, InterruptedException
208208
loadObserver.dispose();
209209

210210
// Assert: items are in the outbox.
211-
assertTrue(mutationOutbox.hasPendingMutation(tony.getId(), tony.getClass().getName()));
212-
assertTrue(mutationOutbox.hasPendingMutation(sam.getId(), sam.getClass().getName()));
211+
assertTrue(mutationOutbox.hasPendingMutation(tony.getId(), tony.getClass().getSimpleName()));
212+
assertTrue(mutationOutbox.hasPendingMutation(sam.getId(), sam.getClass().getSimpleName()));
213213

214214
// Tony is first, since he is the older of the two mutations.
215215
assertEquals(updateTony, mutationOutbox.peek());
@@ -240,7 +240,7 @@ public void removeRemovesChangesFromQueue() throws DataStoreException, Interrupt
240240
assertEquals(0, storage.query(PersistentRecord.class).size());
241241

242242
assertNull(mutationOutbox.peek());
243-
assertFalse(mutationOutbox.hasPendingMutation(bill.getId(), bill.getClass().getName()));
243+
assertFalse(mutationOutbox.hasPendingMutation(bill.getId(), bill.getClass().getSimpleName()));
244244
}
245245

246246
/**
@@ -330,8 +330,8 @@ public void hasPendingMutationReturnsTrueForExistingModelMutation() {
330330
boolean completed = mutationOutbox.enqueue(pendingMutation).blockingAwait(TIMEOUT_MS, TimeUnit.MILLISECONDS);
331331

332332
assertTrue(completed);
333-
assertTrue(mutationOutbox.hasPendingMutation(modelId, joe.getClass().getName()));
334-
assertFalse(mutationOutbox.hasPendingMutation(mutationId.toString(), mutationId.getClass().getName()));
333+
assertTrue(mutationOutbox.hasPendingMutation(modelId, joe.getClass().getSimpleName()));
334+
assertFalse(mutationOutbox.hasPendingMutation(mutationId.toString(), mutationId.getClass().getSimpleName()));
335335
}
336336

337337
/**
@@ -357,9 +357,9 @@ public void hasPendingMutationReturnsFalseForItemNotInStore() throws DataStoreEx
357357
mutationId, joe, schema, PendingMutation.Type.CREATE, QueryPredicates.all()
358358
);
359359

360-
assertFalse(mutationOutbox.hasPendingMutation(joeId, joe.getClass().getName()));
360+
assertFalse(mutationOutbox.hasPendingMutation(joeId, joe.getClass().getSimpleName()));
361361
assertFalse(mutationOutbox.hasPendingMutation(unrelatedMutation.getMutationId().toString(),
362-
unrelatedMutation.getClass().getName()));
362+
unrelatedMutation.getClass().getSimpleName()));
363363
}
364364

365365
/**
@@ -385,7 +385,7 @@ public void hasPendingMutationReturnsFalseForModelMutationWithSamePrimaryKeyForD
385385

386386
// Act & Assert: Enqueue and verify BlogOwner
387387
assertTrue(mutationOutbox.enqueue(pendingBlogOwnerMutation).blockingAwait(TIMEOUT_MS, TimeUnit.MILLISECONDS));
388-
assertTrue(mutationOutbox.hasPendingMutation(modelId, blogOwner.getClass().getName()));
388+
assertTrue(mutationOutbox.hasPendingMutation(modelId, blogOwner.getClass().getSimpleName()));
389389

390390
// Act & Assert: Enqueue and verify Author
391391
Author author = Author.builder()
@@ -394,7 +394,7 @@ public void hasPendingMutationReturnsFalseForModelMutationWithSamePrimaryKeyForD
394394
.build();
395395

396396
// Check hasPendingMutation returns False for Author with same Primary Key (id) as BlogOwner
397-
assertFalse(mutationOutbox.hasPendingMutation(modelId, author.getClass().getName()));
397+
assertFalse(mutationOutbox.hasPendingMutation(modelId, author.getClass().getSimpleName()));
398398

399399
PendingMutation<Author> pendingAuthorMutation = PendingMutation.instance(
400400
mutationId, author, ModelSchema.fromModelClass(Author.class),
@@ -403,7 +403,7 @@ public void hasPendingMutationReturnsFalseForModelMutationWithSamePrimaryKeyForD
403403
assertTrue(mutationOutbox.enqueue(pendingAuthorMutation).blockingAwait(TIMEOUT_MS, TimeUnit.MILLISECONDS));
404404

405405
// Make sure Author Mutation is stored
406-
assertTrue(mutationOutbox.hasPendingMutation(modelId, author.getClass().getName()));
406+
assertTrue(mutationOutbox.hasPendingMutation(modelId, author.getClass().getSimpleName()));
407407

408408
// Act & Assert: Enqueue and verify Author
409409
Post post = Post.builder()
@@ -414,7 +414,7 @@ public void hasPendingMutationReturnsFalseForModelMutationWithSamePrimaryKeyForD
414414
.build();
415415

416416
// Check hasPendingMutation returns False for Post with same Primary Key (id) as BlogOwner
417-
assertFalse(mutationOutbox.hasPendingMutation(modelId, post.getClass().getName()));
417+
assertFalse(mutationOutbox.hasPendingMutation(modelId, post.getClass().getSimpleName()));
418418

419419
PendingMutation<Post> pendingPostMutation = PendingMutation.instance(
420420
mutationId, post, ModelSchema.fromModelClass(Post.class),
@@ -423,7 +423,7 @@ public void hasPendingMutationReturnsFalseForModelMutationWithSamePrimaryKeyForD
423423
assertTrue(mutationOutbox.enqueue(pendingPostMutation).blockingAwait(TIMEOUT_MS, TimeUnit.MILLISECONDS));
424424

425425
// Make sure Post Mutation is stored
426-
assertTrue(mutationOutbox.hasPendingMutation(modelId, post.getClass().getName()));
426+
assertTrue(mutationOutbox.hasPendingMutation(modelId, post.getClass().getSimpleName()));
427427
}
428428

429429
/**
@@ -474,7 +474,7 @@ public void mutationEnqueueForModelWithDuplicatePrimaryKeyThrowsDatastoreExcepti
474474

475475
// Additional Checks: Peek the Mutation outbox, existing mutation should be present.
476476
assertTrue(mutationOutbox.hasPendingMutation(existingBlogOwner.getPrimaryKeyString(),
477-
existingBlogOwner.getClass().getName()));
477+
existingBlogOwner.getClass().getSimpleName()));
478478
assertEquals(existingCreation, mutationOutbox.peek());
479479
}
480480

@@ -521,7 +521,7 @@ public void existingCreationIncomingCreationYieldsError() throws AmplifyExceptio
521521

522522
// Existing mutation still attainable as next mutation (right now, its the ONLY mutation in outbox)
523523
assertTrue(mutationOutbox.hasPendingMutation(modelInExistingMutation.getPrimaryKeyString(),
524-
modelInExistingMutation.getClass().getName()));
524+
modelInExistingMutation.getClass().getSimpleName()));
525525
assertEquals(existingCreation, mutationOutbox.peek());
526526
}
527527

@@ -567,7 +567,7 @@ public void existingUpdateIncomingCreationYieldsError() throws AmplifyException,
567567

568568
// Existing mutation still attainable as next mutation (right now, its the ONLY mutation in outbox)
569569
assertTrue(mutationOutbox.hasPendingMutation(modelInExistingMutation.getPrimaryKeyString(),
570-
modelInExistingMutation.getClass().getName()));
570+
modelInExistingMutation.getClass().getSimpleName()));
571571
assertEquals(existingUpdate, mutationOutbox.peek());
572572
}
573573

@@ -614,7 +614,7 @@ public void existingDeletionIncomingCreationYieldsError() throws AmplifyExceptio
614614

615615
// Existing mutation still attainable as next mutation (right now, its the ONLY mutation in outbox)
616616
assertTrue(mutationOutbox.hasPendingMutation(modelInExistingMutation.getPrimaryKeyString(),
617-
modelInExistingMutation.getClass().getName()));
617+
modelInExistingMutation.getClass().getSimpleName()));
618618
assertEquals(existingDeletion, mutationOutbox.peek());
619619
}
620620

@@ -660,7 +660,7 @@ public void existingDeletionIncomingUpdateYieldsError() throws AmplifyException,
660660

661661
// Existing mutation still attainable as next mutation (right now, its the ONLY mutation in outbox)
662662
assertTrue(mutationOutbox.hasPendingMutation(modelInExistingMutation.getPrimaryKeyString(),
663-
modelInExistingMutation.getClass().getName()));
663+
modelInExistingMutation.getClass().getSimpleName()));
664664
assertEquals(existingDeletion, mutationOutbox.peek());
665665
}
666666

@@ -1186,7 +1186,7 @@ public void nextItemForModelIdReturnsFirstEnqueued() throws DataStoreException {
11861186
assertTrue(completed);
11871187
assertEquals(
11881188
firstMutation,
1189-
mutationOutbox.getMutationForModelId(originalJoe.getId(), originalJoe.getClass().getName())
1189+
mutationOutbox.getMutationForModelId(originalJoe.getId(), originalJoe.getClass().getSimpleName())
11901190
);
11911191
}
11921192

0 commit comments

Comments
 (0)