Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.

Commit 85f1240

Browse files
committed
.
1 parent 3e86b96 commit 85f1240

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1beta2/StreamWriter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ private void setException(Throwable t) {
251251
* @return the message ID wrapped in a future.
252252
*/
253253
public ApiFuture<AppendRowsResponse> append(AppendRowsRequest message) {
254+
if (shutdown.get()) {
255+
throw new IllegalStateException("Cannot append to a shutdown writer");
256+
}
254257
appendAndRefreshAppendLock.lock();
255258
Preconditions.checkState(!shutdown.get(), "Cannot append on a shut-down writer.");
256259
Preconditions.checkNotNull(message, "Message is null.");

google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/StreamWriterTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,4 +1049,28 @@ public void testShutdownWithConnectionError() throws Exception {
10491049
assertEquals("Request aborted due to previous failures", e.getCause().getMessage());
10501050
}
10511051
}
1052+
1053+
@Test
1054+
public void testAppendAfterShutdown() throws Exception {
1055+
StreamWriter writer =
1056+
getTestStreamWriterBuilder()
1057+
.setBatchingSettings(
1058+
StreamWriter.Builder.DEFAULT_BATCHING_SETTINGS
1059+
.toBuilder()
1060+
.setElementCountThreshold(1L)
1061+
.build())
1062+
.build();
1063+
testBigQueryWrite.addResponse(
1064+
AppendRowsResponse.newBuilder()
1065+
.setAppendResult(
1066+
AppendRowsResponse.AppendResult.newBuilder().setOffset(Int64Value.of(1)).build())
1067+
.build());
1068+
writer.shutdown();
1069+
try {
1070+
ApiFuture<AppendRowsResponse> appendFuture1 = sendTestMessage(writer, new String[] {"A"});
1071+
fail("Should fail with exception");
1072+
} catch (IllegalStateException e) {
1073+
assertEquals("Cannot append to a shutdown writer", e.getMessage());
1074+
}
1075+
}
10521076
}

0 commit comments

Comments
 (0)