From dc07ed84778028f149cab3883af9bb9a7929efd1 Mon Sep 17 00:00:00 2001 From: Yiru Tang Date: Tue, 7 Feb 2023 22:52:01 +0000 Subject: [PATCH] feat: Add isDone to JsonWriter to indicate a JsonWriter is no longer usable and needs to be recreated. (#1978) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * . * . * 🦉 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 --- .../cloud/bigquery/storage/v1/JsonStreamWriter.java | 9 +++++++++ .../cloud/bigquery/storage/v1/JsonStreamWriterTest.java | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java index d2c58e372b..5cf3cec250 100644 --- a/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java +++ b/google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriter.java @@ -382,6 +382,15 @@ public void close() { this.streamWriter.close(); } + /** + * @return if a Json writer can no longer be used for writing. It is due to either the + * JsonStreamWriter is explicitly closed or the underlying connection is broken when + * connection pool is not used. Client should recreate JsonStreamWriter in this case. + */ + public boolean isDone() { + return this.streamWriter.isDone(); + } + public static final class Builder { private String streamName; private BigQueryWriteClient client; diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriterTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriterTest.java index 8c34ad9b3c..1cb8000858 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriterTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/JsonStreamWriterTest.java @@ -1139,6 +1139,14 @@ public void testWriterId() Assert.assertNotEquals(writer1.getWriterId(), writer2.getWriterId()); } + @Test + public void testIsDone() throws DescriptorValidationException, IOException, InterruptedException { + JsonStreamWriter writer1 = getTestJsonStreamWriterBuilder(TEST_STREAM, TABLE_SCHEMA).build(); + Assert.assertFalse(writer1.isDone()); + writer1.close(); + Assert.assertTrue(writer1.isDone()); + } + private AppendRowsResponse createAppendResponse(long offset) { return AppendRowsResponse.newBuilder() .setAppendResult(