Skip to content

Commit dc07ed8

Browse files
feat: Add isDone to JsonWriter to indicate a JsonWriter is no longer usable and needs to be recreated. (#1978)
* . * . * 🦉 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 48abc75 commit dc07ed8

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,15 @@ public void close() {
382382
this.streamWriter.close();
383383
}
384384

385+
/**
386+
* @return if a Json writer can no longer be used for writing. It is due to either the
387+
* JsonStreamWriter is explicitly closed or the underlying connection is broken when
388+
* connection pool is not used. Client should recreate JsonStreamWriter in this case.
389+
*/
390+
public boolean isDone() {
391+
return this.streamWriter.isDone();
392+
}
393+
385394
public static final class Builder {
386395
private String streamName;
387396
private BigQueryWriteClient client;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,14 @@ public void testWriterId()
11391139
Assert.assertNotEquals(writer1.getWriterId(), writer2.getWriterId());
11401140
}
11411141

1142+
@Test
1143+
public void testIsDone() throws DescriptorValidationException, IOException, InterruptedException {
1144+
JsonStreamWriter writer1 = getTestJsonStreamWriterBuilder(TEST_STREAM, TABLE_SCHEMA).build();
1145+
Assert.assertFalse(writer1.isDone());
1146+
writer1.close();
1147+
Assert.assertTrue(writer1.isDone());
1148+
}
1149+
11421150
private AppendRowsResponse createAppendResponse(long offset) {
11431151
return AppendRowsResponse.newBuilder()
11441152
.setAppendResult(

0 commit comments

Comments
 (0)