Repository: GoogleCloudPlatform/cloud-bigtable-client
Pull request #2072 (2019-02-06 18:39:22)

Removing some dead code from AsyncExecutor.
This will help with the change to google-cloud-bigtable


Patch:
diff --git a/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/grpc/async/AsyncExecutor.java b/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/grpc/async/AsyncExecutor.java
index f427804eb..729fec74d 100644
--- a/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/grpc/async/AsyncExecutor.java
+++ b/bigtable-client-core-parent/bigtable-client-core/src/main/java/com/google/cloud/bigtable/grpc/async/AsyncExecutor.java
@@ -16,25 +16,14 @@
 package com.google.cloud.bigtable.grpc.async;
 
 import java.io.IOException;
-import java.util.List;
 
-import com.google.bigtable.v2.CheckAndMutateRowRequest;
-import com.google.bigtable.v2.CheckAndMutateRowResponse;
-import com.google.bigtable.v2.MutateRowRequest;
-import com.google.bigtable.v2.MutateRowResponse;
-import com.google.bigtable.v2.MutateRowsRequest;
-import com.google.bigtable.v2.MutateRowsResponse;
 import com.google.bigtable.v2.ReadModifyWriteRowRequest;
 import com.google.bigtable.v2.ReadModifyWriteRowResponse;
-import com.google.bigtable.v2.ReadRowsRequest;
-import com.google.bigtable.v2.Row;
 import com.google.cloud.bigtable.config.Logger;
 import com.google.cloud.bigtable.grpc.BigtableDataClient;
-import com.google.cloud.bigtable.grpc.scanner.FlatRow;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
-import com.google.protobuf.MessageLite;
 
 /**
  * This class provides management of asynchronous Bigtable RPCs. It ensures that there aren't too
@@ -49,80 +38,6 @@ public class AsyncExecutor {
   /** Constant <code>LOG</code> */
   protected static final Logger LOG = new Logger(AsyncExecutor.class);
 
-  protected interface AsyncCall<RequestT, ResponseT> {
-    ListenableFuture<ResponseT> call(BigtableDataClient client, RequestT request);
-  }
-
-  /**
-   * Calls {@link BigtableDataClient#mutateRowAsync(MutateRowRequest)}.
-   */
-  protected static AsyncCall<MutateRowRequest, MutateRowResponse> MUTATE_ROW_ASYNC =
-      new AsyncCall<MutateRowRequest, MutateRowResponse>() {
-        @Override
-        public ListenableFuture<MutateRowResponse> call(BigtableDataClient client, MutateRowRequest request) {
-          return client.mutateRowAsync(request);
-        }
-      };
-
-  /**
-   * Calls {@link BigtableDataClient#mutateRowsAsync(MutateRowsRequest)}.
-   */
-  protected static AsyncCall<MutateRowsRequest, List<MutateRowsResponse>> MUTATE_ROWS_ASYNC =
-      new AsyncCall<MutateRowsRequest, List<MutateRowsResponse>>() {
-        @Override
-        public ListenableFuture<List<MutateRowsResponse>> call(BigtableDataClient client,
-            MutateRowsRequest request) {
-          return client.mutateRowsAsync(request);
-        }
-      };
-
-  /**
-   * Calls {@link BigtableDataClient#readModifyWriteRowAsync(ReadModifyWriteRowRequest)}.
-   */
-  protected static AsyncCall<ReadModifyWriteRowRequest, ReadModifyWriteRowResponse> READ_MODIFY_WRITE_ASYNC =
-      new AsyncCall<ReadModifyWriteRowRequest, ReadModifyWriteRowResponse>() {
-        @Override
-        public ListenableFuture<ReadModifyWriteRowResponse> call(BigtableDataClient client,
-            ReadModifyWriteRowRequest request) {
-          return client.readModifyWriteRowAsync(request);
-        }
-      };
-
-  /**
-   * Calls {@link BigtableDataClient#checkAndMutateRowAsync(CheckAndMutateRowRequest)}.
-   */
-  protected static AsyncCall<CheckAndMutateRowRequest, CheckAndMutateRowResponse> CHECK_AND_MUTATE_ASYNC =
-      new AsyncCall<CheckAndMutateRowRequest, CheckAndMutateRowResponse>() {
-        @Override
-        public ListenableFuture<CheckAndMutateRowResponse> call(BigtableDataClient client,
-            CheckAndMutateRowRequest request) {
-          return client.checkAndMutateRowAsync(request);
-        }
-      };
-
-  /**
-   * Calls {@link BigtableDataClient#readRowsAsync(ReadRowsRequest)}.
-   */
-  protected static AsyncCall<ReadRowsRequest, List<Row>> READ_ROWS_ASYNC =
-      new AsyncCall<ReadRowsRequest, List<Row>>() {
-        @Override
-        public ListenableFuture<List<Row>> call(BigtableDataClient client, ReadRowsRequest request) {
-          return client.readRowsAsync(request);
-        }
-      };
-
-
-  /**
-   * Calls {@link BigtableDataClient#readRowsAsync(ReadRowsRequest)}.
-   */
-  protected static AsyncCall<ReadRowsRequest, List<FlatRow>> READ_FLAT_ROWS_ASYNC =
-      new AsyncCall<ReadRowsRequest, List<FlatRow>>() {
-        @Override
-        public ListenableFuture<List<FlatRow>> call(BigtableDataClient client, ReadRowsRequest request) {
-          return client.readFlatRowsAsync(request);
-        }
-      };
-
   private final BigtableDataClient client;
   private final OperationAccountant operationsAccountant;
 
