Search in sources :

Example 1 with ServerStreamingStashCallable

use of com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable in project java-bigtable by googleapis.

the class ReadRowsMergingAcceptanceTest method test.

@Test
public void test() throws Exception {
    List<ReadRowsResponse> responses = Lists.newArrayList();
    // Convert the chunks into a single ReadRowsResponse
    for (CellChunk chunk : testCase.getChunksList()) {
        ReadRowsResponse.Builder responseBuilder = ReadRowsResponse.newBuilder();
        responseBuilder.addChunks(chunk);
        responses.add(responseBuilder.build());
    }
    // Wrap the responses in a callable
    ServerStreamingCallable<ReadRowsRequest, ReadRowsResponse> source = new ServerStreamingStashCallable<>(responses);
    RowMergingCallable<Row> mergingCallable = new RowMergingCallable<>(source, new DefaultRowAdapter());
    // Invoke the callable to get the merged rows
    ServerStream<Row> stream = mergingCallable.call(ReadRowsRequest.getDefaultInstance());
    // Read all of the rows and transform them into logical cells
    List<ReadRowsTest.Result> actualResults = Lists.newArrayList();
    Exception error = null;
    try {
        for (Row row : stream) {
            for (RowCell cell : row.getCells()) {
                actualResults.add(ReadRowsTest.Result.newBuilder().setRowKeyBytes(row.getKey()).setFamilyName(cell.getFamily()).setQualifierBytes(cell.getQualifier()).setTimestampMicros(cell.getTimestamp()).setValueBytes(cell.getValue()).setLabel(cell.getLabels().isEmpty() ? "" : cell.getLabels().get(0)).build());
            }
        }
    } catch (Exception e) {
        error = e;
    }
    // Verify the results
    if (expectsError(testCase)) {
        assertThat(error).isNotNull();
    } else {
        if (error != null) {
            throw error;
        }
    }
    assertThat(getNonExceptionResults(testCase)).isEqualTo(actualResults);
}
Also used : CellChunk(com.google.bigtable.v2.ReadRowsResponse.CellChunk) ServerStreamingStashCallable(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable) RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) IOException(java.io.IOException) DefaultRowAdapter(com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter) ReadRowsResponse(com.google.bigtable.v2.ReadRowsResponse) Row(com.google.cloud.bigtable.data.v2.models.Row) ReadRowsTest(com.google.cloud.conformance.bigtable.v2.TestDefinition.ReadRowsTest) Test(org.junit.Test)

Example 2 with ServerStreamingStashCallable

use of com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable in project java-bigtable by googleapis.

the class RowMergingCallableTest method scanMarker.

@Test
public void scanMarker() {
    FakeStreamingApi.ServerStreamingStashCallable<ReadRowsRequest, ReadRowsResponse> inner = new ServerStreamingStashCallable<>(Lists.newArrayList(// send a scan marker
    ReadRowsResponse.newBuilder().setLastScannedRowKey(ByteString.copyFromUtf8("key1")).build()));
    RowMergingCallable<Row> rowMergingCallable = new RowMergingCallable<>(inner, new DefaultRowAdapter());
    List<Row> results = rowMergingCallable.all().call(ReadRowsRequest.getDefaultInstance());
    Truth.assertThat(results).containsExactly(Row.create(ByteString.copyFromUtf8("key1"), Lists.<RowCell>newArrayList()));
}
Also used : FakeStreamingApi(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi) ReadRowsResponse(com.google.bigtable.v2.ReadRowsResponse) ServerStreamingStashCallable(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable) RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Row(com.google.cloud.bigtable.data.v2.models.Row) DefaultRowAdapter(com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter) Test(org.junit.Test)

Example 3 with ServerStreamingStashCallable

use of com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable in project java-bigtable by googleapis.

the class RowMergingCallableTest method invalidMarkerInCell.

