Search in sources :

Example 1 with CheckConsistencyRequest

use of com.google.bigtable.admin.v2.CheckConsistencyRequest in project java-bigtable by googleapis.

the class BaseBigtableTableAdminClientTest method checkConsistencyTest2.

@Test
public void checkConsistencyTest2() throws Exception {
    CheckConsistencyResponse expectedResponse = CheckConsistencyResponse.newBuilder().setConsistent(true).build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    String name = "name3373707";
    String consistencyToken = "consistencyToken-1985152319";
    CheckConsistencyResponse actualResponse = client.checkConsistency(name, consistencyToken);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CheckConsistencyRequest actualRequest = ((CheckConsistencyRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertEquals(consistencyToken, actualRequest.getConsistencyToken());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) CheckConsistencyResponse(com.google.bigtable.admin.v2.CheckConsistencyResponse) ByteString(com.google.protobuf.ByteString) CheckConsistencyRequest(com.google.bigtable.admin.v2.CheckConsistencyRequest) Test(org.junit.Test)

Example 2 with CheckConsistencyRequest

use of com.google.bigtable.admin.v2.CheckConsistencyRequest in project java-bigtable by googleapis.

the class BaseBigtableTableAdminClientTest method checkConsistencyTest.

@Test
public void checkConsistencyTest() throws Exception {
    CheckConsistencyResponse expectedResponse = CheckConsistencyResponse.newBuilder().setConsistent(true).build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
    String consistencyToken = "consistencyToken-1985152319";
    CheckConsistencyResponse actualResponse = client.checkConsistency(name, consistencyToken);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CheckConsistencyRequest actualRequest = ((CheckConsistencyRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(consistencyToken, actualRequest.getConsistencyToken());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : TableName(com.google.bigtable.admin.v2.TableName) AbstractMessage(com.google.protobuf.AbstractMessage) CheckConsistencyResponse(com.google.bigtable.admin.v2.CheckConsistencyResponse) ByteString(com.google.protobuf.ByteString) CheckConsistencyRequest(com.google.bigtable.admin.v2.CheckConsistencyRequest) Test(org.junit.Test)

Example 3 with CheckConsistencyRequest

use of com.google.bigtable.admin.v2.CheckConsistencyRequest in project java-bigtable by googleapis.

the class AwaitReplicationCallableTest method testCheckFailure.

@Test
public void testCheckFailure() throws Exception {
    GenerateConsistencyTokenRequest expectedRequest = GenerateConsistencyTokenRequest.newBuilder().setName(TABLE_NAME.toString()).build();
    GenerateConsistencyTokenResponse expectedResponse = GenerateConsistencyTokenResponse.newBuilder().setConsistencyToken("fake-token").build();
    Mockito.when(mockGenerateConsistencyTokenCallable.futureCall(expectedRequest, CALL_CONTEXT)).thenReturn(ApiFutures.immediateFuture(expectedResponse));
    CheckConsistencyRequest expectedRequest2 = CheckConsistencyRequest.newBuilder().setName(TABLE_NAME.toString()).setConsistencyToken("fake-token").build();
    FakeApiException expectedError = new FakeApiException("fake", null, Code.INTERNAL, false);
    Mockito.when(mockCheckConsistencyCallable.futureCall(expectedRequest2, CALL_CONTEXT)).thenReturn(ApiFutures.<CheckConsistencyResponse>immediateFailedFuture(expectedError));
    ApiFuture<Void> future = callable.futureCall(TABLE_NAME, CALL_CONTEXT);
    Throwable actualError = null;
    try {
        future.get();
    } catch (ExecutionException e) {
        actualError = e.getCause();
    }
    assertThat(actualError).isSameInstanceAs(expectedError);
}
Also used : GenerateConsistencyTokenRequest(com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest) GenerateConsistencyTokenResponse(com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse) ExecutionException(java.util.concurrent.ExecutionException) CheckConsistencyRequest(com.google.bigtable.admin.v2.CheckConsistencyRequest) FakeApiException(com.google.api.gax.rpc.testing.FakeApiException) Test(org.junit.Test)

Example 4 with CheckConsistencyRequest

use of com.google.bigtable.admin.v2.CheckConsistencyRequest in project java-bigtable by googleapis.

the class AwaitReplicationCallableTest method testPollingTimeout.

@Test
public void testPollingTimeout() throws Exception {
    GenerateConsistencyTokenRequest expectedRequest = GenerateConsistencyTokenRequest.newBuilder().setName(TABLE_NAME.toString()).build();
    GenerateConsistencyTokenResponse expectedResponse = GenerateConsistencyTokenResponse.newBuilder().setConsistencyToken("fake-token").build();
    Mockito.when(mockGenerateConsistencyTokenCallable.futureCall(expectedRequest, CALL_CONTEXT)).thenReturn(ApiFutures.immediateFuture(expectedResponse));
    CheckConsistencyRequest expectedRequest2 = CheckConsistencyRequest.newBuilder().setName(TABLE_NAME.toString()).setConsistencyToken("fake-token").build();
    CheckConsistencyResponse expectedResponse2 = CheckConsistencyResponse.newBuilder().setConsistent(false).build();
    Mockito.when(mockCheckConsistencyCallable.futureCall(expectedRequest2, CALL_CONTEXT)).thenReturn(ApiFutures.immediateFuture(expectedResponse2));
    ApiFuture<Void> consistentFuture = callable.futureCall(TABLE_NAME, CALL_CONTEXT);
    Throwable actualError = null;
    try {
        consistentFuture.get(1, TimeUnit.SECONDS);
    } catch (ExecutionException e) {
        actualError = e.getCause();
    }
    assertThat(actualError).isInstanceOf(PollException.class);
}
Also used : GenerateConsistencyTokenRequest(com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest) CheckConsistencyResponse(com.google.bigtable.admin.v2.CheckConsistencyResponse) GenerateConsistencyTokenResponse(com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse) ExecutionException(java.util.concurrent.ExecutionException) CheckConsistencyRequest(com.google.bigtable.admin.v2.CheckConsistencyRequest) Test(org.junit.Test)

Example 5 with CheckConsistencyRequest

use of com.google.bigtable.admin.v2.CheckConsistencyRequest in project java-bigtable by googleapis.

the class AwaitReplicationCallableTest method testPolling.

@Test
public void testPolling() throws Exception {
    GenerateConsistencyTokenRequest expectedRequest = GenerateConsistencyTokenRequest.newBuilder().setName(TABLE_NAME.toString()).build();
    GenerateConsistencyTokenResponse expectedResponse = GenerateConsistencyTokenResponse.newBuilder().setConsistencyToken("fake-token").build();
    Mockito.when(mockGenerateConsistencyTokenCallable.futureCall(expectedRequest, CALL_CONTEXT)).thenReturn(ApiFutures.immediateFuture(expectedResponse));
    CheckConsistencyRequest expectedRequest2 = CheckConsistencyRequest.newBuilder().setName(TABLE_NAME.toString()).setConsistencyToken("fake-token").build();
    CheckConsistencyResponse expectedResponse2 = CheckConsistencyResponse.newBuilder().setConsistent(false).build();
    CheckConsistencyResponse expectedResponse3 = CheckConsistencyResponse.newBuilder().setConsistent(true).build();
    Mockito.when(mockCheckConsistencyCallable.futureCall(expectedRequest2, CALL_CONTEXT)).thenReturn(ApiFutures.immediateFuture(expectedResponse2)).thenReturn(ApiFutures.immediateFuture(expectedResponse3));
    ApiFuture<Void> consistentFuture = callable.futureCall(TABLE_NAME, CALL_CONTEXT);
    consistentFuture.get(1, TimeUnit.SECONDS);
}
Also used : GenerateConsistencyTokenRequest(com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest) CheckConsistencyResponse(com.google.bigtable.admin.v2.CheckConsistencyResponse) GenerateConsistencyTokenResponse(com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse) CheckConsistencyRequest(com.google.bigtable.admin.v2.CheckConsistencyRequest) Test(org.junit.Test)

Aggregations

CheckConsistencyRequest (com.google.bigtable.admin.v2.CheckConsistencyRequest)6 CheckConsistencyResponse (com.google.bigtable.admin.v2.CheckConsistencyResponse)6 Test (org.junit.Test)6 GenerateConsistencyTokenRequest (com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest)4 GenerateConsistencyTokenResponse (com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse)4 AbstractMessage (com.google.protobuf.AbstractMessage)2 ByteString (com.google.protobuf.ByteString)2 ExecutionException (java.util.concurrent.ExecutionException)2 ExponentialPollAlgorithm (com.google.api.gax.retrying.ExponentialPollAlgorithm)1 ResultRetryAlgorithm (com.google.api.gax.retrying.ResultRetryAlgorithm)1 RetryAlgorithm (com.google.api.gax.retrying.RetryAlgorithm)1 ScheduledRetryingExecutor (com.google.api.gax.retrying.ScheduledRetryingExecutor)1 FakeApiException (com.google.api.gax.rpc.testing.FakeApiException)1 TableName (com.google.bigtable.admin.v2.TableName)1