From 933f8b88ea65174e6192a5695b503e577a396c5a Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Mon, 29 Oct 2018 11:43:09 -0400 Subject: [PATCH] Bigtable: Add integration test to test nonexistent row handling --- .../cloud/bigtable/data/v2/it/ReadIT.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadIT.java b/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadIT.java index a4fab6e2ac08..3870bce43243 100644 --- a/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadIT.java +++ b/google-cloud-clients/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadIT.java @@ -17,6 +17,9 @@ import static com.google.common.truth.Truth.assertThat; +import com.google.api.core.ApiFuture; +import com.google.api.core.ApiFutureCallback; +import com.google.api.core.ApiFutures; import com.google.api.core.SettableApiFuture; import com.google.api.gax.rpc.ResponseObserver; import com.google.api.gax.rpc.StreamController; @@ -27,11 +30,14 @@ import com.google.cloud.bigtable.data.v2.models.RowMutation; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; +import com.google.common.util.concurrent.MoreExecutors; import com.google.protobuf.ByteString; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; @@ -111,6 +117,31 @@ public void read() throws Throwable { assertThat(observer.responses).containsExactlyElementsIn(expectedRows); } + @Test + public void readSingleNonexistentAsyncCallback() throws Exception { + ApiFuture future = testEnvRule.env().getDataClient() + .readRowAsync(testEnvRule.env().getTableName().getTable(), "somenonexistentkey"); + + final AtomicBoolean found = new AtomicBoolean(); + final CountDownLatch latch = new CountDownLatch(1); + + ApiFutures.addCallback(future, new ApiFutureCallback() { + @Override + public void onFailure(Throwable t) { + latch.countDown(); + } + + @Override + public void onSuccess(Row result) { + found.set(true); + latch.countDown(); + } + }, MoreExecutors.directExecutor()); + + latch.await(1, TimeUnit.MINUTES); + assertThat(found.get()).isTrue(); + } + static class AccumulatingObserver implements ResponseObserver { final List responses = Lists.newArrayList(); final SettableApiFuture completionFuture = SettableApiFuture.create();