Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Return explicit StreamWriterClosedException #1709

Merged
merged 3 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ If you are using Maven without BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies

```Groovy
implementation platform('com.google.cloud:libraries-bom:25.4.0')
implementation platform('com.google.cloud:libraries-bom:26.0.0')

implementation 'com.google.cloud:google-cloud-bigquerystorage'
```
If you are using Gradle without BOM, add this to your dependencies

```Groovy
implementation 'com.google.cloud:google-cloud-bigquerystorage:2.14.2'
implementation 'com.google.cloud:google-cloud-bigquerystorage:2.16.1'
```

If you are using SBT, add this to your dependencies

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-bigquerystorage" % "2.14.2"
libraryDependencies += "com.google.cloud" % "google-cloud-bigquerystorage" % "2.16.1"
```

## Authentication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,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"));
}
}