@@ -152,48 +67,6 @@ public class AsyncExecutor {
     this.operationsAccountant = operationAccountant;
   }
 
-  /**
-   * Performs a {@link com.google.cloud.bigtable.grpc.BigtableDataClient#mutateRowAsync(MutateRowRequest)} on the
-   * {@link com.google.bigtable.v2.MutateRowRequest}. This method may block if
-   * {@link OperationAccountant#registerOperation(ListenableFuture)} blocks.
-   *
-   * @param request The {@link com.google.bigtable.v2.MutateRowRequest} to send.
-   * @return a {@link com.google.common.util.concurrent.ListenableFuture} which can be listened to for completion events.
-   * @throws java.lang.InterruptedException if any.
-   */
-  public ListenableFuture<MutateRowResponse> mutateRowAsync(MutateRowRequest request)
-      throws InterruptedException {
-    return call(MUTATE_ROW_ASYNC, request);
-  }
-
-  /**
-   * Performs a {@link com.google.cloud.bigtable.grpc.BigtableDataClient#mutateRowsAsync(MutateRowsRequest)} on the
-   * {@link com.google.bigtable.v2.MutateRowsRequest}. This method may block if
-   * {@link OperationAccountant#registerOperation(ListenableFuture)} blocks.
-   *
-   * @param request The {@link com.google.bigtable.v2.MutateRowRequest} to send.
-   * @return a {@link com.google.common.util.concurrent.ListenableFuture} which can be listened to for completion events.
-   * @throws java.lang.InterruptedException if any.
-   */
-  public ListenableFuture<List<MutateRowsResponse>> mutateRowsAsync(MutateRowsRequest request)
-      throws InterruptedException {
-    return call(MUTATE_ROWS_ASYNC, request);
-  }
-
-  /**
-   * Performs a {@link com.google.cloud.bigtable.grpc.BigtableDataClient#checkAndMutateRowAsync(CheckAndMutateRowRequest)} on the
-   * {@link com.google.bigtable.v2.CheckAndMutateRowRequest}. This method may block if
-   * {@link OperationAccountant#registerOperation(ListenableFuture)} blocks.
-   *
-   * @param request The {@link com.google.bigtable.v2.CheckAndMutateRowRequest} to send.
-   * @return a {@link com.google.common.util.concurrent.ListenableFuture} which can be listened to for completion events.
-   * @throws java.lang.InterruptedException if any.
-   */
-  public ListenableFuture<CheckAndMutateRowResponse> checkAndMutateRowAsync(
-      CheckAndMutateRowRequest request) throws InterruptedException {
-    return call(CHECK_AND_MUTATE_ASYNC, request);
-  }
-
   /**
    * Performs a {@link com.google.cloud.bigtable.grpc.BigtableDataClient#readModifyWriteRow(ReadModifyWriteRowRequest)} on the
    * {@link com.google.bigtable.v2.ReadModifyWriteRowRequest}. This method may block if
@@ -204,45 +77,12 @@ public class AsyncExecutor {
    * @throws java.lang.InterruptedException if any.
    */
   public ListenableFuture<ReadModifyWriteRowResponse>
