protected Builder(ClientContext clientContext) { super(clientContext); deleteLogSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); writeLogEntriesSettings = BatchingCallSettings.newBuilder(WRITE_LOG_ENTRIES_BATCHING_DESC) .setBatchingSettings(BatchingSettings.newBuilder().build()); listLogEntriesSettings = PagedCallSettings.newBuilder(LIST_LOG_ENTRIES_PAGE_STR_FACT); listMonitoredResourceDescriptorsSettings = PagedCallSettings.newBuilder(LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_FACT); listLogsSettings = PagedCallSettings.newBuilder(LIST_LOGS_PAGE_STR_FACT); unaryMethodSettingsBuilders = ImmutableList.<UnaryCallSettings.Builder<?, ?>>of( deleteLogSettings, writeLogEntriesSettings, listLogEntriesSettings, listMonitoredResourceDescriptorsSettings, listLogsSettings); initDefaults(this); }
protected Builder(ClientContext clientContext) { super(clientContext); createTopicSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); updateTopicSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); publishSettings = BatchingCallSettings.newBuilder(PUBLISH_BATCHING_DESC) .setBatchingSettings(BatchingSettings.newBuilder().build()); getTopicSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); listTopicsSettings = PagedCallSettings.newBuilder(LIST_TOPICS_PAGE_STR_FACT); listTopicSubscriptionsSettings = PagedCallSettings.newBuilder(LIST_TOPIC_SUBSCRIPTIONS_PAGE_STR_FACT); deleteTopicSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); setIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); getIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); testIamPermissionsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); unaryMethodSettingsBuilders = ImmutableList.<UnaryCallSettings.Builder<?, ?>>of( createTopicSettings, updateTopicSettings, publishSettings, getTopicSettings, listTopicsSettings, listTopicSubscriptionsSettings, deleteTopicSettings, setIamPolicySettings, getIamPolicySettings, testIamPermissionsSettings); initDefaults(this); }
/** * 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 Builder(ClientContext clientContext) { super(clientContext); deleteLogSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); writeLogEntriesSettings = BatchingCallSettings.newBuilder(WRITE_LOG_ENTRIES_BATCHING_DESC) .setBatchingSettings(BatchingSettings.newBuilder().build()); listLogEntriesSettings = PagedCallSettings.newBuilder(LIST_LOG_ENTRIES_PAGE_STR_FACT); listMonitoredResourceDescriptorsSettings = PagedCallSettings.newBuilder(LIST_MONITORED_RESOURCE_DESCRIPTORS_PAGE_STR_FACT); listLogsSettings = PagedCallSettings.newBuilder(LIST_LOGS_PAGE_STR_FACT); unaryMethodSettingsBuilders = ImmutableList.<UnaryCallSettings.Builder<?, ?>>of( deleteLogSettings, writeLogEntriesSettings, listLogEntriesSettings, listMonitoredResourceDescriptorsSettings, listLogsSettings); initDefaults(this); }
@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(); } }
private Builder() { super((ClientContext) null); fakeMethodSimple = UnaryCallSettings.newUnaryCallSettingsBuilder(); fakePagedMethod = PagedCallSettings.newBuilder(fakePagedListResponseFactory); fakeMethodBatching = BatchingCallSettings.newBuilder(FAKE_BATCHING_DESCRIPTOR) .setBatchingSettings(BatchingSettings.newBuilder().build()); }
@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 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)); }
/** * 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); }
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 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)); }
BatchingCallSettings.newBuilder(SQUARER_BATCHING_DESC) .setBatchingSettings(batchingSettings) .setFlowController(trackedFlowController)
@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 } } }