Skip to content

Commit 09b8d06

Browse files
committed
Polish
1 parent 97213e8 commit 09b8d06

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

modules/gcloud/src/test/java/org/testcontainers/containers/BigQueryEmulatorContainerTest.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,6 @@
3535

3636
class BigQueryEmulatorContainerTest {
3737

38-
private BigQuery getBigQuery(BigQueryEmulatorContainer container) {
39-
String url = container.getEmulatorHttpEndpoint();
40-
return BigQueryOptions
41-
.newBuilder()
42-
.setProjectId(container.getProjectId())
43-
.setHost(url)
44-
.setLocation(url)
45-
.setCredentials(NoCredentials.getInstance())
46-
.build().getService();
47-
}
48-
4938
@Test
5039
void testHttpEndpoint() throws Exception {
5140
try (
@@ -56,7 +45,15 @@ void testHttpEndpoint() throws Exception {
5645
container.start();
5746

5847
// bigQueryClient {
59-
BigQuery bigQuery = getBigQuery(container);
48+
String url = container.getEmulatorHttpEndpoint();
49+
BigQueryOptions options = BigQueryOptions
50+
.newBuilder()
51+
.setProjectId(container.getProjectId())
52+
.setHost(url)
53+
.setLocation(url)
54+
.setCredentials(NoCredentials.getInstance())
55+
.build();
56+
BigQuery bigQuery = options.getService();
6057
// }
6158

6259
String fn =
@@ -80,8 +77,6 @@ void testGrcpEndpoint() throws IOException {
8077
try (BigQueryEmulatorContainer container = new BigQueryEmulatorContainer("ghcr.io/goccy/bigquery-emulator:0.6.5")) {
8178
container.start();
8279

83-
// Test setup.
84-
// Create a table the "regular" way. We need this to verify we can connect a writestream
8580
BigQuery bigQuery = getBigQuery(container);
8681
String tableName = "test-table";
8782
String datasetName = "test-dataset";
@@ -98,8 +93,6 @@ void testGrcpEndpoint() throws IOException {
9893

9994
bigQuery.create(tableInfo);
10095

101-
// Actual test.
102-
// BigQueryWriteSettings requires a HTTP/2 connection, not provided by the originally exposed endpoint.
10396
BigQueryWriteSettings.Builder bigQueryWriteSettingsBuilder = BigQueryWriteSettings.newBuilder();
10497

10598
bigQueryWriteSettingsBuilder.createWriteStreamSettings()
@@ -109,7 +102,6 @@ void testGrcpEndpoint() throws IOException {
109102
.setTotalTimeout(Duration.ofSeconds(60))
110103
.build());
111104

112-
// Use the now exposed grpcPort to get a working connection.
113105
BigQueryWriteClient bigQueryWriteClient = BigQueryWriteClient.create(
114106
bigQueryWriteSettingsBuilder.setTransportChannelProvider(FixedTransportChannelProvider.create(GrpcTransportChannel.create(
115107
ManagedChannelBuilder.forAddress(container.getHost(), container.getEmulatorGrpcPort()).usePlaintext().build())))
@@ -123,12 +115,22 @@ void testGrcpEndpoint() throws IOException {
123115
.setWriteStream(WriteStream.newBuilder().setType(WriteStream.Type.PENDING))
124116
.build();
125117

126-
// Validate that we can successfully create a write stream. This would not work with http endpoint
127118
bigQueryWriteClient.createWriteStream(createWriteStreamRequest);
128119

129120
bigQueryWriteClient.shutdown();
130121
bigQueryWriteClient.close();
131122
}
132123
}
133124

125+
private BigQuery getBigQuery(BigQueryEmulatorContainer container) {
126+
String url = container.getEmulatorHttpEndpoint();
127+
return BigQueryOptions
128+
.newBuilder()
129+
.setProjectId(container.getProjectId())
130+
.setHost(url)
131+
.setLocation(url)
132+
.setCredentials(NoCredentials.getInstance())
133+
.build().getService();
134+
}
135+
134136
}

0 commit comments

Comments
 (0)