use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class MutationProcessorTest method outboxStatusIsPublishedToHubOnProcess.
/**
* Processing a mutation should publish current outbox status.
*/
@Test
public void outboxStatusIsPublishedToHubOnProcess() {
BlogOwner raphael = BlogOwner.builder().name("Raphael Kim").build();
ModelSchema schema = schemaRegistry.getModelSchemaForModelClass(BlogOwner.class);
PendingMutation<BlogOwner> createRaphael = PendingMutation.creation(raphael, schema);
// Mock up a response from AppSync and enqueue a mutation.
AppSyncMocking.create(appSync).mockSuccessResponse(raphael);
assertTrue(mutationOutbox.enqueue(createRaphael).blockingAwait(TIMEOUT_SECONDS, TimeUnit.SECONDS));
// Start listening for publication events.
// outbox should be empty after processing its only mutation
HubAccumulator statusAccumulator = HubAccumulator.create(HubChannel.DATASTORE, isOutboxEmpty(true), 1).start();
// Start draining the outbox which has one mutation enqueued,
// and make sure that outbox status is published to hub.
mutationProcessor.startDrainingMutationOutbox();
statusAccumulator.await();
}
use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class MutationProcessorTest method hubEventPublishedForPublicationError.
/**
* If the AppSync response to the mutation contains not-empty GraphQLResponse error
* list without any ConflictUnhandled error, then
* {@link DataStoreChannelEventName#OUTBOX_MUTATION_FAILED} event is published via Hub.
* @throws DataStoreException On failure to save model and metadata
*/
@Test
public void hubEventPublishedForPublicationError() throws DataStoreException {
// Save a model, its metadata, and its last sync data.
BlogOwner model = BlogOwner.builder().name("Average Joe").build();
ModelMetadata metadata = new ModelMetadata(model.getModelName() + "|" + model.getId(), false, 1, Temporal.Timestamp.now());
ModelSchema schema = schemaRegistry.getModelSchemaForModelClass(BlogOwner.class);
synchronousStorageAdapter.save(model, metadata);
// Enqueue an update in the mutation outbox
assertTrue(mutationOutbox.enqueue(PendingMutation.update(model, schema)).blockingAwait(TIMEOUT_SECONDS, TimeUnit.SECONDS));
// When AppSync receives that update, have it respond with an error.
AppSyncMocking.update(appSync).mockErrorResponse(model, 1);
// Start listening for publication events.
HubAccumulator errorAccumulator = HubAccumulator.create(HubChannel.DATASTORE, DataStoreChannelEventName.OUTBOX_MUTATION_FAILED, 1).start();
// Start the mutation processor and wait for hub event.
mutationProcessor.startDrainingMutationOutbox();
errorAccumulator.await();
}
use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class MutationQueueTest method removePendingMutationTest.
/**
* Prepare a {@link PendingMutation} instance and insert into the tail of
* the {@link MutationQueue} and then remove it, verify the {@link MutationQueue}
* is empty after the remove.
*/
@Test
public void removePendingMutationTest() {
mutationQueue.clear();
BlogOwner qing = BlogOwner.builder().name("Qing Zhong").build();
PendingMutation<BlogOwner> createQing = PendingMutation.creation(qing, schema);
mutationQueue.add(createQing);
assertEquals(mutationQueue.size(), 1);
mutationQueue.remove(createQing);
assertTrue(mutationQueue.isEmpty());
}
use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class MutationQueueTest method peekingPendingMutationsTest.
/**
* Prepare two {@link PendingMutation} instances and insert them into the tail of
* the {@link MutationQueue}, verify the first element in the queue should be the
* first element we insert, which is FIFO.
*/
@Test
public void peekingPendingMutationsTest() {
mutationQueue.clear();
BlogOwner qing = BlogOwner.builder().name("Qing Zhong").build();
PendingMutation<BlogOwner> createQing = PendingMutation.creation(qing, schema);
BlogOwner tony = BlogOwner.builder().name("The Real Papa Tony").build();
PendingMutation<BlogOwner> createTony = PendingMutation.creation(tony, schema);
mutationQueue.add(createQing);
mutationQueue.add(createTony);
assertEquals(createQing, mutationQueue.peek());
}
use of com.amplifyframework.testmodels.commentsblog.BlogOwner in project amplify-android by aws-amplify.
the class MutationQueueTest method addPendingMutationTest.
/**
* Prepare a {@link PendingMutation} instance and insert into the tail of
* the {@link MutationQueue}, verify the instance exist by checking its {@link TimeBasedUuid}.
*/
@Test
public void addPendingMutationTest() {
mutationQueue.clear();
BlogOwner qing = BlogOwner.builder().name("Qing Zhong").build();
PendingMutation<BlogOwner> createQing = PendingMutation.creation(qing, schema);
mutationQueue.add(createQing);
assertEquals(mutationQueue.size(), 1);
TimeBasedUuid id = createQing.getMutationId();
assertEquals(mutationQueue.getMutationById(id), createQing);
}
Aggregations