BatchExecutor implements ThresholdBatchReceiver<Batch<RequestT, ResponseT>> { @Override public void validateBatch(Batch<RequestT, ResponseT> item) { PartitionKey itemPartitionKey = batchingDescriptor.getBatchPartitionKey(item.getRequest()); if (!itemPartitionKey.equals(partitionKey)) { String requestClassName = item.getRequest().getClass().getSimpleName(); throw new IllegalArgumentException( String.format( "For type %s, invalid partition key: %s, should be: %s", requestClassName, itemPartitionKey, partitionKey)); } } BatchExecutor(
      BatchingDescriptor<RequestT, ResponseT> batchingDescriptor, PartitionKey partitionKey); @Override void validateBatch(Batch<RequestT, ResponseT> item); @Override ApiFuture<ResponseT> processBatch(Batch<RequestT, ResponseT> batch);  }
@Test public void testValidate() { BatchExecutor<List<Integer>, Integer> executor = new BatchExecutor<List<Integer>, Integer>(integerDescriptor, new PartitionKey(0)); List<Integer> request = new ArrayList<Integer>(); request.add(2); Batch<List<Integer>, Integer> batchingContextOk = new Batch<>(integerDescriptor, request, null, null); executor.validateBatch(batchingContextOk); }
@Test(expected = IllegalArgumentException.class) public void testValidateFailure() { BatchExecutor<List<Integer>, Integer> executor = new BatchExecutor<List<Integer>, Integer>(integerDescriptor, new PartitionKey(0)); List<Integer> request = new ArrayList<>(); request.add(3); Batch<List<Integer>, Integer> batchingContextOk = new Batch<>(integerDescriptor, request, null, null); executor.validateBatch(batchingContextOk); }