-      readModifyWriteRowAsync(ReadModifyWriteRowRequest request) throws InterruptedException {
-    return call(READ_MODIFY_WRITE_ASYNC, request);
-  }
-
-  /**
-   * Performs a {@link com.google.cloud.bigtable.grpc.BigtableDataClient#readRowsAsync(ReadRowsRequest)} on the
-   * {@link com.google.bigtable.v2.ReadRowsRequest}. This method may block if
-   * {@link OperationAccountant#registerOperation(ListenableFuture)} blocks.
-   *
-   * @param request The {@link com.google.bigtable.v2.ReadRowsRequest} to send.
-   * @return a {@link com.google.common.util.concurrent.ListenableFuture} which can be listened to for completion events.
-   * @throws java.lang.InterruptedException if any.
-   */
-  public ListenableFuture<List<Row>> readRowsAsync(ReadRowsRequest request)
-      throws InterruptedException {
-    return call(READ_ROWS_ASYNC, request);
-  }
-
-  /**
-   * Performs a {@link com.google.cloud.bigtable.grpc.BigtableDataClient#readRowsAsync(ReadRowsRequest)} on the
-   * {@link com.google.bigtable.v2.ReadRowsRequest}. This method may block if
-   * {@link OperationAccountant#registerOperation(ListenableFuture)} blocks.
-   *
-   * @param request The {@link com.google.bigtable.v2.ReadRowsRequest} to send.
-   * @return a {@link com.google.common.util.concurrent.ListenableFuture} which can be listened to for completion events.
-   * @throws java.lang.InterruptedException if any.
-   */
-  public ListenableFuture<List<FlatRow>> readFlatRowsAsync(ReadRowsRequest request)
-      throws InterruptedException {
-    return call(READ_FLAT_ROWS_ASYNC, request);
-  }
-
-  private <RequestT extends MessageLite, ResponseT> ListenableFuture<ResponseT> call(
-      AsyncCall<RequestT, ResponseT> rpc, RequestT request) {
+      readModifyWriteRowAsync(ReadModifyWriteRowRequest request) {
     // Wait until both the memory and rpc count maximum requirements are achieved before getting a
     // unique id used to track this request.
-    ListenableFuture<ResponseT> future;
+    ListenableFuture<ReadModifyWriteRowResponse> future;
     try {
-      future = rpc.call(client, request);
+      future = client.readModifyWriteRowAsync(request);
     } catch (Throwable e) {
       future = Futures.immediateFailedFuture(e);
     }
@@ -278,23 +118,4 @@ public class AsyncExecutor {
     return operationsAccountant.hasInflightOperations();
   }
 
-  /**
-   * <p>
-   * Getter for the field <code>client</code>.
-   * </p>
-   * @return a {@link com.google.cloud.bigtable.grpc.BigtableDataClient} object.
-   */
-  public BigtableDataClient getClient() {
-    return client;
-  }
-
-  /**
-   * <p>
-   * Getter for the field <code>operationsAccountant</code>.
-   * </p>
-   * @return a {@link com.google.cloud.bigtable.grpc.async.OperationAccountant} object.
-   */
-  public OperationAccountant getOperationAccountant() {
-    return operationsAccountant;
-  }
 }
diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/BatchExecutor.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/BatchExecutor.java
index 83f5ba0f9..beaeb867d 100644
--- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/BatchExecutor.java
+++ b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/BatchExecutor.java
@@ -220,9 +220,6 @@ public class BatchExecutor {
       } else if (row instanceof RowMutations) {
         return bulkOperation.bulkMutation.add(requestAdapter.adaptEntry((RowMutations) row));
       }
-    } catch (InterruptedException e) {
-      Thread.currentThread().interrupt();
-      return Futures.immediateFailedFuture(new IOException("Could not process the batch due to interrupt", e));
     } catch (Throwable e) {
       return Futures.immediateFailedFuture(new IOException("Could not process the batch", e));
     }


Test patch:
diff --git a/bigtable-client-core-parent/bigtable-client-core/src/test/java/com/google/cloud/bigtable/grpc/async/TestAsyncExecutor.java b/bigtable-client-core-parent/bigtable-client-core/src/test/java/com/google/cloud/bigtable/grpc/async/TestAsyncExecutor.java
index e2e2c5683..8cec21fde 100644
--- a/bigtable-client-core-parent/bigtable-client-core/src/test/java/com/google/cloud/bigtable/grpc/async/TestAsyncExecutor.java
+++ b/bigtable-client-core-parent/bigtable-client-core/src/test/java/com/google/cloud/bigtable/grpc/async/TestAsyncExecutor.java
@@ -62,26 +62,9 @@ public class TestAsyncExecutor {
     Assert.assertFalse(underTest.hasInflightRequests());
   }
 
