From 4ae3434dd42750ea0107451b8348b78d747d38e7 Mon Sep 17 00:00:00 2001 From: elisheva-qlogic Date: Thu, 25 Oct 2018 13:14:30 -0400 Subject: [PATCH 1/5] sync methods added --- .../bigtable/data/v2/BigtableDataClient.java | 164 +++++++++++++++++- .../data/v2/BigtableDataClientTest.java | 109 +++++++++++- 2 files changed, 268 insertions(+), 5 deletions(-) diff --git a/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java b/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java index 4a7a48d33575..4cd7fc2ff42b 100644 --- a/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java +++ b/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java @@ -18,6 +18,7 @@ import com.google.api.core.ApiFuture; import com.google.api.core.BetaApi; import com.google.api.core.InternalApi; +import com.google.api.gax.rpc.ApiExceptions; import com.google.api.gax.rpc.ResponseObserver; import com.google.api.gax.rpc.ServerStream; import com.google.api.gax.rpc.ServerStreamingCallable; @@ -128,6 +129,54 @@ public static BigtableDataClient create(BigtableDataSettings settings) throws IO this.stub = stub; } + /** + * Convenience method for synchronously reading a single row. If the row does not exist, the + * value will be null. + * + *

Sample code: + * + *

{code
+   * InstanceName instanceName = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   * try (BigtableDataClient bigtableDataClient = BigtableDataClient.create(instanceName)) {
+   *   String tableId = "[TABLE]";
+   *
+   *   Row row = bigtableDataClient.readRow(tableId, ByteString.copyFromUtf8("key"));
+   *   // Do something with row, for example, display all cells
+   *   System.out.println(row.getKey().toStringUtf8());
+   *   for(RowCell cell : row.getCells()) {
+   *     System.out.println("Family: " + cell.getFamily() + "   Qualifier: " + cell.getQualifier().toStringUtf8() + "   Value: " + cell.getValue().toStringUtf8());
+   *   }
+   * }
+   * }
+ */ + public Row readRow(String tableId, ByteString rowKey) { + return ApiExceptions.callAndTranslateApiException(readRowAsync(tableId, rowKey)); + } + + /** + * Convenience method for synchronously reading a single row. If the row does not exist, the + * value will be null. + * + *

Sample code: + * + *

{code
+   * InstanceName instanceName = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   * try (BigtableDataClient bigtableDataClient = BigtableDataClient.create(instanceName)) {
+   *   String tableId = "[TABLE]";
+   *
+   *   Row row = bigtableDataClient.readRow(tableId, "key");
+   *   // Do something with row, for example, display all cells
+   *   System.out.println(row.getKey().toStringUtf8());
+   *   for(RowCell cell : row.getCells()) {
+   *     System.out.println("Family: " + cell.getFamily() + "   Qualifier: " + cell.getQualifier().toStringUtf8() + "   Value: " + cell.getValue().toStringUtf8());
+   *   }
+   * }
+   * }
+ */ + public Row readRow(String tableId, String rowKey) { + return ApiExceptions.callAndTranslateApiException(readRowAsync(tableId, rowKey)); + } + /** * Convenience method for asynchronously reading a single row. If the row does not exist, the * future's value will be null. @@ -296,6 +345,29 @@ public ServerStreamingCallable readRowsCallable(RowAdapterSample code: + * + *
{@code
+   * InstanceName instanceName = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   * try (BigtableDataClient bigtableDataClient = BigtableDataClient.create(instanceName)) {
+   *   String tableId = "[TABLE_ID]";
+   *
+   *   List keyOffsets = bigtableDataClient.sampleRowKeys(tableId);
+   *   for(KeyOffset keyOffset : keyOffsets) {
+   *   // Do something with keyOffset
+   *   }
+   * }
+   * }
+ */ + public List sampleRowKeys(String tableId) { + return ApiExceptions.callAndTranslateApiException(sampleRowKeysAsync(tableId)); + } + /** * Convenience method to asynchronously return a sample of row keys in the table. The returned row * keys will delimit contiguous sections of the table of approximately equal size, which can be @@ -337,6 +409,26 @@ public UnaryCallable> sampleRowKeysCallable() { return stub.sampleRowKeysCallable(); } + /** + * Convenience method to synchronously mutate a single row atomically. Cells already present in + * the row are left unchanged unless explicitly changed by the {@link RowMutation}. + * + *

Sample code: + * + *

{@code
+   * InstanceName instanceName = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   * try (BigtableDataClient bigtableDataClient = BigtableDataClient.create(instanceName)) {
+   *   RowMutation mutation = RowMutation.create("[TABLE]", "[ROW KEY]")
+   *     .setCell("[FAMILY NAME]", "[QUALIFIER]", "[VALUE]");
+   *
+   *   bigtableDataClient.mutateRow(mutation);
+   * }
+   * }
+ */ + public void mutateRow(RowMutation rowMutation) { + ApiExceptions.callAndTranslateApiException(mutateRowAsync(rowMutation)); + } + /** * Convenience method to asynchronously mutate a single row atomically. Cells already present in * the row are left unchanged unless explicitly changed by the {@link RowMutation}. @@ -405,6 +497,28 @@ public BulkMutationBatcher newBulkMutationBatcher() { return new BulkMutationBatcher(stub.bulkMutateRowsBatchingCallable()); } + /** + * Convenience method to mutate multiple rows in a batch. Each individual row is mutated + * atomically as in MutateRow, but the entire batch is not executed atomically. Unlike {@link + * #newBulkMutationBatcher()}, this method expects the mutations to be pre-batched. + * + *

Sample code: + * + *

{@code
+   * InstanceName instanceName = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   * try (BigtableDataClient bigtableDataClient = BigtableDataClient.create(instanceName)) {
+   *   BulkMutation batch = BulkMutation.create("[TABLE]");
+   *   for (String someValue : someCollection) {
+   *     batch.add("[ROW KEY]", Mutation.create().setCell("[FAMILY NAME]", "[QUALIFIER]", "[VALUE]"));
+   *   }
+   *   bigtableDataClient.bulkMutateRows(batch);
+   * }
+   * }
+ */ + public void bulkMutateRows(BulkMutation mutation) { + ApiExceptions.callAndTranslateApiException(bulkMutateRowsAsync(mutation)); + } + /** * Convenience method to mutate multiple rows in a batch. Each individual row is mutated * atomically as in MutateRow, but the entire batch is not executed atomically. Unlike {@link @@ -417,7 +531,7 @@ public BulkMutationBatcher newBulkMutationBatcher() { * try (BigtableClient bigtableClient = BigtableClient.create(instanceName)) { * BulkMutation batch = BulkMutation.create("[TABLE]"); * for (String someValue : someCollection) { - * batch.add("[ROW KEY]", Mutation.create().setCell("[FAMILY NAME]", "[QUALIFIER]", "[VALUE]"); + * batch.add("[ROW KEY]", Mutation.create().setCell("[FAMILY NAME]", "[QUALIFIER]", "[VALUE]")); * } * ApiFuture result = bigtableClient.bulkMutateRowsAsync(batch); * } @@ -439,7 +553,7 @@ public ApiFuture bulkMutateRowsAsync(BulkMutation mutation) { * try (BigtableClient bigtableClient = BigtableClient.create(instanceName)) { * BulkMutation batch = BulkMutation.create("[TABLE]"); * for (String someValue : someCollection) { - * batch.add("[ROW KEY]", Mutation.create().setCell("[FAMILY NAME]", "[QUALIFIER]", "[VALUE]"); + * batch.add("[ROW KEY]", Mutation.create().setCell("[FAMILY NAME]", "[QUALIFIER]", "[VALUE]")); * } * bigtableClient.bulkMutateRowsCallable().call(batch); * } @@ -449,6 +563,29 @@ public UnaryCallable bulkMutationCallable() { return stub.bulkMutateRowsCallable(); } + /** + * Convenience method to synchronously mutate a row atomically based on the output of a filter. + * + *

Sample code: + * + *

{@code
+   * InstanceName instanceName = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   * try (BigtableDataClient bigtableDataClient = BigtableDataClient.create(instanceName)) {
+   *   ConditionalRowMutation mutation = ConditionalRowMutation.create("[TABLE]", "[KEY]")
+   *     .condition(FILTERS.value().regex("old-value"))
+   *     .then(
+   *       Mutation.create()
+   *         .setCell("[FAMILY]", "[QUALIFIER]", "[VALUE]")
+   *       );
+   *
+   *   Boolean result = bigtableDataClient.checkAndMutateRow(mutation);
+   * }
+   * }
+ */ + public Boolean checkAndMutateRow(ConditionalRowMutation mutation) { + return ApiExceptions.callAndTranslateApiException(checkAndMutateRowAsync(mutation)); + } + /** * Convenience method to asynchronously mutate a row atomically based on the output of a filter. * @@ -495,6 +632,29 @@ public UnaryCallable checkAndMutateRowCallable( return stub.checkAndMutateRowCallable(); } + /** + * Convenience method that synchronously modifies a row atomically on the server. The method + * reads the latest existing timestamp and value from the specified columns and writes a new + * entry. The new value for the timestamp is the greater of the existing timestamp or the current + * server time. The method returns the new contents of all modified cells. + * + *

Sample code: + * + *

{@code
+   * InstanceName instanceName = InstanceName.of("[PROJECT]", "[INSTANCE]");
+   * try (BigtableDataClient bigtableDataClient = BigtableDataClient.create(instanceName)) {
+   *   ReadModifyWriteRow mutation = ReadModifyWriteRow.create("[TABLE]", "[KEY]")
+   *     .increment("[FAMILY]", "[QUALIFIER]", 1)
+   *     .append("[FAMILY2]", "[QUALIFIER2]", "suffix");
+   *
+   *   Row success = bigtableDataClient.readModifyWriteRow(mutation);
+   * }
+   * }
+ */ + public Row readModifyWriteRow(ReadModifyWriteRow mutation) { + return ApiExceptions.callAndTranslateApiException(readModifyWriteRowAsync(mutation)); + } + /** * Convenience method that asynchronously modifies a row atomically on the server. The method * reads the latest existing timestamp and value from the specified columns and writes a new diff --git a/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java b/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java index 9aee30878d9c..7dc62f48040d 100644 --- a/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java +++ b/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java @@ -16,8 +16,10 @@ package com.google.cloud.bigtable.data.v2; import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Matchers.any; import com.google.api.core.ApiFuture; +import com.google.api.core.ApiFutures; import com.google.api.core.SettableApiFuture; import com.google.api.gax.grpc.GrpcStatusCode; import com.google.api.gax.rpc.ApiException; @@ -37,10 +39,13 @@ import com.google.cloud.bigtable.data.v2.models.Query; import com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow; import com.google.cloud.bigtable.data.v2.models.Row; +import com.google.cloud.bigtable.data.v2.models.RowCell; import com.google.cloud.bigtable.data.v2.models.RowMutation; import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub; import com.google.protobuf.ByteString; +import com.google.protobuf.Empty; import io.grpc.Status.Code; +import java.util.Collections; import java.util.List; import java.util.concurrent.TimeoutException; import org.junit.Before; @@ -51,6 +56,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; import org.threeten.bp.Duration; @RunWith(MockitoJUnitRunner.class) @@ -115,7 +121,6 @@ public void proxyReadRowAsyncTest() { @Test public void proxyReadRowStrAsyncTest() { bigtableDataClient.readRowAsync("fake-table", "fake-row-key"); - ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(Query.class); Mockito.verify(mockReadRowsCallable.first()).futureCall(requestCaptor.capture()); @@ -131,6 +136,48 @@ public void proxyReadRowStrAsyncTest() { .build()); } + @Test + public void readRowTest() { + Mockito.when(mockReadRowsCallable.first().futureCall(any(Query.class))) + .thenReturn(ApiFutures.immediateFuture(Row.create(ByteString.copyFromUtf8("fake-row-key"), Collections.emptyList()))); + bigtableDataClient.readRow("fake-table", ByteString.copyFromUtf8("fake-row-key")); + + ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(Query.class); + Mockito.verify(mockReadRowsCallable.first()).futureCall(requestCaptor.capture()); + + RequestContext ctx = + RequestContext.create(InstanceName.of("fake-project", "fake-instance"), "fake-profile"); + // NOTE: limit(1) is added by the mocked first() call, so it's not tested here + assertThat(requestCaptor.getValue().toProto(ctx)) + .isEqualTo( + ReadRowsRequest.newBuilder() + .setTableName("projects/fake-project/instances/fake-instance/tables/fake-table") + .setAppProfileId("fake-profile") + .setRows(RowSet.newBuilder().addRowKeys(ByteString.copyFromUtf8("fake-row-key"))) + .build()); + } + + @Test + public void readRowStrTest() { + Mockito.when(mockReadRowsCallable.first().futureCall(any(Query.class))) + .thenReturn(ApiFutures.immediateFuture(Row.create(ByteString.copyFromUtf8("fake-row-key"), Collections.emptyList()))); + bigtableDataClient.readRow("fake-table", "fake-row-key"); + + ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(Query.class); + Mockito.verify(mockReadRowsCallable.first()).futureCall(requestCaptor.capture()); + + RequestContext ctx = + RequestContext.create(InstanceName.of("fake-project", "fake-instance"), "fake-profile"); + // NOTE: limit(1) is added by the mocked first() call, so it's not tested here + assertThat(requestCaptor.getValue().toProto(ctx)) + .isEqualTo( + ReadRowsRequest.newBuilder() + .setTableName("projects/fake-project/instances/fake-instance/tables/fake-table") + .setAppProfileId("fake-profile") + .setRows(RowSet.newBuilder().addRowKeys(ByteString.copyFromUtf8("fake-row-key"))) + .build()); + } + @Test public void proxyReadRowsSyncTest() { Query query = Query.create("fake-table"); @@ -160,6 +207,13 @@ public void proxySampleRowKeysTest() { Mockito.verify(mockSampleRowKeysCallable).futureCall("fake-table"); } + @Test + public void sampleRowKeysTest() { + Mockito.when(mockSampleRowKeysCallable.futureCall(any(String.class))).thenReturn(ApiFutures.immediateFuture(Collections.emptyList())); + bigtableDataClient.sampleRowKeys("fake-table"); + Mockito.verify(mockSampleRowKeysCallable).futureCall("fake-table"); + } + @Test public void proxyMutateRowCallableTest() { assertThat(bigtableDataClient.mutateRowCallable()).isSameAs(mockMutateRowCallable); @@ -168,13 +222,26 @@ public void proxyMutateRowCallableTest() { @Test public void proxyMutateRowTest() { RowMutation request = - RowMutation.create("fake-table", "some-key") - .setCell("some-family", "fake-qualifier", "fake-value"); + RowMutation.create("fake-table", "some-key") + .setCell("some-family", "fake-qualifier", "fake-value"); bigtableDataClient.mutateRowAsync(request); Mockito.verify(mockMutateRowCallable).futureCall(request); } + @Test + public void mutateRowTest() { + Mockito.when(mockMutateRowCallable.futureCall(any(RowMutation.class))) + .thenAnswer((Answer) (invocationOnMock) -> ApiFutures.immediateFuture(Empty.getDefaultInstance())); + + RowMutation request = + RowMutation.create("fake-table", "some-key") + .setCell("some-family", "fake-qualifier", "fake-value"); + + bigtableDataClient.mutateRow(request); + Mockito.verify(mockMutateRowCallable).futureCall(request); + } + @Test public void proxyBulkMutatesRowTest() { BulkMutation request = @@ -187,6 +254,21 @@ public void proxyBulkMutatesRowTest() { Mockito.verify(mockBulkMutateRowsCallable).futureCall(request); } + @Test + public void bulkMutatesRowTest() { + Mockito.when(mockBulkMutateRowsCallable.futureCall(any(BulkMutation.class))) + .thenAnswer((Answer) (invocationOnMock) -> ApiFutures.immediateFuture(Empty.getDefaultInstance())); + + BulkMutation request = + BulkMutation.create("fake-table") + .add( + "fake-key", + Mutation.create().setCell("fake-family", "fake-qualifier", "fake-value")); + + bigtableDataClient.bulkMutateRows(request); + Mockito.verify(mockBulkMutateRowsCallable).futureCall(request); + } + @Test public void proxyBulkMutationsBatchingSendTest() { BulkMutationBatcher batcher = bigtableDataClient.newBulkMutationBatcher(); @@ -291,6 +373,17 @@ public void proxyCheckAndMutateRowTest() { Mockito.verify(mockCheckAndMutateRowCallable).futureCall(mutation); } + @Test + public void checkAndMutateRowTest() { + Mockito.when(mockCheckAndMutateRowCallable.futureCall(any(ConditionalRowMutation.class))).thenReturn(ApiFutures.immediateFuture(Boolean.TRUE)); + ConditionalRowMutation mutation = + ConditionalRowMutation.create("fake-table", "fake-key") + .then(Mutation.create().setCell("fake-family", "fake-qualifier", "fake-value")); + bigtableDataClient.checkAndMutateRow(mutation); + + Mockito.verify(mockCheckAndMutateRowCallable).futureCall(mutation); + } + @Test public void proxyReadModifyWriteRowTest() { ReadModifyWriteRow request = @@ -300,6 +393,16 @@ public void proxyReadModifyWriteRowTest() { Mockito.verify(mockReadModifyWriteRowCallable).futureCall(request); } + @Test + public void readModifyWriteRowTest() { + Mockito.when(mockReadModifyWriteRowCallable.futureCall(any(ReadModifyWriteRow.class))).thenReturn(ApiFutures.immediateFuture(Row.create(ByteString.copyFromUtf8("fake-row-key"), Collections.emptyList()))); + ReadModifyWriteRow request = + ReadModifyWriteRow.create("fake-table", "some-key") + .append("fake-family", "fake-qualifier", "suffix"); + bigtableDataClient.readModifyWriteRow(request); + Mockito.verify(mockReadModifyWriteRowCallable).futureCall(request); + } + @Test public void proxyReadModifyWriterRowCallableTest() { assertThat(bigtableDataClient.readModifyWriteRowCallable()) From 0d20ded5a55ea75636c6095798440452b05759ae Mon Sep 17 00:00:00 2001 From: elisheva-qlogic Date: Mon, 29 Oct 2018 10:44:36 -0400 Subject: [PATCH 2/5] docs update --- .../bigtable/data/v2/BigtableDataClient.java | 62 +++++++++++++++---- 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java b/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java index 4d4df5c45dac..52dbe0393382 100644 --- a/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java +++ b/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java @@ -150,12 +150,18 @@ public static BigtableDataClient create(BigtableDataSettings settings) throws IO * * Row row = bigtableDataClient.readRow(tableId, ByteString.copyFromUtf8("key")); * // Do something with row, for example, display all cells - * System.out.println(row.getKey().toStringUtf8()); - * for(RowCell cell : row.getCells()) { - * System.out.println("Family: " + cell.getFamily() + " Qualifier: " + cell.getQualifier().toStringUtf8() + " Value: " + cell.getValue().toStringUtf8()); + * if(row != null) { + * System.out.println(row.getKey().toStringUtf8()); + * for(RowCell cell : row.getCells()) { + * System.out.println("Family: " + cell.getFamily() + " Qualifier: " + cell.getQualifier().toStringUtf8() + " Value: " + cell.getValue().toStringUtf8()); + * } * } - * } + * } catch(ApiException e) { + * e.printStackTrace(); + * } * } + * + * @throws com.google.api.gax.rpc.ApiException when a serverside error occurs */ public Row readRow(String tableId, ByteString rowKey) { return ApiExceptions.callAndTranslateApiException(readRowAsync(tableId, rowKey)); @@ -174,12 +180,18 @@ public Row readRow(String tableId, ByteString rowKey) { * * Row row = bigtableDataClient.readRow(tableId, "key"); * // Do something with row, for example, display all cells - * System.out.println(row.getKey().toStringUtf8()); - * for(RowCell cell : row.getCells()) { - * System.out.println("Family: " + cell.getFamily() + " Qualifier: " + cell.getQualifier().toStringUtf8() + " Value: " + cell.getValue().toStringUtf8()); + * if(row != null) { + * System.out.println(row.getKey().toStringUtf8()); + * for(RowCell cell : row.getCells()) { + * System.out.println("Family: " + cell.getFamily() + " Qualifier: " + cell.getQualifier().toStringUtf8() + " Value: " + cell.getValue().toStringUtf8()); + * } * } - * } + * } catch(ApiException e) { + * e.printStackTrace(); + * } * } + * + * @throws com.google.api.gax.rpc.ApiException when a serverside error occurs */ public Row readRow(String tableId, String rowKey) { return ApiExceptions.callAndTranslateApiException(readRowAsync(tableId, rowKey)); @@ -439,8 +451,12 @@ public ServerStreamingCallable readRowsCallable(RowAdapter + * + * @throws com.google.api.gax.rpc.ApiException when a serverside error occurs */ public List sampleRowKeys(String tableId) { return ApiExceptions.callAndTranslateApiException(sampleRowKeysAsync(tableId)); @@ -532,8 +548,12 @@ public UnaryCallable> sampleRowKeysCallable() { * .setCell("[FAMILY NAME]", "[QUALIFIER]", "[VALUE]"); * * bigtableDataClient.mutateRow(mutation); - * } + * } catch(ApiException e) { + * e.printStackTrace(); + * } * } + * + * @throws com.google.api.gax.rpc.ApiException when a serverside error occurs */ public void mutateRow(RowMutation rowMutation) { ApiExceptions.callAndTranslateApiException(mutateRowAsync(rowMutation)); @@ -642,8 +662,16 @@ public BulkMutationBatcher newBulkMutationBatcher() { * batch.add("[ROW KEY]", Mutation.create().setCell("[FAMILY NAME]", "[QUALIFIER]", "[VALUE]")); * } * bigtableDataClient.bulkMutateRows(batch); - * } + * } catch(ApiException e) { + * e.printStackTrace(); + * } + * catch(MutateRowsException e) { + * e.printStackTrace(); + * } * } + * + * @throws com.google.api.gax.rpc.ApiException when a serverside error occurs + * @throws com.google.cloud.bigtable.data.v2.models.MutateRowsException if any of the entries failed to be applied */ public void bulkMutateRows(BulkMutation mutation) { ApiExceptions.callAndTranslateApiException(bulkMutateRowsAsync(mutation)); @@ -724,8 +752,12 @@ public UnaryCallable bulkMutationCallable() { * ); * * Boolean result = bigtableDataClient.checkAndMutateRow(mutation); - * } + * } catch(ApiException e) { + * e.printStackTrace(); + * } * } + * + * @throws com.google.api.gax.rpc.ApiException when a serverside error occurs */ public Boolean checkAndMutateRow(ConditionalRowMutation mutation) { return ApiExceptions.callAndTranslateApiException(checkAndMutateRowAsync(mutation)); @@ -816,8 +848,12 @@ public UnaryCallable checkAndMutateRowCallable( * .append("[FAMILY2]", "[QUALIFIER2]", "suffix"); * * Row success = bigtableDataClient.readModifyWriteRow(mutation); - * } + * } catch(ApiException e) { + * e.printStackTrace(); + * } * } + * + * @throws com.google.api.gax.rpc.ApiException when a serverside error occurs */ public Row readModifyWriteRow(ReadModifyWriteRow mutation) { return ApiExceptions.callAndTranslateApiException(readModifyWriteRowAsync(mutation)); From 4142b4204f214790f0a0fbaac5becebb74fb2773 Mon Sep 17 00:00:00 2001 From: elisheva-qlogic Date: Mon, 29 Oct 2018 14:14:14 -0400 Subject: [PATCH 3/5] fixed_whitespace --- .../bigtable/data/v2/BigtableDataClient.java | 41 ++++++++++--------- .../data/v2/BigtableDataClientTest.java | 9 ++-- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java b/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java index 6264b004d09a..e36e7900057b 100644 --- a/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java +++ b/google-cloud-clients/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java @@ -157,8 +157,8 @@ public static BigtableDataClient create(BigtableDataSettings settings) throws IO * } * } * } catch(ApiException e) { - * e.printStackTrace(); - * } + * e.printStackTrace(); + * } * } * * @throws com.google.api.gax.rpc.ApiException when a serverside error occurs @@ -187,8 +187,8 @@ public Row readRow(String tableId, ByteString rowKey) { * } * } * } catch(ApiException e) { - * e.printStackTrace(); - * } + * e.printStackTrace(); + * } * } * * @throws com.google.api.gax.rpc.ApiException when a serverside error occurs @@ -219,7 +219,9 @@ public Row readRow(String tableId, String rowKey) { * } * } * public void onSuccess(Row result) { - * System.out.println("Got row: " + result); + * if (result != null) { + * System.out.println("Got row: " + result); + * } * } * }, MoreExecutors.directExecutor()); * } @@ -251,7 +253,9 @@ public ApiFuture readRowAsync(String tableId, String rowKey) { * } * } * public void onSuccess(Row row) { - * System.out.println("Got row: " + row); + * if (result != null) { + * System.out.println("Got row: " + result); + * } * } * }, MoreExecutors.directExecutor()); * } @@ -452,8 +456,8 @@ public ServerStreamingCallable readRowsCallable(RowAdapter * * @throws com.google.api.gax.rpc.ApiException when a serverside error occurs @@ -549,8 +553,8 @@ public UnaryCallable> sampleRowKeysCallable() { * * bigtableDataClient.mutateRow(mutation); * } catch(ApiException e) { - * e.printStackTrace(); - * } + * e.printStackTrace(); + * } * } * * @throws com.google.api.gax.rpc.ApiException when a serverside error occurs @@ -663,11 +667,10 @@ public BulkMutationBatcher newBulkMutationBatcher() { * } * bigtableDataClient.bulkMutateRows(batch); * } catch(ApiException e) { - * e.printStackTrace(); - * } - * catch(MutateRowsException e) { - * e.printStackTrace(); - * } + * e.printStackTrace(); + * } catch(MutateRowsException e) { + * e.printStackTrace(); + * } * } * * @throws com.google.api.gax.rpc.ApiException when a serverside error occurs @@ -753,8 +756,8 @@ public UnaryCallable bulkMutationCallable() { * * Boolean result = bigtableDataClient.checkAndMutateRow(mutation); * } catch(ApiException e) { - * e.printStackTrace(); - * } + * e.printStackTrace(); + * } * } * * @throws com.google.api.gax.rpc.ApiException when a serverside error occurs @@ -849,8 +852,8 @@ public UnaryCallable checkAndMutateRowCallable( * * Row success = bigtableDataClient.readModifyWriteRow(mutation); * } catch(ApiException e) { - * e.printStackTrace(); - * } + * e.printStackTrace(); + * } * } * * @throws com.google.api.gax.rpc.ApiException when a serverside error occurs diff --git a/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java b/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java index 7dc62f48040d..ffaebcdab63d 100644 --- a/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java +++ b/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java @@ -139,7 +139,8 @@ public void proxyReadRowStrAsyncTest() { @Test public void readRowTest() { Mockito.when(mockReadRowsCallable.first().futureCall(any(Query.class))) - .thenReturn(ApiFutures.immediateFuture(Row.create(ByteString.copyFromUtf8("fake-row-key"), Collections.emptyList()))); + .thenReturn(ApiFutures.immediateFuture( + Row.create(ByteString.copyFromUtf8("fake-row-key"), Collections.emptyList()))); bigtableDataClient.readRow("fake-table", ByteString.copyFromUtf8("fake-row-key")); ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(Query.class); @@ -160,7 +161,8 @@ public void readRowTest() { @Test public void readRowStrTest() { Mockito.when(mockReadRowsCallable.first().futureCall(any(Query.class))) - .thenReturn(ApiFutures.immediateFuture(Row.create(ByteString.copyFromUtf8("fake-row-key"), Collections.emptyList()))); + .thenReturn(ApiFutures.immediateFuture( + Row.create(ByteString.copyFromUtf8("fake-row-key"), Collections.emptyList()))); bigtableDataClient.readRow("fake-table", "fake-row-key"); ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(Query.class); @@ -209,7 +211,8 @@ public void proxySampleRowKeysTest() { @Test public void sampleRowKeysTest() { - Mockito.when(mockSampleRowKeysCallable.futureCall(any(String.class))).thenReturn(ApiFutures.immediateFuture(Collections.emptyList())); + Mockito.when(mockSampleRowKeysCallable.futureCall(any(String.class))) + .thenReturn(ApiFutures.immediateFuture(Collections.emptyList())); bigtableDataClient.sampleRowKeys("fake-table"); Mockito.verify(mockSampleRowKeysCallable).futureCall("fake-table"); } From 31c2d79ce4c374f6e6948a0fcd74a1a15782097c Mon Sep 17 00:00:00 2001 From: elisheva-qlogic Date: Thu, 1 Nov 2018 12:13:19 -0400 Subject: [PATCH 4/5] lambdas_removed --- .../bigtable/data/v2/BigtableDataClientTest.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java b/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java index ffaebcdab63d..9595e05599fe 100644 --- a/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java +++ b/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java @@ -55,6 +55,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; import org.mockito.runners.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import org.threeten.bp.Duration; @@ -235,7 +236,12 @@ public void proxyMutateRowTest() { @Test public void mutateRowTest() { Mockito.when(mockMutateRowCallable.futureCall(any(RowMutation.class))) - .thenAnswer((Answer) (invocationOnMock) -> ApiFutures.immediateFuture(Empty.getDefaultInstance())); + .thenAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocationOnMock) throws Throwable { + return ApiFutures.immediateFuture(Empty.getDefaultInstance()); + } + }); RowMutation request = RowMutation.create("fake-table", "some-key") @@ -260,7 +266,12 @@ public void proxyBulkMutatesRowTest() { @Test public void bulkMutatesRowTest() { Mockito.when(mockBulkMutateRowsCallable.futureCall(any(BulkMutation.class))) - .thenAnswer((Answer) (invocationOnMock) -> ApiFutures.immediateFuture(Empty.getDefaultInstance())); + .thenAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocationOnMock) throws Throwable { + return ApiFutures.immediateFuture(Empty.getDefaultInstance()); + } + }); BulkMutation request = BulkMutation.create("fake-table") From 027c419a075ea3d0d9833a1fbd9f0c7847133fb5 Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Mon, 5 Nov 2018 14:06:38 -0500 Subject: [PATCH 5/5] fix compilation issues --- .../cloud/bigtable/data/v2/BigtableDataClientTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java b/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java index 9595e05599fe..2fdfe1c37401 100644 --- a/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java +++ b/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientTest.java @@ -141,7 +141,7 @@ public void proxyReadRowStrAsyncTest() { public void readRowTest() { Mockito.when(mockReadRowsCallable.first().futureCall(any(Query.class))) .thenReturn(ApiFutures.immediateFuture( - Row.create(ByteString.copyFromUtf8("fake-row-key"), Collections.emptyList()))); + Row.create(ByteString.copyFromUtf8("fake-row-key"), Collections.emptyList()))); bigtableDataClient.readRow("fake-table", ByteString.copyFromUtf8("fake-row-key")); ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(Query.class); @@ -163,7 +163,7 @@ public void readRowTest() { public void readRowStrTest() { Mockito.when(mockReadRowsCallable.first().futureCall(any(Query.class))) .thenReturn(ApiFutures.immediateFuture( - Row.create(ByteString.copyFromUtf8("fake-row-key"), Collections.emptyList()))); + Row.create(ByteString.copyFromUtf8("fake-row-key"), Collections.emptyList()))); bigtableDataClient.readRow("fake-table", "fake-row-key"); ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(Query.class); @@ -213,7 +213,7 @@ public void proxySampleRowKeysTest() { @Test public void sampleRowKeysTest() { Mockito.when(mockSampleRowKeysCallable.futureCall(any(String.class))) - .thenReturn(ApiFutures.immediateFuture(Collections.emptyList())); + .thenReturn(ApiFutures.immediateFuture(Collections.emptyList())); bigtableDataClient.sampleRowKeys("fake-table"); Mockito.verify(mockSampleRowKeysCallable).futureCall("fake-table"); }