Skip to content

Commit 57eb6d0

Browse files
feat: Return explicit StreamWriterClosedException (#1709)
* feat: Return explicit StreamWriterClosedException * fix format * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent e92a8c0 commit 57eb6d0

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/Exceptions.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ protected StreamFinalizedException(Status grpcStatus, String name) {
8383
}
8484
}
8585

86+
public static final class StreamWriterClosedException extends StorageException {
87+
protected StreamWriterClosedException(Status grpcStatus, String name) {
88+
super(grpcStatus, name, null, null, ImmutableMap.of());
89+
}
90+
}
91+
8692
/**
8793
* There was a schema mismatch due to bigquery table with fewer fields than the input message.
8894
* This can be resolved by updating the table's schema with the message schema.

google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/StreamWriter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,10 @@ private ApiFuture<AppendRowsResponse> appendInternal(AppendRowsRequest message)
309309
try {
310310
if (userClosed) {
311311
requestWrapper.appendResult.setException(
312-
new StatusRuntimeException(
312+
new Exceptions.StreamWriterClosedException(
313313
Status.fromCode(Status.Code.FAILED_PRECONDITION)
314-
.withDescription("Connection is already closed")));
314+
.withDescription("Connection is already closed"),
315+
streamName));
315316
return requestWrapper.appendResult;
316317
}
317318
// Check if queue is going to be full before adding the request.

google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/StreamWriterTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,4 +653,16 @@ public void testWriterClosedStream() throws Exception {
653653
TimeUnit.SECONDS.sleep(1);
654654
}
655655
}
656+
657+
@Test
658+
public void testWriterException() throws Exception {
659+
StreamWriter writer = getTestStreamWriter();
660+
writer.close();
661+
ApiFuture<AppendRowsResponse> appendFuture1 = sendTestMessage(writer, new String[] {"A"}, 0);
662+
Exceptions.StreamWriterClosedException actualError =
663+
assertFutureException(Exceptions.StreamWriterClosedException.class, appendFuture1);
664+
// The basic StatusRuntimeException API is not changed.
665+
assertEquals(Status.Code.FAILED_PRECONDITION, actualError.getStatus().getCode());
666+
assertTrue(actualError.getStatus().getDescription().contains("Connection is already closed"));
667+
}
656668
}

0 commit comments

Comments
 (0)