Search in sources :

Example 6 with BigtableDataSettings

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings in project java-bigtable-hbase by googleapis.

the class TestBigtableHBaseVeneerSettings method testDataSettingsBasicKeys.

@Test
public void testDataSettingsBasicKeys() throws IOException {
    String appProfileId = "appProfileId";
    String userAgent = "test-user-agent";
    String fakeTracingCookie = "fake-tracing-cookie";
    Credentials credentials = Mockito.mock(Credentials.class);
    configuration.set(BIGTABLE_PORT_KEY, String.valueOf(TEST_PORT));
    configuration.set(APP_PROFILE_ID_KEY, appProfileId);
    configuration.setBoolean(BIGTABLE_USE_PLAINTEXT_NEGOTIATION, true);
    configuration.set(CUSTOM_USER_AGENT_KEY, userAgent);
    configuration.set(BIGTABLE_USE_CACHED_DATA_CHANNEL_POOL, "true");
    configuration.set(BIGTABLE_USE_SERVICE_ACCOUNTS_KEY, "true");
    configuration.set(ALLOW_NO_TIMESTAMP_RETRIES_KEY, "true");
    configuration.set(BIGTABLE_TRACING_COOKIE, fakeTracingCookie);
    configuration = BigtableConfiguration.withCredentials(configuration, credentials);
    BigtableHBaseVeneerSettings settingUtils = (BigtableHBaseVeneerSettings) BigtableHBaseSettings.create(configuration);
    BigtableDataSettings dataSettings = settingUtils.getDataSettings();
    assertEquals(TEST_PROJECT_ID, dataSettings.getProjectId());
    assertEquals(TEST_INSTANCE_ID, dataSettings.getInstanceId());
    assertEquals(appProfileId, dataSettings.getAppProfileId());
    assertEquals(TEST_HOST, settingUtils.getDataHost());
    assertEquals(TEST_PORT, settingUtils.getPort());
    assertEquals(TEST_HOST, settingUtils.getAdminHost());
    assertEquals(TEST_HOST + ":" + TEST_PORT, dataSettings.getStubSettings().getEndpoint());
    Map<String, String> headers = dataSettings.getStubSettings().getHeaderProvider().getHeaders();
    assertTrue(headers.get(GrpcUtil.USER_AGENT_KEY.name()).contains(userAgent));
    assertTrue(headers.get(GrpcUtil.USER_AGENT_KEY.name()).contains("bigtable-hbase/" + BigtableHBaseVersion.getVersion()));
    assertTrue(headers.get("cookie").equals(fakeTracingCookie));
    assertEquals(credentials, dataSettings.getStubSettings().getCredentialsProvider().getCredentials());
    assertTrue(settingUtils.isChannelPoolCachingEnabled());
    assertTrue(settingUtils.isRetriesWithoutTimestampAllowed());
    assertTrue(dataSettings.getStubSettings().getTracerFactory() instanceof MetricsApiTracerAdapterFactory);
}
Also used : BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) Credentials(com.google.auth.Credentials) MetricsApiTracerAdapterFactory(com.google.cloud.bigtable.hbase.wrappers.veneer.metrics.MetricsApiTracerAdapterFactory) Test(org.junit.Test)

Example 7 with BigtableDataSettings

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings in project java-bigtable by googleapis.

the class HelloWorldTest method beforeClass.

@BeforeClass
public static void beforeClass() throws IOException {
    initializeVariables();
    BigtableDataSettings settings = BigtableDataSettings.newBuilder().setProjectId(projectId).setInstanceId(instanceId).build();
    dataClient = BigtableDataClient.create(settings);
    BigtableTableAdminSettings adminSettings = BigtableTableAdminSettings.newBuilder().setProjectId(projectId).setInstanceId(instanceId).build();
    adminClient = BigtableTableAdminClient.create(adminSettings);
}
Also used : BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) BeforeClass(org.junit.BeforeClass)

Example 8 with BigtableDataSettings

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings in project java-bigtable-hbase by googleapis.

the class TestBigtableHBaseVeneerSettings method testRpcMethodWithoutRetry.

