Skip to content

Commit

Permalink
feat: Add isDone to JsonWriter to indicate a JsonWriter is no longer …
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
yirutang and gcf-owl-bot[bot] committed Feb 7, 2023
1 parent 48abc75 commit dc07ed8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Expand Up @@ -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;
Expand Down
Expand Up @@ -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(
Expand Down

0 comments on commit dc07ed8

Please sign in to comment.