use of com.google.cloud.bigquery.storage.v1beta1.Storage.Stream in project java-bigquerystorage by googleapis.
the class ITBigQueryStorageLongRunningTest method testLongRunningReadSession.
@Test
public void testLongRunningReadSession() throws InterruptedException, ExecutionException {
// This test reads a larger table with the goal of doing a simple validation of timeout settings
// for a longer running session.
TableReference tableReference = TableReference.newBuilder().setProjectId("bigquery-public-data").setDatasetId("samples").setTableId("wikipedia").build();
ReadSession session = client.createReadSession(/* tableReference = */
tableReference, /* parent = */
parentProjectId, /* requestedStreams = */
5);
assertEquals(String.format("Did not receive expected number of streams for table reference '%s' CreateReadSession response:%n%s", TextFormat.shortDebugString(tableReference), session.toString()), 5, session.getStreamsCount());
List<Callable<Long>> tasks = new ArrayList<>(session.getStreamsCount());
for (final Stream stream : session.getStreamsList()) {
tasks.add(new Callable<Long>() {
@Override
public Long call() throws Exception {
return readAllRowsFromStream(stream);
}
});
}
ExecutorService executor = Executors.newFixedThreadPool(tasks.size());
List<Future<Long>> results = executor.invokeAll(tasks);
long rowCount = 0;
for (Future<Long> result : results) {
rowCount += result.get();
}
assertEquals(313_797_035, rowCount);
}
use of com.google.cloud.bigquery.storage.v1beta1.Storage.Stream in project java-bigquerystorage by googleapis.
the class BigQueryStorageClientTest method finalizeStreamExceptionTest.
@Test
@SuppressWarnings("all")
public void finalizeStreamExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockBigQueryStorage.addException(exception);
try {
Stream stream = Stream.newBuilder().build();
client.finalizeStream(stream);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
}
}
use of com.google.cloud.bigquery.storage.v1beta1.Storage.Stream in project java-bigquerystorage by googleapis.
the class ReadRowsRetryTest method multipleRetryTestWithNonZeroInitialOffset.
@Test
public void multipleRetryTestWithNonZeroInitialOffset() {
ReadRowsRequest request = RpcExpectation.createRequest("fake-stream", 17);
service.expectations.add(RpcExpectation.create().expectRequest("fake-stream", 17).respondWithNumberOfRows(5).respondWithStatus(Code.UNAVAILABLE));
service.expectations.add(RpcExpectation.create().expectRequest("fake-stream", 22).respondWithNumberOfRows(10).respondWithNumberOfRows(7).respondWithStatus(Code.UNAVAILABLE));
service.expectations.add(RpcExpectation.create().expectRequest("fake-stream", 39).respondWithNumberOfRows(3));
Assert.assertEquals(25, getRowCount(request));
}
use of com.google.cloud.bigquery.storage.v1beta1.Storage.Stream in project java-bigquerystorage by googleapis.
the class ReadRowsRetryTest method multipleRetryTestWithZeroInitialOffset.
@Test
public void multipleRetryTestWithZeroInitialOffset() {
ReadRowsRequest request = RpcExpectation.createRequest("fake-stream", 0);
service.expectations.add(RpcExpectation.create().expectRequest("fake-stream", 0).respondWithNumberOfRows(5).respondWithStatus(Code.UNAVAILABLE));
service.expectations.add(RpcExpectation.create().expectRequest("fake-stream", 5).respondWithNumberOfRows(10).respondWithNumberOfRows(7).respondWithStatus(Code.UNAVAILABLE));
service.expectations.add(RpcExpectation.create().expectRequest("fake-stream", 22).respondWithNumberOfRows(6));
Assert.assertEquals(28, getRowCount(request));
}
use of com.google.cloud.bigquery.storage.v1beta1.Storage.Stream in project java-bigquerystorage by googleapis.
the class BigQueryStorageClient method finalizeStream.
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Triggers the graceful termination of a single stream in a ReadSession. This API can be used to
* dynamically adjust the parallelism of a batch processing task downwards without losing data.
*
* <p>This API does not delete the stream -- it remains visible in the ReadSession, and any data
* processed by the stream is not released to other streams. However, no additional data will be
* assigned to the stream once this call completes. Callers must continue reading data on the
* stream until the end of the stream is reached so that data which has already been assigned to
* the stream will be processed.
*
* <p>This method will return an error if there are no other live streams in the Session, or if
* SplitReadStream() has been called on the given Stream.
*
* <p>Sample code:
*
* <pre><code>
* try (BigQueryStorageClient bigQueryStorageClient = BigQueryStorageClient.create()) {
* Stream stream = Stream.newBuilder().build();
* bigQueryStorageClient.finalizeStream(stream);
* }
* </code></pre>
*
* @param stream Stream to finalize.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final void finalizeStream(Stream stream) {
FinalizeStreamRequest request = FinalizeStreamRequest.newBuilder().setStream(stream).build();
finalizeStream(request);
}
Aggregations