Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions gax/src/test/java/com/google/api/gax/batching/BatcherImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -841,14 +841,14 @@ public void testThrottlingBlocking() throws Exception {
.setLimitExceededBehavior(LimitExceededBehavior.Block)
.setMaxOutstandingElementCount(1L)
.build());
ExecutorService executor = Executors.newSingleThreadExecutor();
ExecutorService executor = Executors.newFixedThreadPool(2);

ApiCallContext callContext = Mockito.mock(ApiCallContext.class);
ArgumentCaptor<ApiCallContext.Key<Long>> key =
ArgumentCaptor.forClass(ApiCallContext.Key.class);
ArgumentCaptor<Long> value = ArgumentCaptor.forClass(Long.class);
when(callContext.withOption(key.capture(), value.capture())).thenReturn(callContext);
long throttledTime = 10;
long throttledTime = 50;

try (final Batcher<Integer, Integer> batcher =
new BatcherImpl<>(
Expand All @@ -868,14 +868,22 @@ public void run() {
batcher.add(1);
}
});
executor.submit(
() -> {
try {
Thread.sleep(throttledTime);
flowController.release(1, 1);
} catch (InterruptedException e) {
}
});

try {
future.get(10, TimeUnit.MILLISECONDS);
Thread.sleep(throttledTime);
assertWithMessage("adding elements to batcher should be blocked by FlowControlled").fail();
} catch (TimeoutException e) {
// expected
}
flowController.release(1, 1);

try {
future.get(100, TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
Expand Down