Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
yirutang committed Feb 17, 2021
1 parent 3e86b96 commit 85f1240
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ private void setException(Throwable t) {
* @return the message ID wrapped in a future.
*/
public ApiFuture<AppendRowsResponse> append(AppendRowsRequest message) {
if (shutdown.get()) {
throw new IllegalStateException("Cannot append to a shutdown writer");
}
appendAndRefreshAppendLock.lock();
Preconditions.checkState(!shutdown.get(), "Cannot append on a shut-down writer.");
Preconditions.checkNotNull(message, "Message is null.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1049,4 +1049,28 @@ public void testShutdownWithConnectionError() throws Exception {
assertEquals("Request aborted due to previous failures", e.getCause().getMessage());
}
}

@Test
public void testAppendAfterShutdown() throws Exception {
StreamWriter writer =
getTestStreamWriterBuilder()
.setBatchingSettings(
StreamWriter.Builder.DEFAULT_BATCHING_SETTINGS
.toBuilder()
.setElementCountThreshold(1L)
.build())
.build();
testBigQueryWrite.addResponse(
AppendRowsResponse.newBuilder()
.setAppendResult(
AppendRowsResponse.AppendResult.newBuilder().setOffset(Int64Value.of(1)).build())
.build());
writer.shutdown();
try {
ApiFuture<AppendRowsResponse> appendFuture1 = sendTestMessage(writer, new String[] {"A"});
fail("Should fail with exception");
} catch (IllegalStateException e) {
assertEquals("Cannot append to a shutdown writer", e.getMessage());
}
}
}

0 comments on commit 85f1240

Please sign in to comment.