@Test
public void testBatchedCall() throws Exception {

  BatchingSettings batchingSettings =
      BatchingSettings.newBuilder()
          .setDelayThreshold(Duration.ofSeconds(10))
          .setElementCountThreshold(2L)
          .setRequestByteThreshold(1000L)
          .build();
  FlowControlSettings flowControlSettings =
      FlowControlSettings.newBuilder()
          .setLimitExceededBehavior(LimitExceededBehavior.Ignore)
          .build();
  FlowController flowController = new FlowController(flowControlSettings);
  BatcherFactory<LabeledIntList, List<Integer>> batcherFactory =
      new BatcherFactory<>(
          new SquarerBatchingDescriptor(), batchingSettings, batchingExecutor, flowController);
  BatchingCallable<LabeledIntList, List<Integer>> batchingCallable =
      new BatchingCallable<>(
          FakeBatchableApi.callLabeledIntSquarer,
          FakeBatchableApi.SQUARER_BATCHING_DESC,
          batcherFactory);
  LabeledIntList request1 = new LabeledIntList("label", 2);
  ApiFuture<List<Integer>> future1 =
      batchingCallable.futureCall(request1, FakeCallContext.createDefault());
  // Assume it won't take 10 seconds (the batching delay threshold) to check the first future
  Truth.assertThat(future1.isDone()).isFalse();
  LabeledIntList request2 = new LabeledIntList("label", 3);
  ApiFuture<List<Integer>> future2 =
      batchingCallable.futureCall(request2, FakeCallContext.createDefault());
  List<Integer> response1 = future1.get();
  List<Integer> response2 = future2.get();
  Truth.assertThat(response1.size()).isEqualTo(1);
  Truth.assertThat(response1.get(0)).isEqualTo(2 * 2);
  Truth.assertThat(response2.size()).isEqualTo(1);
  Truth.assertThat(response2.get(0)).isEqualTo(3 * 3);
}