private EnhancedBigtableStubSettings(Builder builder) { super(builder); // Since point reads & streaming reads share the same base callable that converts grpc errors // into ApiExceptions, they must have the same retry codes. Preconditions.checkState( builder .readRowSettings .getRetryableCodes() .equals(builder.readRowsSettings.getRetryableCodes()), "Single ReadRow retry codes must match ReadRows retry codes"); projectId = builder.projectId; instanceId = builder.instanceId; appProfileId = builder.appProfileId; // Per method settings. readRowsSettings = builder.readRowsSettings.build(); readRowSettings = builder.readRowSettings.build(); sampleRowKeysSettings = builder.sampleRowKeysSettings.build(); mutateRowSettings = builder.mutateRowSettings.build(); bulkMutateRowsSettings = builder.bulkMutateRowsSettings.build(); checkAndMutateRowSettings = builder.checkAndMutateRowSettings.build(); readModifyWriteRowSettings = builder.readModifyWriteRowSettings.build(); }
.setRetrySettings(retrySettings) .setBatchingSettings(batchingSettings) .build();
private EnhancedBigtableStubSettings(Builder builder) { super(builder); // Since point reads & streaming reads share the same base callable that converts grpc errors // into ApiExceptions, they must have the same retry codes. Preconditions.checkState( builder .readRowSettings .getRetryableCodes() .equals(builder.readRowsSettings.getRetryableCodes()), "Single ReadRow retry codes must match ReadRows retry codes"); projectId = builder.projectId; instanceId = builder.instanceId; appProfileId = builder.appProfileId; // Per method settings. readRowsSettings = builder.readRowsSettings.build(); readRowSettings = builder.readRowSettings.build(); sampleRowKeysSettings = builder.sampleRowKeysSettings.build(); mutateRowSettings = builder.mutateRowSettings.build(); bulkMutateRowsSettings = builder.bulkMutateRowsSettings.build(); checkAndMutateRowSettings = builder.checkAndMutateRowSettings.build(); readModifyWriteRowSettings = builder.readModifyWriteRowSettings.build(); }
.setBatchingSettings(batchingSettings) .setFlowController(trackedFlowController) .build(); Callables.BatchingCreateResult<LabeledIntList, List<Integer>> batchingCreateResult = Callables.batchingImpl(callLabeledIntSquarer, batchingCallSettings, clientContext);
@Test public void batchingException() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() .setDelayThreshold(Duration.ofSeconds(1)) .setElementCountThreshold(2L) .build(); BatchingCallSettings<LabeledIntList, List<Integer>> batchingCallSettings = BatchingCallSettings.newBuilder(SQUARER_BATCHING_DESC) .setBatchingSettings(batchingSettings) .build(); UnaryCallable<LabeledIntList, List<Integer>> callable = FakeCallableFactory.createBatchingCallable( callLabeledIntExceptionThrower, batchingCallSettings, clientContext); ApiFuture<List<Integer>> f1 = callable.futureCall(new LabeledIntList("one", 1, 2)); ApiFuture<List<Integer>> f2 = callable.futureCall(new LabeledIntList("one", 3, 4)); try { f1.get(); Assert.fail("Expected exception from batching call"); } catch (ExecutionException e) { // expected } try { f2.get(); Assert.fail("Expected exception from batching call"); } catch (ExecutionException e) { // expected } } }
/** * Creates a callable chain to handle MutatesRows RPCs. This is meant to be used for automatic * batching with flow control. The chain will: * * <ul> * <li>Convert a {@link RowMutation} into a {@link MutateRowsRequest} with a single entry. * <li>Using gax's {@link com.google.api.gax.rpc.BatchingCallable} to spool the requests and * aggregate the {@link MutateRowsRequest.Entry}s. * <li>Process the response and schedule retries. At the end of each attempt, entries that have * been applied, are filtered from the next attempt. Also, any entries that failed with a * nontransient error, are filtered from the next attempt. This will continue until there * are no more entries or there are no more retry attempts left. * <li>Wrap batch failures in a {@link * com.google.cloud.bigtable.data.v2.models.MutateRowsException}. * <li>Split the responses using {@link MutateRowsBatchingDescriptor}. * </ul> */ private UnaryCallable<RowMutation, Void> createBulkMutateRowsBatchingCallable() { UnaryCallable<MutateRowsRequest, Void> baseCallable = createMutateRowsBaseCallable(); BatchingCallSettings.Builder<MutateRowsRequest, Void> batchingCallSettings = BatchingCallSettings.newBuilder(new MutateRowsBatchingDescriptor()) .setBatchingSettings(settings.bulkMutateRowsSettings().getBatchingSettings()); UnaryCallable<MutateRowsRequest, Void> batching = Callables.batching(baseCallable, batchingCallSettings.build(), clientContext); MutateRowsUserFacingCallable userFacing = new MutateRowsUserFacingCallable(batching, requestContext); return userFacing.withDefaultCallContext(clientContext.getDefaultCallContext()); }
@Test public void testBuilder() { @SuppressWarnings("unchecked") BatchingDescriptor<Integer, Integer> batchingDescriptor = Mockito.mock(BatchingDescriptor.class); BatchingCallSettings.Builder<Integer, Integer> builder = BatchingCallSettings.newBuilder(batchingDescriptor); BatchingSettings batchingSettings = BatchingSettings.newBuilder().setElementCountThreshold(1L).build(); FlowController flowController = Mockito.mock(FlowController.class); Set<StatusCode.Code> retryCodes = Sets.newHashSet(Code.UNAVAILABLE); RetrySettings retrySettings = RetrySettings.newBuilder().build(); builder.setBatchingSettings(batchingSettings); builder.setFlowController(flowController); builder.setRetryableCodes(retryCodes); builder.setRetrySettings(retrySettings); Truth.assertThat(builder.getBatchingDescriptor()).isSameAs(batchingDescriptor); Truth.assertThat(builder.getBatchingSettings()).isSameAs(batchingSettings); Truth.assertThat(builder.getFlowController()).isSameAs(flowController); Truth.assertThat(builder.getRetryableCodes().size()).isEqualTo(1); Truth.assertThat(builder.getRetrySettings()).isSameAs(retrySettings); BatchingCallSettings settings = builder.build(); Truth.assertThat(settings.getBatchingDescriptor()).isSameAs(batchingDescriptor); Truth.assertThat(settings.getBatchingSettings()).isSameAs(batchingSettings); Truth.assertThat(settings.getFlowController()).isSameAs(flowController); Truth.assertThat(settings.getRetryableCodes().size()).isEqualTo(1); Truth.assertThat(settings.getRetrySettings()).isSameAs(retrySettings); }
@Test public void testBuilderFromSettings() throws Exception { @SuppressWarnings("unchecked") BatchingDescriptor<Integer, Integer> batchingDescriptor = Mockito.mock(BatchingDescriptor.class); BatchingCallSettings.Builder<Integer, Integer> builder = BatchingCallSettings.newBuilder(batchingDescriptor); BatchingSettings batchingSettings = BatchingSettings.newBuilder().setElementCountThreshold(1L).build(); FlowController flowController = Mockito.mock(FlowController.class); Set<StatusCode.Code> retryCodes = Sets.newHashSet(Code.UNAVAILABLE); RetrySettings retrySettings = RetrySettings.newBuilder().build(); builder.setBatchingSettings(batchingSettings); builder.setFlowController(flowController); builder.setRetryableCodes(retryCodes); builder.setRetrySettings(retrySettings); BatchingCallSettings settings = builder.build(); BatchingCallSettings.Builder newBuilder = settings.toBuilder(); Truth.assertThat(newBuilder.getBatchingDescriptor()).isSameAs(batchingDescriptor); Truth.assertThat(newBuilder.getBatchingSettings()).isSameAs(batchingSettings); Truth.assertThat(newBuilder.getFlowController()).isSameAs(flowController); Truth.assertThat(newBuilder.getRetryableCodes().size()).isEqualTo(1); Truth.assertThat(newBuilder.getRetrySettings()).isSameAs(retrySettings); }
@Test public void testEmptyBuilder() { @SuppressWarnings("unchecked") BatchingDescriptor<Integer, Integer> batchingDescriptor = Mockito.mock(BatchingDescriptor.class); BatchingCallSettings.Builder<Integer, Integer> builder = BatchingCallSettings.newBuilder(batchingDescriptor); Truth.assertThat(builder.getBatchingDescriptor()).isSameAs(batchingDescriptor); Truth.assertThat(builder.getBatchingSettings()).isNull(); Truth.assertThat(builder.getFlowController()).isNull(); Truth.assertThat(builder.getRetryableCodes().size()).isEqualTo(0); Truth.assertThat(builder.getRetrySettings()).isNotNull(); BatchingSettings batchingSettings = BatchingSettings.newBuilder().setElementCountThreshold(1L).build(); builder.setBatchingSettings(batchingSettings); BatchingCallSettings settings = builder.build(); Truth.assertThat(settings.getBatchingDescriptor()).isSameAs(batchingDescriptor); Truth.assertThat(settings.getBatchingSettings()).isSameAs(batchingSettings); Truth.assertThat(settings.getFlowController()).isNotNull(); Truth.assertThat(settings.getRetryableCodes().size()).isEqualTo(0); Truth.assertThat(settings.getRetrySettings()).isNotNull(); }
@Test public void batching() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() .setDelayThreshold(Duration.ofSeconds(1)) .setElementCountThreshold(2L) .build(); BatchingCallSettings<LabeledIntList, List<Integer>> batchingCallSettings = BatchingCallSettings.newBuilder(SQUARER_BATCHING_DESC) .setBatchingSettings(batchingSettings) .build(); UnaryCallable<LabeledIntList, List<Integer>> callable = FakeCallableFactory.createBatchingCallable( callLabeledIntSquarer, batchingCallSettings, clientContext); ApiFuture<List<Integer>> f1 = callable.futureCall(new LabeledIntList("one", 1, 2)); ApiFuture<List<Integer>> f2 = callable.futureCall(new LabeledIntList("one", 3, 4)); Truth.assertThat(f1.get()).isEqualTo(Arrays.asList(1, 4)); Truth.assertThat(f2.get()).isEqualTo(Arrays.asList(9, 16)); }
public void batchingWithBlockingCallThreshold() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder() .setDelayThreshold(Duration.ofSeconds(1)) .setElementCountThreshold(2L) .build(); BatchingCallSettings<LabeledIntList, List<Integer>> batchingCallSettings = BatchingCallSettings.newBuilder(SQUARER_BATCHING_DESC) .setBatchingSettings(batchingSettings) .build(); UnaryCallable<LabeledIntList, List<Integer>> callable = FakeCallableFactory.createBatchingCallable( callLabeledIntSquarer, batchingCallSettings, clientContext); ApiFuture<List<Integer>> f1 = callable.futureCall(new LabeledIntList("one", 1)); ApiFuture<List<Integer>> f2 = callable.futureCall(new LabeledIntList("one", 3)); Truth.assertThat(f1.get()).isEqualTo(Arrays.asList(1)); Truth.assertThat(f2.get()).isEqualTo(Arrays.asList(9)); }
@Test public void testNoFlowControlSettings() throws Exception { @SuppressWarnings("unchecked") BatchingDescriptor<Integer, Integer> batchingDescriptor = Mockito.mock(BatchingDescriptor.class); BatchingCallSettings.Builder<Integer, Integer> builder = BatchingCallSettings.newBuilder(batchingDescriptor); BatchingSettings batchingSettings = BatchingSettings.newBuilder().setElementCountThreshold(1L).build(); builder.setBatchingSettings(batchingSettings); BatchingCallSettings settings = builder.build(); Truth.assertThat(settings.getFlowController()).isNotNull(); } }
@Test public void batchingDisabled() throws Exception { BatchingSettings batchingSettings = BatchingSettings.newBuilder().setIsEnabled(false).build(); BatchingCallSettings<LabeledIntList, List<Integer>> batchingCallSettings = BatchingCallSettings.newBuilder(SQUARER_BATCHING_DESC) .setBatchingSettings(batchingSettings) .build(); UnaryCallable<LabeledIntList, List<Integer>> callable = FakeCallableFactory.createBatchingCallable( callLabeledIntSquarer, batchingCallSettings, clientContext); ApiFuture<List<Integer>> f1 = callable.futureCall(new LabeledIntList("one", 1, 2)); ApiFuture<List<Integer>> f2 = callable.futureCall(new LabeledIntList("one", 3, 4)); Truth.assertThat(f1.get()).isEqualTo(Arrays.asList(1, 4)); Truth.assertThat(f2.get()).isEqualTo(Arrays.asList(9, 16)); }
private FakeStubSettings(Builder settingsBuilder) throws IOException { super(settingsBuilder); this.fakeMethodSimple = settingsBuilder.fakeMethodSimple().build(); this.fakePagedMethod = settingsBuilder.fakePagedMethod().build(); this.fakeMethodBatching = settingsBuilder.fakeMethodBatching().build(); }
protected LoggingServiceV2StubSettings(Builder settingsBuilder) throws IOException { super(settingsBuilder); deleteLogSettings = settingsBuilder.deleteLogSettings().build(); writeLogEntriesSettings = settingsBuilder.writeLogEntriesSettings().build(); listLogEntriesSettings = settingsBuilder.listLogEntriesSettings().build(); listMonitoredResourceDescriptorsSettings = settingsBuilder.listMonitoredResourceDescriptorsSettings().build(); listLogsSettings = settingsBuilder.listLogsSettings().build(); }
/** * Creates a callable chain to handle MutatesRows RPCs. This is meant to be used for automatic * batching with flow control. The chain will: * * <ul> * <li>Convert a {@link RowMutation} into a {@link MutateRowsRequest} with a single entry. * <li>Using gax's {@link com.google.api.gax.rpc.BatchingCallable} to spool the requests and * aggregate the {@link MutateRowsRequest.Entry}s. * <li>Process the response and schedule retries. At the end of each attempt, entries that have * been applied, are filtered from the next attempt. Also, any entries that failed with a * nontransient error, are filtered from the next attempt. This will continue until there * are no more entries or there are no more retry attempts left. * <li>Wrap batch failures in a {@link * com.google.cloud.bigtable.data.v2.models.MutateRowsException}. * <li>Split the responses using {@link MutateRowsBatchingDescriptor}. * </ul> */ private UnaryCallable<RowMutation, Void> createBulkMutateRowsBatchingCallable() { UnaryCallable<MutateRowsRequest, Void> baseCallable = createMutateRowsBaseCallable(); BatchingCallSettings.Builder<MutateRowsRequest, Void> batchingCallSettings = BatchingCallSettings.newBuilder(new MutateRowsBatchingDescriptor()) .setBatchingSettings(settings.bulkMutateRowsSettings().getBatchingSettings()); UnaryCallable<MutateRowsRequest, Void> batching = Callables.batching(baseCallable, batchingCallSettings.build(), clientContext); MutateRowsUserFacingCallable userFacing = new MutateRowsUserFacingCallable(batching, requestContext); return userFacing.withDefaultCallContext(clientContext.getDefaultCallContext()); }
protected PublisherStubSettings(Builder settingsBuilder) throws IOException { super(settingsBuilder); createTopicSettings = settingsBuilder.createTopicSettings().build(); updateTopicSettings = settingsBuilder.updateTopicSettings().build(); publishSettings = settingsBuilder.publishSettings().build(); getTopicSettings = settingsBuilder.getTopicSettings().build(); listTopicsSettings = settingsBuilder.listTopicsSettings().build(); listTopicSubscriptionsSettings = settingsBuilder.listTopicSubscriptionsSettings().build(); deleteTopicSettings = settingsBuilder.deleteTopicSettings().build(); setIamPolicySettings = settingsBuilder.setIamPolicySettings().build(); getIamPolicySettings = settingsBuilder.getIamPolicySettings().build(); testIamPermissionsSettings = settingsBuilder.testIamPermissionsSettings().build(); }
protected LoggingServiceV2StubSettings(Builder settingsBuilder) throws IOException { super(settingsBuilder); deleteLogSettings = settingsBuilder.deleteLogSettings().build(); writeLogEntriesSettings = settingsBuilder.writeLogEntriesSettings().build(); listLogEntriesSettings = settingsBuilder.listLogEntriesSettings().build(); listMonitoredResourceDescriptorsSettings = settingsBuilder.listMonitoredResourceDescriptorsSettings().build(); listLogsSettings = settingsBuilder.listLogsSettings().build(); }