Search in sources :

Example 1 with MockServerStreamingCallable

use of com.google.cloud.bigtable.gaxx.testing.MockStreamingApi.MockServerStreamingCallable in project java-bigtable by googleapis.

the class ReframingResponseObserverTest method testConcurrentCancel.

@Test
public void testConcurrentCancel() throws InterruptedException {
    final MockResponseObserver<String> outerObserver = new MockResponseObserver<>(true);
    ReframingResponseObserver<String, String> middleware = new ReframingResponseObserver<>(outerObserver, new DasherizingReframer(2));
    MockServerStreamingCallable<String, String> innerCallable = new MockServerStreamingCallable<>();
    innerCallable.call("request", middleware);
    MockServerStreamingCall<String, String> lastCall = innerCallable.popLastCall();
    final MockStreamController<String> innerController = lastCall.getController();
    final CountDownLatch latch = new CountDownLatch(2);
    executor.submit(new Runnable() {

        @Override
        public void run() {
            while (!outerObserver.isDone()) {
                outerObserver.popNextResponse();
            }
            latch.countDown();
        }
    });
    executor.submit(new Runnable() {

        @Override
        public void run() {
            while (!innerController.isCancelled()) {
                if (innerController.popLastPull() > 0) {
                    innerController.getObserver().onResponse("a");
                }
            }
            innerController.getObserver().onError(new RuntimeException("Some other upstream error"));
            latch.countDown();
        }
    });
    outerObserver.getController().cancel();
    Truth.assertThat(latch.await(1, TimeUnit.MINUTES)).isTrue();
}
Also used : MockResponseObserver(com.google.cloud.bigtable.gaxx.testing.MockStreamingApi.MockResponseObserver) CountDownLatch(java.util.concurrent.CountDownLatch) MockServerStreamingCallable(com.google.cloud.bigtable.gaxx.testing.MockStreamingApi.MockServerStreamingCallable) Test(org.junit.Test)

Aggregations

MockResponseObserver (com.google.cloud.bigtable.gaxx.testing.MockStreamingApi.MockResponseObserver)1 MockServerStreamingCallable (com.google.cloud.bigtable.gaxx.testing.MockStreamingApi.MockServerStreamingCallable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1