Java Code Examples for rx.observers.TestSubscriber#getOnErrorEvents()

The following examples show how to use rx.observers.TestSubscriber#getOnErrorEvents() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AwsLoadBalancerConnectorTest.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Test
public void validateExceptionsAreUnmodifiedWithMockClientTest() {
    Class defaultExceptionClass = TargetGroupAssociationLimitException.class;
    TestSubscriber testSubscriber = new TestSubscriber();

    AmazonElasticLoadBalancingAsync albClient = mock(AmazonElasticLoadBalancingAsync.class);
    when(albClient.describeTargetHealthAsync(any(), any())).thenThrow(defaultExceptionClass);

    awsLoadBalancerConnector = getAwsLoadBalancerConnector(albClient);
    awsLoadBalancerConnector.getLoadBalancer(targetGroupWithTargets).subscribe(testSubscriber);

    testSubscriber.awaitTerminalEvent();

    List<Throwable> errors = testSubscriber.getOnErrorEvents();
    assertEquals(1, errors.size());

    Throwable throwable = errors.get(0);
    assertFalse(throwable instanceof LoadBalancerException);
    assertTrue(throwable instanceof TargetGroupAssociationLimitException);
}
 
Example 2
Source File: CompressionTest.java    From hawkular-metrics with Apache License 2.0 6 votes vote down vote up
private void createAndInsertMetrics(long start, int amountOfMetrics, int datapointsPerMetric) {
    for (int j = 0; j < datapointsPerMetric; j++) {
        final int dpAdd = j;
        Observable<Metric<Double>> metrics = Observable.create(emitter -> {
            for (int i = 0; i < amountOfMetrics; i++) {
                String metricName = String.format("m%d", i);
                MetricId<Double> mId = new MetricId<>(tenantId, GAUGE, metricName);
                emitter.onNext(new Metric<>(mId, asList(new DataPoint<>(start + dpAdd, startValue + dpAdd))));
            }
            emitter.onCompleted();
        }, Emitter.BackpressureMode.BUFFER);

        TestSubscriber<Void> subscriber = new TestSubscriber<>();
        Observable<Void> observable = metricsService.addDataPoints(GAUGE, metrics);
        observable.subscribe(subscriber);
        subscriber.awaitTerminalEvent(20, TimeUnit.SECONDS); // For Travis..
        for (Throwable throwable : subscriber.getOnErrorEvents()) {
            throwable.printStackTrace();
        }
        subscriber.assertNoErrors();
        subscriber.assertCompleted();
    }
}
 
Example 3
Source File: ViewLocatorTest.java    From couchbase-jvm-core with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldFailWhenUsedAgainstMemcacheBucket() {
    Locator locator = new ViewLocator(0);

    ClusterConfig config = mock(ClusterConfig.class);
    when(config.bucketConfig("default")).thenReturn(mock(MemcachedBucketConfig.class));

    CouchbaseRequest request = mock(ViewQueryRequest.class);
    Subject<CouchbaseResponse, CouchbaseResponse> response = AsyncSubject.create();
    when(request.bucket()).thenReturn("default");
    when(request.observable()).thenReturn(response);

    TestSubscriber<CouchbaseResponse> subscriber = new TestSubscriber<CouchbaseResponse>();
    response.subscribe(subscriber);

    locator.locateAndDispatch(request, Collections.<Node>emptyList(), config, null, null);

    subscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
    List<Throwable> errors = subscriber.getOnErrorEvents();
    assertEquals(1, errors.size());
    assertTrue(errors.get(0) instanceof ServiceNotAvailableException);
}
 
Example 4
Source File: AbstractEndpointTest.java    From couchbase-jvm-core with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldForceTimeoutOfSocketConnectDoesNotReturn() {
    BootstrapAdapter bootstrap = mock(BootstrapAdapter.class);
    when(bootstrap.connect()).thenReturn(channel.newPromise()); // this promise never completes
    Endpoint endpoint = new DummyEndpoint(bootstrap, ctx);

    Observable<LifecycleState> observable = endpoint.connect();

    TestSubscriber<LifecycleState> testSubscriber = new TestSubscriber<LifecycleState>();
    observable.subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent();

    List<Throwable> errors = testSubscriber.getOnErrorEvents();
    assertEquals(1, errors.size());
    assertEquals(ConnectTimeoutException.class, errors.get(0).getClass());

    endpoint.disconnect().subscribe();
}
 
Example 5
Source File: KeyValueHandlerTest.java    From couchbase-jvm-core with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPropagateErrorOnEncode() {
    String id = "key";
    ByteBuf content = Unpooled.buffer();
    content.release(); // provoke a IllegalReferenceCountException
    UpsertRequest request = new UpsertRequest(id, content, BUCKET);
    request.partition((short) 1);


    TestSubscriber<CouchbaseResponse> ts = TestSubscriber.create();
    request.observable().subscribe(ts);

    try {
        channel.writeOutbound(request);
        fail("Expected exception, none thrown.");
    } catch (EncoderException ex) {
        assertTrue(ex.getCause() instanceof IllegalReferenceCountException);
    }

    List<Throwable> onErrorEvents = ts.getOnErrorEvents();
    assertTrue(onErrorEvents.get(0) instanceof RequestCancelledException);
    assertTrue(onErrorEvents.get(0).getCause() instanceof IllegalReferenceCountException);
}
 
Example 6
Source File: TestSubscriberAssertionsWrapper.java    From rxassertions with Apache License 2.0 5 votes vote down vote up
TestSubscriberAssertionsWrapper(BlockingObservable<T> actual) {
    super(actual, TestSubscriberAssertionsWrapper.class);
    TestSubscriber<T> subscriber = new TestSubscriber<>();
    actual.subscribe(subscriber);
    onErrorEvents = subscriber.getOnErrorEvents();
    onNextEvents = subscriber.getOnNextEvents();
    onCompletedEvents = subscriber.getOnCompletedEvents();
}
 
Example 7
Source File: CompressionTest.java    From hawkular-metrics with Apache License 2.0 5 votes vote down vote up
private void compressData(long start) {
    Completable completable = metricsService.compressBlock(start, 2000, 2);

    TestSubscriber<Row> tsr = new TestSubscriber<>();
    completable.subscribe(tsr);
    tsr.awaitTerminalEvent(100, TimeUnit.SECONDS); // Travis again
    for (Throwable throwable : tsr.getOnErrorEvents()) {
        throwable.printStackTrace();
    }
    tsr.assertCompleted();
    tsr.assertNoErrors();
}
 
Example 8
Source File: BaseITest.java    From hawkular-metrics with Apache License 2.0 5 votes vote down vote up
/**
 * This method take a function that produces an Observable that has side effects, like
 * inserting rows into the database. A {@link TestSubscriber} is subscribed to the
 * Observable. The subscriber blocks up to five seconds waiting for a terminal event
 * from the Observable.
 *
 * @param fn A function that produces an Observable with side effects
 */
protected <T> void doAction(Supplier<Observable<T>> fn) {
    TestSubscriber<T> subscriber = new TestSubscriber<>();
    Observable<T> observable = fn.get().doOnError(Throwable::printStackTrace);
    observable.subscribe(subscriber);
    subscriber.awaitTerminalEvent(5, TimeUnit.SECONDS);
    for (Throwable throwable : subscriber.getOnErrorEvents()) {
        throwable.printStackTrace();
    }
    subscriber.assertNoErrors();
    subscriber.assertCompleted();

}