@Test
public void invalidMarkerInCell() {
    FakeStreamingApi.ServerStreamingStashCallable<ReadRowsRequest, ReadRowsResponse> inner = new ServerStreamingStashCallable<>(Lists.newArrayList(ReadRowsResponse.newBuilder().addChunks(CellChunk.newBuilder().setRowKey(ByteString.copyFromUtf8("key1")).setFamilyName(StringValue.newBuilder().setValue("family")).setQualifier(BytesValue.newBuilder().setValue(ByteString.EMPTY)).setTimestampMicros(1_000).setValue(ByteString.copyFromUtf8("a")).setValueSize(2)).build(), // send a scan marker
    ReadRowsResponse.newBuilder().setLastScannedRowKey(ByteString.copyFromUtf8("key1")).build(), // finish the cell & row
    ReadRowsResponse.newBuilder().addChunks(CellChunk.newBuilder().setValue(ByteString.copyFromUtf8("b")).setValueSize(0).setCommitRow(true)).build()));
    RowMergingCallable<Row> rowMergingCallable = new RowMergingCallable<>(inner, new DefaultRowAdapter());
    Throwable actualError = null;
    try {
        rowMergingCallable.all().call(ReadRowsRequest.getDefaultInstance());
    } catch (Throwable t) {
        actualError = t;
    }
    Truth.assertThat(actualError).isInstanceOf(IllegalStateException.class);
}
Also used : FakeStreamingApi(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi) ReadRowsResponse(com.google.bigtable.v2.ReadRowsResponse) ServerStreamingStashCallable(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Row(com.google.cloud.bigtable.data.v2.models.Row) DefaultRowAdapter(com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter) Test(org.junit.Test)

Example 4 with ServerStreamingStashCallable

use of com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable in project java-bigtable by googleapis.

the class ReframingResponseObserverTest method testReframerPopError.

@Test
public void testReframerPopError() {
    final AtomicInteger popCount = new AtomicInteger();
    MockResponseObserver<String> outerObserver = new MockResponseObserver<>(true);
    Reframer<String, String> reframer = new DasherizingReframer(1) {

        @Override
        public String pop() {
            if (popCount.incrementAndGet() == 2) {
                throw new IllegalStateException("fake error");
            }
            return super.pop();
        }
    };
    ReframingResponseObserver<String, String> middleware = new ReframingResponseObserver<>(outerObserver, reframer);
    ServerStreamingStashCallable<String, String> innerCallable = new ServerStreamingStashCallable<>(ImmutableList.of("a", "boom", "c"));
    innerCallable.call("request", middleware);
    StreamControllerStash<String> lastCall = innerCallable.popLastCall();
    Truth.assertThat(outerObserver.getFinalError()).isInstanceOf(IllegalStateException.class);
    Truth.assertThat(outerObserver.getFinalError()).hasMessageThat().isEqualTo("fake error");
    Truth.assertThat(outerObserver.popNextResponse()).isEqualTo("a");
    Truth.assertThat(outerObserver.popNextResponse()).isNull();
    Truth.assertThat(popCount.get()).isEqualTo(2);
    Truth.assertThat(lastCall.getError()).isInstanceOf(CancellationException.class);
    Truth.assertThat(lastCall.getNumDelivered()).isEqualTo(2);
}
Also used : MockResponseObserver(com.google.cloud.bigtable.gaxx.testing.MockStreamingApi.MockResponseObserver) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerStreamingStashCallable(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable) Test(org.junit.Test)

Example 5 with ServerStreamingStashCallable

use of com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable in project java-bigtable by googleapis.

the class ReadRowsUserCallableTest method testRequestConverted.

@Test
public void testRequestConverted() {
    ServerStreamingStashCallable<ReadRowsRequest, Row> innerCallable = new ServerStreamingStashCallable<>();
    ReadRowsUserCallable<Row> callable = new ReadRowsUserCallable<>(innerCallable, REQUEST_CONTEXT);
    Query query = Query.create("fake-table");
    callable.call(query);
    Truth.assertThat(innerCallable.getActualRequest()).isEqualTo(query.toProto(REQUEST_CONTEXT));
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) ServerStreamingStashCallable(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Row(com.google.cloud.bigtable.data.v2.models.Row) Test(org.junit.Test)

Aggregations

ServerStreamingStashCallable (com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable)8 Test (org.junit.Test)8 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)7 Row (com.google.cloud.bigtable.data.v2.models.Row)7 ReadRowsResponse (com.google.bigtable.v2.ReadRowsResponse)3 DefaultRowAdapter (com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter)3 Query (com.google.cloud.bigtable.data.v2.models.Query)2 RowCell (com.google.cloud.bigtable.data.v2.models.RowCell)2 FakeStreamingApi (com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi)2 CellChunk (com.google.bigtable.v2.ReadRowsResponse.CellChunk)1 MockResponseObserver (com.google.cloud.bigtable.gaxx.testing.MockStreamingApi.MockResponseObserver)1 ReadRowsTest (com.google.cloud.conformance.bigtable.v2.TestDefinition.ReadRowsTest)1 IOException (java.io.IOException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1