@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).isSameAs(expectedError); }
CheckConsistencyRequest.newBuilder() .setName(TABLE_NAME.toString()) .setConsistencyToken("fake-token") .build();
@Test public void testImmediatelyConsistent() 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(true).build(); Mockito.when(mockCheckConsistencyCallable.futureCall(expectedRequest2, CALL_CONTEXT)) .thenReturn(ApiFutures.immediateFuture(expectedResponse2)); ApiFuture<Void> consistentFuture = callable.futureCall(TABLE_NAME, CALL_CONTEXT); consistentFuture.get(1, TimeUnit.MILLISECONDS); }
/** * Checks replication consistency based on a consistency token, that is, if replication has caught * up based on the conditions specified in the token and the check request. * * <p>Sample code: * * <pre><code> * try (BaseBigtableTableAdminClient baseBigtableTableAdminClient = BaseBigtableTableAdminClient.create()) { * TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); * String consistencyToken = ""; * CheckConsistencyResponse response = baseBigtableTableAdminClient.checkConsistency(name.toString(), consistencyToken); * } * </code></pre> * * @param name The unique name of the Table for which to check replication consistency. Values are * of the form `projects/<project>/instances/<instance>/tables/<table>`. * @param consistencyToken The token created using GenerateConsistencyToken for the Table. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final CheckConsistencyResponse checkConsistency(String name, String consistencyToken) { CheckConsistencyRequest request = CheckConsistencyRequest.newBuilder() .setName(name) .setConsistencyToken(consistencyToken) .build(); return checkConsistency(request); }
/** * Checks replication consistency based on a consistency token, that is, if replication has caught * up based on the conditions specified in the token and the check request. * * <p>Sample code: * * <pre><code> * try (BaseBigtableTableAdminClient baseBigtableTableAdminClient = BaseBigtableTableAdminClient.create()) { * TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); * String consistencyToken = ""; * CheckConsistencyResponse response = baseBigtableTableAdminClient.checkConsistency(name, consistencyToken); * } * </code></pre> * * @param name The unique name of the Table for which to check replication consistency. Values are * of the form `projects/<project>/instances/<instance>/tables/<table>`. * @param consistencyToken The token created using GenerateConsistencyToken for the Table. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final CheckConsistencyResponse checkConsistency(TableName name, String consistencyToken) { CheckConsistencyRequest request = CheckConsistencyRequest.newBuilder() .setName(name == null ? null : name.toString()) .setConsistencyToken(consistencyToken) .build(); return checkConsistency(request); }
@Override public ApiFuture<Void> apply(GenerateConsistencyTokenResponse input) { CheckConsistencyRequest request = CheckConsistencyRequest.newBuilder() .setName(tableName.toString()) .setConsistencyToken(input.getConsistencyToken()) .build(); return pollToken(request, context); } },
private boolean checkConsistency(BigtableTableName tableName, String token) { CheckConsistencyRequest request = CheckConsistencyRequest.newBuilder() .setName(tableName.toString()) .setConsistencyToken(token) .build(); return createUnaryListener(request, checkConsistencyRpc, request.getName()) .getBlockingResult() .getConsistent(); }
@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); }
/** * Checks replication consistency based on a consistency token, that is, if replication has caught * up based on the conditions specified in the token and the check request. * * <p>Sample code: * * <pre><code> * try (BaseBigtableTableAdminClient baseBigtableTableAdminClient = BaseBigtableTableAdminClient.create()) { * TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); * String consistencyToken = ""; * CheckConsistencyResponse response = baseBigtableTableAdminClient.checkConsistency(name.toString(), consistencyToken); * } * </code></pre> * * @param name The unique name of the Table for which to check replication consistency. Values are * of the form `projects/<project>/instances/<instance>/tables/<table>`. * @param consistencyToken The token created using GenerateConsistencyToken for the Table. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final CheckConsistencyResponse checkConsistency(String name, String consistencyToken) { CheckConsistencyRequest request = CheckConsistencyRequest.newBuilder() .setName(name) .setConsistencyToken(consistencyToken) .build(); return checkConsistency(request); }
/** * Checks replication consistency based on a consistency token, that is, if replication has caught * up based on the conditions specified in the token and the check request. * * <p>Sample code: * * <pre><code> * try (BaseBigtableTableAdminClient baseBigtableTableAdminClient = BaseBigtableTableAdminClient.create()) { * TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); * String consistencyToken = ""; * CheckConsistencyResponse response = baseBigtableTableAdminClient.checkConsistency(name, consistencyToken); * } * </code></pre> * * @param name The unique name of the Table for which to check replication consistency. Values are * of the form `projects/<project>/instances/<instance>/tables/<table>`. * @param consistencyToken The token created using GenerateConsistencyToken for the Table. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final CheckConsistencyResponse checkConsistency(TableName name, String consistencyToken) { CheckConsistencyRequest request = CheckConsistencyRequest.newBuilder() .setName(name == null ? null : name.toString()) .setConsistencyToken(consistencyToken) .build(); return checkConsistency(request); }
@Override public ApiFuture<Void> apply(GenerateConsistencyTokenResponse input) { CheckConsistencyRequest request = CheckConsistencyRequest.newBuilder() .setName(tableName.toString()) .setConsistencyToken(input.getConsistencyToken()) .build(); return pollToken(request, context); } },