use of com.amplifyframework.core.async.NoOpCancelable in project amplify-android by aws-amplify.
the class SubscriptionProcessorTest method arrangeStartedSubscriptions.
private static void arrangeStartedSubscriptions(AppSync appSync, List<ModelSchema> modelSchemas, SubscriptionType[] subscriptionTypes) {
Answer<Cancelable> answer = invocation -> {
final int startConsumerIndex = 1;
Consumer<String> onStart = invocation.getArgument(startConsumerIndex);
onStart.accept(RandomString.string());
return new NoOpCancelable();
};
arrangeSubscriptions(appSync, answer, modelSchemas, subscriptionTypes);
}
use of com.amplifyframework.core.async.NoOpCancelable in project amplify-android by aws-amplify.
the class SubscriptionProcessorTest method appSyncInvokedWhenSubscriptionsStarted.
/**
* When {@link SubscriptionProcessor#startSubscriptions()} is invoked,
* the {@link AppSync} client receives subscription requests.
*/
@Test
public void appSyncInvokedWhenSubscriptionsStarted() {
// For every Class-SubscriptionType pairing, use a CountDownLatch
// to tell whether or not we've "seen" a subscription event for it.
Map<Pair<ModelSchema, SubscriptionType>, CountDownLatch> seen = new HashMap<>();
// Build a stream of such pairs.
Observable.fromIterable(modelSchemas).flatMap(modelSchema -> Observable.fromArray(SubscriptionType.values()).map(value -> Pair.create(modelSchema, value))).blockingForEach(pair -> {
// For each one, store a latch. Add a mocking behavior to count down
// the latch when the subscription API is hit, for that class and subscription type.
CountDownLatch latch = new CountDownLatch(1);
seen.put(Pair.create(pair.first, pair.second), latch);
Answer<Cancelable> answer = invocation -> {
latch.countDown();
return new NoOpCancelable();
};
arrangeSubscription(appSync, answer, pair.first, pair.second);
});
// Act: start some subscriptions.
try {
subscriptionProcessor.startSubscriptions();
} catch (DataStoreException exception) {
// startSubscriptions throws this exception if it doesn't receive the start_ack messages after a time out.
// This test doesn't mock those start_ack messages, so this expection is expected. That's okay though -
// we just want to verify that the subscriptions were requested.
}
// Make sure that all of the subscriptions have been
Observable.fromIterable(seen.entrySet()).blockingForEach(entry -> {
CountDownLatch latch = entry.getValue();
assertTrue(latch.await(OPERATION_TIMEOUT_MS, TimeUnit.MILLISECONDS));
});
}
use of com.amplifyframework.core.async.NoOpCancelable in project amplify-android by aws-amplify.
the class RxAdaptersTest method singleFiresErrorWhenErrorEmitted.
/**
* The {@link Single} returned by
* {@link CancelableBehaviors#toSingle(CancelableBehaviors.ResultEmitter)}
* will dispatch an error when the {@link CancelableBehaviors.ResultEmitter}'s error consumer is
* invoked.
*/
@Test
public void singleFiresErrorWhenErrorEmitted() {
Throwable expected = new Throwable(RandomString.string());
CancelableBehaviors.toSingle((onResult, onError) -> {
onError.accept(expected);
return new NoOpCancelable();
}).test().assertError(expected).assertNoValues();
}
use of com.amplifyframework.core.async.NoOpCancelable in project amplify-android by aws-amplify.
the class RxAdaptersTest method singleFiresResultWhenEmitted.
/**
* The {@link Single} returned by
* {@link CancelableBehaviors#toSingle(CancelableBehaviors.ResultEmitter)}
* will dispatch a result when the {@link CancelableBehaviors.ResultEmitter}'s value consumer
* is invoked.
*/
@Test
public void singleFiresResultWhenEmitted() {
String result = RandomString.string();
CancelableBehaviors.toSingle((onResult, onError) -> {
onResult.accept(result);
return new NoOpCancelable();
}).test().assertValue(result).assertComplete();
}
use of com.amplifyframework.core.async.NoOpCancelable in project amplify-android by aws-amplify.
the class RxAdaptersTest method observableFiresValuesAndCompletesWhenEmitterDoes.
/**
* The {@link Observable} returned by
* {@link CancelableBehaviors#toObservable(CancelableBehaviors.StreamEmitter)}
* will contain a stream of values corresponding to those that have been passed via the emitter's
* item consumer. When the emitters' completion action is invoked, the Observable completes.
*/
@Test
public void observableFiresValuesAndCompletesWhenEmitterDoes() {
String first = RandomString.string();
String second = RandomString.string();
CancelableBehaviors.toObservable((onStart, onItem, onError, onComplete) -> {
onStart.accept(RandomString.string());
onItem.accept(first);
onItem.accept(second);
onComplete.call();
return new NoOpCancelable();
}).test().assertValues(first, second).assertComplete().assertNoErrors();
}
Aggregations