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();
}
Aggregations