Skip to content

Commit

Permalink
feat: Return explicit StreamWriterClosedException (#1709)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
yirutang and gcf-owl-bot[bot] authored Jul 25, 2022
1 parent e92a8c0 commit 57eb6d0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ protected StreamFinalizedException(Status grpcStatus, String name) {
}
}

public static final class StreamWriterClosedException extends StorageException {
protected StreamWriterClosedException(Status grpcStatus, String name) {
super(grpcStatus, name, null, null, ImmutableMap.of());
}
}

/**
* There was a schema mismatch due to bigquery table with fewer fields than the input message.
* This can be resolved by updating the table's schema with the message schema.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,10 @@ private ApiFuture<AppendRowsResponse> appendInternal(AppendRowsRequest message)
try {
if (userClosed) {
requestWrapper.appendResult.setException(
new StatusRuntimeException(
new Exceptions.StreamWriterClosedException(
Status.fromCode(Status.Code.FAILED_PRECONDITION)
.withDescription("Connection is already closed")));
.withDescription("Connection is already closed"),
streamName));
return requestWrapper.appendResult;
}
// Check if queue is going to be full before adding the request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,4 +653,16 @@ public void testWriterClosedStream() throws Exception {
TimeUnit.SECONDS.sleep(1);
}
}

@Test
public void testWriterException() throws Exception {
StreamWriter writer = getTestStreamWriter();
writer.close();
ApiFuture<AppendRowsResponse> appendFuture1 = sendTestMessage(writer, new String[] {"A"}, 0);
Exceptions.StreamWriterClosedException actualError =
assertFutureException(Exceptions.StreamWriterClosedException.class, appendFuture1);
// The basic StatusRuntimeException API is not changed.
assertEquals(Status.Code.FAILED_PRECONDITION, actualError.getStatus().getCode());
assertTrue(actualError.getStatus().getDescription().contains("Connection is already closed"));
}
}

0 comments on commit 57eb6d0

Please sign in to comment.