-  @Test
-  public void testMutation() throws InterruptedException {
-    when(client.mutateRowAsync(any(MutateRowRequest.class))).thenReturn(future);
-    underTest.mutateRowAsync(MutateRowRequest.getDefaultInstance());
-    Assert.assertTrue(underTest.hasInflightRequests());
-    future.set("");
-    Assert.assertFalse(underTest.hasInflightRequests());
-  }
-
-  @Test
-  public void testCheckAndMutate() throws InterruptedException {
-    when(client.checkAndMutateRowAsync(any(CheckAndMutateRowRequest.class))).thenReturn(future);
-    underTest.checkAndMutateRowAsync(CheckAndMutateRowRequest.getDefaultInstance());
-    Assert.assertTrue(underTest.hasInflightRequests());
-    future.set("");
-    Assert.assertFalse(underTest.hasInflightRequests());
-  }
 
   @Test
-  public void testReadWriteModify() throws InterruptedException {
+  public void testReadWriteModify()  {
     when(client.readModifyWriteRowAsync(any(ReadModifyWriteRowRequest.class))).thenReturn(future);
     underTest.readModifyWriteRowAsync(ReadModifyWriteRowRequest.getDefaultInstance());
     Assert.assertTrue(underTest.hasInflightRequests());
@@ -90,30 +73,9 @@ public class TestAsyncExecutor {
   }
 
   @Test
-  public void testReadRowsAsync() throws InterruptedException {
-    when(client.readRowsAsync(any(ReadRowsRequest.class))).thenReturn(future);
-    underTest.readRowsAsync(ReadRowsRequest.getDefaultInstance());
-    Assert.assertTrue(underTest.hasInflightRequests());
-    future.set("");
-    Assert.assertFalse(underTest.hasInflightRequests());
-  }
-
-  @Test
-  public void testReadFlatRowsAsync() throws InterruptedException {
-    when(client.readFlatRowsAsync(any(ReadRowsRequest.class))).thenReturn(future);
-    underTest.readFlatRowsAsync(ReadRowsRequest.getDefaultInstance());
-    Assert.assertTrue(underTest.hasInflightRequests());
-    future.set("");
-    Assert.assertFalse(underTest.hasInflightRequests());
-  }
-
-  @Test
-  public void testInvalidMutation() throws Exception {
-    try {
-      when(client.mutateRowAsync(any(MutateRowRequest.class))).thenThrow(new RuntimeException());
-      underTest.mutateRowAsync(MutateRowRequest.getDefaultInstance());
-    } catch(Exception ignored) {
-    }
+  public void testInvalidMutation() {
+    when(client.readModifyWriteRowAsync(any(ReadModifyWriteRowRequest.class))).thenThrow(new RuntimeException());
+    underTest.readModifyWriteRowAsync(ReadModifyWriteRowRequest.getDefaultInstance());
     future.set(ReadRowsResponse.getDefaultInstance());
     Assert.assertFalse(underTest.hasInflightRequests());
   }
diff --git a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/TestBatchExecutor.java b/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/TestBatchExecutor.java
index 3e7b71b6b..9164a0d2d 100644
--- a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/TestBatchExecutor.java
+++ b/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/TestBatchExecutor.java
@@ -24,7 +24,6 @@ import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import com.google.bigtable.v2.MutateRowRequest;
 import com.google.bigtable.v2.MutateRowsRequest;
 import com.google.bigtable.v2.ReadModifyWriteRowRequest;
 import com.google.bigtable.v2.ReadRowsRequest;
@@ -70,7 +69,6 @@ import org.mockito.MockitoAnnotations;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -134,8 +132,9 @@ public class TestBatchExecutor {
   private HBaseRequestAdapter requestAdapter;
 
   private BigtableOptions options;
+
   @Before
-  public void setup() throws InterruptedException {
+  public void setup() {
     options = BigtableOptions.builder()
         .setProjectId("projectId")
         .setInstanceId("instanceId")
@@ -196,28 +195,25 @@ public class TestBatchExecutor {
 
   @Test
   public void testShutdownService() throws Exception {
-    when(mockAsyncExecutor.mutateRowAsync(any(MutateRowRequest.class)))
-        .thenThrow(new IllegalStateException("closed"));
+    when(mockFuture.get()).thenThrow(new IllegalStateException("closed"));
     try {
       batch(Arrays.asList(randomPut()));
     } catch (RetriesExhaustedWithDetailsException e) {
       Assert.assertEquals(1, e.getCauses().size());
-      Assert.assertEquals(IOException.class, e.getCause(0).getClass());
+      Assert.assertEquals(IllegalStateException.class, e.getCause(0).getClass());
     }
   }
 
   @Test
   public void testAsyncException() throws Exception {
     String message = "Something bad happened";
-    when(mockAsyncExecutor.mutateRowAsync(any(MutateRowRequest.class)))
-        .thenThrow(new RuntimeException(message));
+    when(mockFuture.get()).thenThrow(new RuntimeException(message));
     try {
       batch(Arrays.asList(randomPut()));
     } catch (RetriesExhaustedWithDetailsException e) {
       Assert.assertEquals(1, e.getCauses().size());
-      Assert.assertEquals(IOException.class, e.getCause(0).getClass());
-      Assert.assertEquals(RuntimeException.class, e.getCause(0).getCause().getClass());
-      Assert.assertEquals(message, e.getCause(0).getCause().getMessage());
+      Assert.assertEquals(RuntimeException.class, e.getCause(0).getClass());
+      Assert.assertEquals(message, e.getCause(0).getMessage());
     }
   }
 
diff --git a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/TestBigtableBufferedMutator.java b/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/TestBigtableBufferedMutator.java
index 7ebc3fa3c..a9f6eb444 100644
--- a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/TestBigtableBufferedMutator.java
+++ b/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/TestBigtableBufferedMutator.java
@@ -42,7 +42,6 @@ import org.junit.runners.JUnit4;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
-import com.google.bigtable.v2.MutateRowRequest;
 import com.google.bigtable.v2.MutateRowResponse;
 import com.google.bigtable.v2.MutateRowsRequest;
 import com.google.bigtable.v2.ReadModifyWriteRowRequest;
@@ -112,25 +111,23 @@ public class TestBigtableBufferedMutator {
   }
 
   @Test
-  public void testPut() throws IOException, InterruptedException {
+  public void testPut() throws IOException{
     when(mockBulkMutation.add(any(MutateRowsRequest.Entry.class))).thenReturn(future);
     BigtableBufferedMutator underTest = createMutator(new Configuration(false));
     underTest.mutate(SIMPLE_PUT);
-    verify(mockAsyncExecutor, times(0)).mutateRowAsync(any(MutateRowRequest.class));
     verify(mockBulkMutation, times(1)).add(any(MutateRowsRequest.Entry.class));
   }
 
   @Test
-  public void testDelete() throws IOException, InterruptedException {
+  public void testDelete() throws IOException {
     when(mockBulkMutation.add(any(MutateRowsRequest.Entry.class))).thenReturn(future);
     BigtableBufferedMutator underTest = createMutator(new Configuration(false));
     underTest.mutate(new Delete(EMPTY_BYTES));
-    verify(mockAsyncExecutor, times(0)).mutateRowAsync(any(MutateRowRequest.class));
     verify(mockBulkMutation, times(1)).add(any(MutateRowsRequest.Entry.class));
   }
 
   @Test
-  public void testIncrement() throws IOException, InterruptedException {
+  public void testIncrement() throws IOException {
     when(mockAsyncExecutor.readModifyWriteRowAsync(any(ReadModifyWriteRowRequest.class)))
         .thenReturn(future);
     BigtableBufferedMutator underTest = createMutator(new Configuration(false));
@@ -140,7 +137,7 @@ public class TestBigtableBufferedMutator {
   }
 
   @Test
-  public void testAppend() throws IOException, InterruptedException {
+  public void testAppend() throws IOException {
     when(mockAsyncExecutor.readModifyWriteRowAsync(any(ReadModifyWriteRowRequest.class)))
         .thenReturn(future);
     BigtableBufferedMutator underTest = createMutator(new Configuration(false));
@@ -168,7 +165,6 @@ public class TestBigtableBufferedMutator {
     when(mockBulkMutation.add(any(MutateRowsRequest.Entry.class))).thenReturn(future);
     final BigtableBufferedMutator underTest = createMutator(config);
     underTest.mutate(SIMPLE_PUT);
-    verify(mockAsyncExecutor, times(0)).mutateRowAsync(any(MutateRowRequest.class));
     verify(mockBulkMutation, times(1)).add(any(MutateRowsRequest.Entry.class));
     underTest.flush();
     verify(mockBulkMutation, times(1)).flush();