@Ignore("Re-enable this test once veneer default align with hbase")
@Test
public void testRpcMethodWithoutRetry() throws IOException {
    configuration.set(ENABLE_GRPC_RETRIES_KEY, "false");
    BigtableHBaseVeneerSettings settingUtils = BigtableHBaseVeneerSettings.create(configuration);
    BigtableDataSettings settings = settingUtils.getDataSettings();
    assertTrue(settings.getStubSettings().readRowsSettings().getRetryableCodes().isEmpty());
    BigtableDataSettings defaultSettings = BigtableDataSettings.newBuilder().setProjectId(TEST_PROJECT_ID).setInstanceId(TEST_INSTANCE_ID).build();
    assertEquals(settings.getStubSettings().readRowsSettings().getRetrySettings().toString(), defaultSettings.getStubSettings().readRowsSettings().getRetrySettings().toString());
    assertEquals(settings.getStubSettings().mutateRowSettings().getRetrySettings().toString(), defaultSettings.getStubSettings().mutateRowSettings().getRetrySettings().toString());
}
Also used : BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with BigtableDataSettings

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings in project java-bigtable-hbase by googleapis.

the class TestBigtableHBaseVeneerSettings method testWithNullCredentials.

@Test
public void testWithNullCredentials() throws IOException {
    configuration.set(ADDITIONAL_RETRY_CODES, "UNAVAILABLE,ABORTED");
    configuration.setBoolean(BIGTABLE_USE_SERVICE_ACCOUNTS_KEY, false);
    configuration.setBoolean(BIGTABLE_NULL_CREDENTIAL_ENABLE_KEY, true);
    BigtableDataSettings dataSettings = ((BigtableHBaseVeneerSettings) BigtableHBaseVeneerSettings.create(configuration)).getDataSettings();
    assertTrue(dataSettings.getStubSettings().getCredentialsProvider() instanceof NoCredentialsProvider);
    assertNull(dataSettings.getStubSettings().getCredentialsProvider().getCredentials());
    BigtableTableAdminSettings adminSettings = ((BigtableHBaseVeneerSettings) BigtableHBaseVeneerSettings.create(configuration)).getTableAdminSettings();
    assertTrue(adminSettings.getStubSettings().getCredentialsProvider() instanceof NoCredentialsProvider);
    assertNull(adminSettings.getStubSettings().getCredentialsProvider().getCredentials());
}
Also used : NoCredentialsProvider(com.google.api.gax.core.NoCredentialsProvider) BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) Test(org.junit.Test)

Example 10 with BigtableDataSettings

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings in project java-bigtable-hbase by googleapis.

the class TestBigtableHBaseVeneerSettings method testTimeoutBeingPassed.

