|
17 | 17 |
|
18 | 18 | import static com.google.common.truth.Truth.assertThat; |
19 | 19 |
|
| 20 | +import com.google.api.core.ApiFuture; |
| 21 | +import com.google.api.core.ApiFutureCallback; |
| 22 | +import com.google.api.core.ApiFutures; |
20 | 23 | import com.google.api.core.SettableApiFuture; |
21 | 24 | import com.google.api.gax.rpc.ResponseObserver; |
22 | 25 | import com.google.api.gax.rpc.StreamController; |
|
27 | 30 | import com.google.cloud.bigtable.data.v2.models.RowMutation; |
28 | 31 | import com.google.common.collect.ImmutableList; |
29 | 32 | import com.google.common.collect.Lists; |
| 33 | +import com.google.common.util.concurrent.MoreExecutors; |
30 | 34 | import com.google.protobuf.ByteString; |
31 | 35 | import java.util.ArrayList; |
32 | 36 | import java.util.List; |
| 37 | +import java.util.concurrent.CountDownLatch; |
33 | 38 | import java.util.concurrent.ExecutionException; |
34 | 39 | import java.util.concurrent.TimeUnit; |
| 40 | +import java.util.concurrent.atomic.AtomicBoolean; |
35 | 41 | import org.junit.Before; |
36 | 42 | import org.junit.ClassRule; |
37 | 43 | import org.junit.Test; |
@@ -111,6 +117,31 @@ public void read() throws Throwable { |
111 | 117 | assertThat(observer.responses).containsExactlyElementsIn(expectedRows); |
112 | 118 | } |
113 | 119 |
|
| 120 | + @Test |
| 121 | + public void readSingleNonexistentAsyncCallback() throws Exception { |
| 122 | + ApiFuture<Row> future = testEnvRule.env().getDataClient() |
| 123 | + .readRowAsync(testEnvRule.env().getTableName().getTable(), "somenonexistentkey"); |
| 124 | + |
| 125 | + final AtomicBoolean found = new AtomicBoolean(); |
| 126 | + final CountDownLatch latch = new CountDownLatch(1); |
| 127 | + |
| 128 | + ApiFutures.addCallback(future, new ApiFutureCallback<Row>() { |
| 129 | + @Override |
| 130 | + public void onFailure(Throwable t) { |
| 131 | + latch.countDown(); |
| 132 | + } |
| 133 | + |
| 134 | + @Override |
| 135 | + public void onSuccess(Row result) { |
| 136 | + found.set(true); |
| 137 | + latch.countDown(); |
| 138 | + } |
| 139 | + }, MoreExecutors.directExecutor()); |
| 140 | + |
| 141 | + latch.await(1, TimeUnit.MINUTES); |
| 142 | + assertThat(found.get()).isTrue(); |
| 143 | + } |
| 144 | + |
114 | 145 | static class AccumulatingObserver implements ResponseObserver<Row> { |
115 | 146 | final List<Row> responses = Lists.newArrayList(); |
116 | 147 | final SettableApiFuture<Void> completionFuture = SettableApiFuture.create(); |
|
0 commit comments