Skip to content

Commit f77465e

Browse files
authored
fix: an atempt to solve test failure in nightly build (#2330)
1 parent ba134e4 commit f77465e

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -371,22 +371,24 @@ static BigQueryWriteSettings getBigQueryWriteSettings(Builder builder) throws IO
371371

372372
// Validate whether the fetched connection pool matched certain properties.
373373
private void validateFetchedConnectonPool(StreamWriter.Builder builder) {
374-
String paramsValidatedFailed = "";
375-
if (!Objects.equals(
376-
this.singleConnectionOrConnectionPool.connectionWorkerPool().getTraceId(),
377-
builder.traceId)) {
378-
paramsValidatedFailed = "Trace id";
379-
} else if (!Objects.equals(
380-
this.singleConnectionOrConnectionPool.connectionWorkerPool().limitExceededBehavior(),
381-
builder.limitExceededBehavior)) {
382-
paramsValidatedFailed = "Limit Exceeds Behavior";
383-
}
384-
385-
if (!paramsValidatedFailed.isEmpty()) {
374+
String storedTraceId =
375+
this.singleConnectionOrConnectionPool.connectionWorkerPool().getTraceId();
376+
if (!Objects.equals(storedTraceId, builder.traceId)) {
386377
throw new IllegalArgumentException(
387378
String.format(
388-
"%s used for the same connection pool for the same location must be the same!",
389-
paramsValidatedFailed));
379+
"Trace id used for the same connection pool for the same location must be the same, "
380+
+ "however stored trace id is %s, and expected trace id is %s.",
381+
storedTraceId, builder.traceId));
382+
}
383+
FlowController.LimitExceededBehavior storedLimitExceededBehavior =
384+
singleConnectionOrConnectionPool.connectionWorkerPool().limitExceededBehavior();
385+
if (!Objects.equals(storedLimitExceededBehavior, builder.limitExceededBehavior)) {
386+
throw new IllegalArgumentException(
387+
String.format(
388+
"Limit exceeded behavior setting used for the same connection pool for the same "
389+
+ "location must be the same, however stored value is %s, and expected "
390+
+ "value is %s.",
391+
storedLimitExceededBehavior, builder.limitExceededBehavior));
390392
}
391393
}
392394

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public class ITBigQueryWriteManualClientTest {
7373
private static final String TABLE = "testtable";
7474
private static final String TABLE2 = "complicatedtable";
7575

76+
private static final String TEST_TRACE_ID = "DATAFLOW:job_id";
77+
7678
private static final String DESCRIPTION = "BigQuery Write Java manual client test dataset";
7779

7880
private static BigQueryWriteClient client;
@@ -928,6 +930,7 @@ public void testStreamWriterWithDefaultValue() throws ExecutionException, Interr
928930
ProtoSchemaConverter.convert(SimpleTypeForDefaultValue.getDescriptor()))
929931
.setDefaultMissingValueInterpretation(MissingValueInterpretation.DEFAULT_VALUE)
930932
.setEnableConnectionPool(true)
933+
.setTraceId(TEST_TRACE_ID)
931934
.build()) {
932935
// 1. row has both fields set.
933936
SimpleTypeForDefaultValue simpleTypeForDefaultValue1 =
@@ -1534,16 +1537,19 @@ public void testMultiplexingMixedLocation()
15341537
StreamWriter.newBuilder(defaultStream1)
15351538
.setWriterSchema(ProtoSchemaConverter.convert(FooType.getDescriptor()))
15361539
.setEnableConnectionPool(true)
1540+
.setTraceId(TEST_TRACE_ID)
15371541
.build();
15381542
StreamWriter streamWriter2 =
15391543
StreamWriter.newBuilder(defaultStream2)
15401544
.setWriterSchema(ProtoSchemaConverter.convert(ComplicateType.getDescriptor()))
15411545
.setEnableConnectionPool(true)
1546+
.setTraceId(TEST_TRACE_ID)
15421547
.build();
15431548
StreamWriter streamWriter3 =
15441549
StreamWriter.newBuilder(defaultStream3)
15451550
.setWriterSchema(ProtoSchemaConverter.convert(FooType.getDescriptor()))
15461551
.setEnableConnectionPool(true)
1552+
.setTraceId(TEST_TRACE_ID)
15471553
.build();
15481554
ApiFuture<AppendRowsResponse> response1 =
15491555
streamWriter1.append(CreateProtoRows(new String[] {"aaa"}));
@@ -1557,6 +1563,9 @@ public void testMultiplexingMixedLocation()
15571563
assertEquals("us", streamWriter1.getLocation());
15581564
assertEquals("us", streamWriter2.getLocation());
15591565
assertEquals("eu", streamWriter3.getLocation());
1566+
streamWriter1.close();
1567+
streamWriter2.close();
1568+
streamWriter3.close();
15601569
}
15611570

15621571
@Test

0 commit comments

Comments
 (0)