@Test
public void testTimeoutBeingPassed() throws IOException {
    int initialElapsedMs = 100;
    int rpcAttemptTimeoutMs = 100;
    int rpcTimeoutMs = 500;
    int perRowTimeoutMs = 1001;
    int maxElapsedMs = 1000;
    int maxAttempt = 10;
    int readRowStreamTimeout = 30000;
    int readRowStreamAttemptTimeout = 3000;
    configuration.setBoolean(BIGTABLE_USE_TIMEOUTS_KEY, true);
    configuration.setInt(INITIAL_ELAPSED_BACKOFF_MILLIS_KEY, initialElapsedMs);
    configuration.setInt(MAX_ELAPSED_BACKOFF_MILLIS_KEY, maxElapsedMs);
    configuration.setInt(BIGTABLE_RPC_ATTEMPT_TIMEOUT_MS_KEY, rpcAttemptTimeoutMs);
    configuration.setInt(BIGTABLE_RPC_TIMEOUT_MS_KEY, rpcTimeoutMs);
    configuration.setInt(READ_PARTIAL_ROW_TIMEOUT_MS, perRowTimeoutMs);
    configuration.setLong(MAX_SCAN_TIMEOUT_RETRIES, maxAttempt);
    configuration.setInt(BIGTABLE_READ_RPC_TIMEOUT_MS_KEY, readRowStreamTimeout);
    configuration.setInt(BIGTABLE_READ_RPC_ATTEMPT_TIMEOUT_MS_KEY, readRowStreamAttemptTimeout);
    BigtableHBaseVeneerSettings settings = BigtableHBaseVeneerSettings.create(configuration);
    BigtableDataSettings dataSettings = settings.getDataSettings();
    assertEquals(Optional.of(Duration.ofMillis(rpcTimeoutMs)), settings.getClientTimeouts().getUnaryTimeouts().getOperationTimeout());
    assertEquals(Optional.of(Duration.ofMillis(rpcAttemptTimeoutMs)), settings.getClientTimeouts().getUnaryTimeouts().getAttemptTimeout());
    assertEquals(Optional.of(Duration.ofMillis(readRowStreamTimeout)), settings.getClientTimeouts().getScanTimeouts().getOperationTimeout());
    assertEquals(Optional.of(Duration.ofMillis(readRowStreamAttemptTimeout)), settings.getClientTimeouts().getScanTimeouts().getAttemptTimeout());
    assertEquals(Optional.of(Duration.ofMillis(perRowTimeoutMs)), settings.getClientTimeouts().getScanTimeouts().getResponseTimeout());
    RetrySettings readRowRetrySettings = dataSettings.getStubSettings().readRowSettings().getRetrySettings();
    assertEquals(initialElapsedMs, readRowRetrySettings.getInitialRetryDelay().toMillis());
    assertEquals(rpcTimeoutMs, readRowRetrySettings.getTotalTimeout().toMillis());
    assertEquals(rpcAttemptTimeoutMs, readRowRetrySettings.getInitialRpcTimeout().toMillis());
    assertEquals(rpcAttemptTimeoutMs, readRowRetrySettings.getMaxRpcTimeout().toMillis());
    RetrySettings checkAndMutateRetrySettings = dataSettings.getStubSettings().checkAndMutateRowSettings().getRetrySettings();
    assertEquals(rpcTimeoutMs, checkAndMutateRetrySettings.getTotalTimeout().toMillis());
    // CheckAndMutate is non-retriable so its rpc timeout = overall timeout
    assertEquals(rpcTimeoutMs, checkAndMutateRetrySettings.getInitialRpcTimeout().toMillis());
    assertEquals(rpcTimeoutMs, checkAndMutateRetrySettings.getMaxRpcTimeout().toMillis());
    RetrySettings readRowsRetrySettings = dataSettings.getStubSettings().readRowsSettings().getRetrySettings();
    assertEquals(initialElapsedMs, readRowsRetrySettings.getInitialRetryDelay().toMillis());
    assertEquals(perRowTimeoutMs, readRowsRetrySettings.getInitialRpcTimeout().toMillis());
    assertEquals(perRowTimeoutMs, readRowsRetrySettings.getMaxRpcTimeout().toMillis());
    assertEquals(maxAttempt, readRowsRetrySettings.getMaxAttempts());
    assertEquals(readRowStreamTimeout, readRowsRetrySettings.getTotalTimeout().toMillis());
}
Also used : RetrySettings(com.google.api.gax.retrying.RetrySettings) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) Test(org.junit.Test)

Aggregations

BigtableDataSettings (com.google.cloud.bigtable.data.v2.BigtableDataSettings)21 Test (org.junit.Test)12 BigtableTableAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings)5 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)5 InstantiatingGrpcChannelProvider (com.google.api.gax.grpc.InstantiatingGrpcChannelProvider)3 EnhancedBigtableStubSettings (com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings)3 Before (org.junit.Before)3 NoCredentialsProvider (com.google.api.gax.core.NoCredentialsProvider)2 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)2 BigtableInstanceAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminSettings)2 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)2 Builder (com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder)2 Row (com.google.cloud.bigtable.data.v2.models.Row)2 ByteString (com.google.protobuf.ByteString)2 IOException (java.io.IOException)2 Ignore (org.junit.Ignore)2 ApiFunction (com.google.api.core.ApiFunction)1 BatcherImpl (com.google.api.gax.batching.BatcherImpl)1 BatchingSettings (com.google.api.gax.batching.BatchingSettings)1 FlowControlEventStats (com.google.api.gax.batching.FlowControlEventStats)1