Skip to content

Commit c472df0

Browse files
committed
Merge branch 'main' into PR #3083 to update
2 parents 431d36c + c478747 commit c472df0

File tree

7 files changed

+182
-186
lines changed

7 files changed

+182
-186
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class BigQueryResource {
2828
* @param tableId
2929
* @return a path to a table resource.
3030
*/
31-
public static String FormatTableResource(String projectId, String datasetId, String tableId) {
31+
public static String formatTableResource(String projectId, String datasetId, String tableId) {
3232
return String.format("projects/%s/datasets/%s/tables/%s", projectId, datasetId, tableId);
3333
}
3434
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void testLongRunningReadSession() throws InterruptedException, ExecutionE
8888
// for a longer running session.
8989

9090
String table =
91-
BigQueryResource.FormatTableResource(
91+
BigQueryResource.formatTableResource(
9292
/* projectId= */ "bigquery-public-data",
9393
/* datasetId= */ "samples",
9494
/* tableId= */ "wikipedia");
@@ -123,6 +123,7 @@ public Long call() throws Exception {
123123

124124
ExecutorService executor = Executors.newFixedThreadPool(tasks.size());
125125
List<Future<Long>> results = executor.invokeAll(tasks);
126+
executor.shutdown();
126127

127128
long rowCount = 0;
128129
for (Future<Long> result : results) {

google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryStorageTest.java renamed to google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryStorageReadClientTest.java

Lines changed: 45 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
import java.util.Collection;
102102
import java.util.Collections;
103103
import java.util.HashMap;
104-
import java.util.Iterator;
105104
import java.util.List;
106105
import java.util.Map;
107106
import java.util.concurrent.TimeUnit;
@@ -119,8 +118,9 @@
119118
import org.junit.Test;
120119

121120
/** Integration tests for BigQuery Storage API. */
122-
public class ITBigQueryStorageTest {
123-
private static final Logger LOG = Logger.getLogger(ITBigQueryStorageTest.class.getName());
121+
public class ITBigQueryStorageReadClientTest {
122+
private static final Logger LOG =
123+
Logger.getLogger(ITBigQueryStorageReadClientTest.class.getName());
124124
private static final String DATASET = RemoteBigQueryHelper.generateDatasetName();
125125
private static final String DESCRIPTION = "BigQuery Storage Java client test dataset";
126126

@@ -504,7 +504,7 @@ public static void beforeClass() throws IOException {
504504
LOG.info(
505505
String.format(
506506
"%s tests running with parent project: %s",
507-
ITBigQueryStorageTest.class.getSimpleName(), parentProjectId));
507+
ITBigQueryStorageReadClientTest.class.getSimpleName(), parentProjectId));
508508

509509
RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create();
510510
bigquery = bigqueryHelper.getOptions().getService();
@@ -532,7 +532,7 @@ public static void afterClass() throws InterruptedException {
532532
@Test
533533
public void testSimpleReadAvro() {
534534
String table =
535-
BigQueryResource.FormatTableResource(
535+
BigQueryResource.formatTableResource(
536536
/* projectId= */ "bigquery-public-data",
537537
/* datasetId= */ "samples",
538538
/* tableId= */ "shakespeare");
@@ -568,7 +568,7 @@ public void testSimpleReadAvro() {
568568
@Test
569569
public void testSimpleReadArrow() {
570570
String table =
571-
BigQueryResource.FormatTableResource(
571+
BigQueryResource.formatTableResource(
572572
/* projectId= */ "bigquery-public-data",
573573
/* datasetId= */ "samples",
574574
/* tableId= */ "shakespeare");
@@ -632,7 +632,7 @@ public void testRangeTypeSimple() throws InterruptedException {
632632
bigquery.query(createTable);
633633

634634
String table =
635-
BigQueryResource.FormatTableResource(
635+
BigQueryResource.formatTableResource(
636636
/* projectId= */ ServiceOptions.getDefaultProjectId(),
637637
/* datasetId= */ DATASET,
638638
/* tableId= */ tableId.getTable());
@@ -741,7 +741,7 @@ public void testRangeTypeWrite()
741741
}
742742

743743
String table =
744-
BigQueryResource.FormatTableResource(
744+
BigQueryResource.formatTableResource(
745745
/* projectId= */ projectName,
746746
/* datasetId= */ DATASET,
747747
/* tableId= */ tableId.getTable());
@@ -802,7 +802,7 @@ public void testRangeTypeWrite()
802802
@Test
803803
public void testSimpleReadAndResume() {
804804
String table =
805-
BigQueryResource.FormatTableResource(
805+
BigQueryResource.formatTableResource(
806806
/* projectId= */ "bigquery-public-data",
807807
/* datasetId= */ "samples",
808808
/* tableId= */ "shakespeare");
@@ -847,7 +847,7 @@ public void testSimpleReadAndResume() {
847847
@Test
848848
public void testFilter() throws IOException {
849849
String table =
850-
BigQueryResource.FormatTableResource(
850+
BigQueryResource.formatTableResource(
851851
/* projectId= */ "bigquery-public-data",
852852
/* datasetId= */ "samples",
853853
/* tableId= */ "shakespeare");
@@ -889,15 +889,13 @@ public void testFilter() throws IOException {
889889
rowCount += response.getRowCount();
890890
reader.processRows(
891891
response.getAvroRows(),
892-
new AvroRowConsumer() {
893-
@Override
894-
public void accept(GenericData.Record record) {
895-
Long wordCount = (Long) record.get("word_count");
896-
assertWithMessage("Row not matching expectations: %s", record.toString())
897-
.that(wordCount)
898-
.isGreaterThan(100L);
899-
}
900-
});
892+
(AvroRowConsumer)
893+
record -> {
894+
Long wordCount = (Long) record.get("word_count");
895+
assertWithMessage("Row not matching expectations: %s", record.toString())
896+
.that(wordCount)
897+
.isGreaterThan(100L);
898+
});
901899
}
902900

903901
assertEquals(1_333, rowCount);
@@ -906,7 +904,7 @@ public void accept(GenericData.Record record) {
906904
@Test
907905
public void testColumnSelection() throws IOException {
908906
String table =
909-
BigQueryResource.FormatTableResource(
907+
BigQueryResource.formatTableResource(
910908
/* projectId= */ "bigquery-public-data",
911909
/* datasetId= */ "samples",
912910
/* tableId= */ "shakespeare");
@@ -966,19 +964,17 @@ public void testColumnSelection() throws IOException {
966964
rowCount += response.getRowCount();
967965
reader.processRows(
968966
response.getAvroRows(),
969-
new AvroRowConsumer() {
970-
@Override
971-
public void accept(GenericData.Record record) {
972-
String rowAssertMessage =
973-
String.format("Row not matching expectations: %s", record.toString());
974-
975-
Long wordCount = (Long) record.get("word_count");
976-
assertWithMessage(rowAssertMessage).that(wordCount).isGreaterThan(100L);
977-
978-
Utf8 word = (Utf8) record.get("word");
979-
assertWithMessage(rowAssertMessage).that(word.length()).isGreaterThan(0);
980-
}
981-
});
967+
(AvroRowConsumer)
968+
record -> {
969+
String rowAssertMessage =
970+
String.format("Row not matching expectations: %s", record.toString());
971+
972+
Long wordCount = (Long) record.get("word_count");
973+
assertWithMessage(rowAssertMessage).that(wordCount).isGreaterThan(100L);
974+
975+
Utf8 word = (Utf8) record.get("word");
976+
assertWithMessage(rowAssertMessage).that(word.length()).isGreaterThan(0);
977+
});
982978
}
983979

984980
assertEquals(1_333, rowCount);
@@ -997,8 +993,6 @@ public void testReadAtSnapshot() throws InterruptedException, IOException {
997993
TableId testTableId = TableId.of(/* dataset= */ DATASET, /* table= */ "test_read_snapshot");
998994
bigquery.create(TableInfo.of(testTableId, StandardTableDefinition.of(tableSchema)));
999995

1000-
testTableId.toString();
1001-
1002996
Job firstJob =
1003997
RunQueryAppendJobAndExpectSuccess(
1004998
/* destinationTableId= */ testTableId, /* query= */ "SELECT 1 AS col");
@@ -1008,7 +1002,7 @@ public void testReadAtSnapshot() throws InterruptedException, IOException {
10081002
/* destinationTableId= */ testTableId, /* query= */ "SELECT 2 AS col");
10091003

10101004
String table =
1011-
BigQueryResource.FormatTableResource(
1005+
BigQueryResource.formatTableResource(
10121006
/* projectId= */ projectName,
10131007
/* datasetId= */ DATASET,
10141008
/* tableId= */ testTableId.getTable());
@@ -1024,7 +1018,7 @@ public void accept(GenericData.Record record) {
10241018
rowsAfterFirstSnapshot.add((Long) record.get("col"));
10251019
}
10261020
});
1027-
assertEquals(Arrays.asList(1L), rowsAfterFirstSnapshot);
1021+
assertEquals(Collections.singletonList(1L), rowsAfterFirstSnapshot);
10281022

10291023
final List<Long> rowsAfterSecondSnapshot = new ArrayList<>();
10301024
ProcessRowsAtSnapshot(
@@ -1062,7 +1056,7 @@ public void testColumnPartitionedTableByDateField() throws InterruptedException,
10621056
RunQueryJobAndExpectSuccess(QueryJobConfiguration.newBuilder(createTableStatement).build());
10631057

10641058
String table =
1065-
BigQueryResource.FormatTableResource(
1059+
BigQueryResource.formatTableResource(
10661060
/* projectId= */ projectName,
10671061
/* datasetId= */ DATASET,
10681062
/* tableId= */ partitionedTableName);
@@ -1110,7 +1104,7 @@ public void testIngestionTimePartitionedTable() throws InterruptedException, IOE
11101104
/* query= */ "SELECT 2 AS num_field");
11111105

11121106
String table =
1113-
BigQueryResource.FormatTableResource(
1107+
BigQueryResource.formatTableResource(
11141108
/* projectId= */ projectName,
11151109
/* datasetId= */ testTableId.getDataset(),
11161110
/* tableId= */ testTableId.getTable());
@@ -1153,7 +1147,7 @@ public void testBasicSqlTypes() throws InterruptedException, IOException {
11531147
RunQueryJobAndExpectSuccess(QueryJobConfiguration.newBuilder(createTableStatement).build());
11541148

11551149
String table =
1156-
BigQueryResource.FormatTableResource(
1150+
BigQueryResource.formatTableResource(
11571151
/* projectId= */ projectName, /* datasetId= */ DATASET, /* tableId= */ tableName);
11581152

11591153
List<GenericData.Record> rows = ReadAllRows(/* table= */ table, /* filter= */ null);
@@ -1250,7 +1244,7 @@ public void testDateAndTimeSqlTypes() throws InterruptedException, IOException {
12501244
RunQueryJobAndExpectSuccess(QueryJobConfiguration.newBuilder(createTableStatement).build());
12511245

12521246
String table =
1253-
BigQueryResource.FormatTableResource(
1247+
BigQueryResource.formatTableResource(
12541248
/* projectId= */ projectName, /* datasetId= */ DATASET, /* tableId= */ tableName);
12551249

12561250
List<GenericData.Record> rows = ReadAllRows(/* table= */ table, /* filter= */ null);
@@ -1345,7 +1339,7 @@ public void testGeographySqlType() throws InterruptedException, IOException {
13451339
RunQueryJobAndExpectSuccess(QueryJobConfiguration.newBuilder(createTableStatement).build());
13461340

13471341
String table =
1348-
BigQueryResource.FormatTableResource(
1342+
BigQueryResource.formatTableResource(
13491343
/* projectId= */ projectName, /* datasetId= */ DATASET, /* tableId= */ tableName);
13501344

13511345
List<GenericData.Record> rows = ReadAllRows(/* table= */ table, /* filter= */ null);
@@ -1388,7 +1382,7 @@ public void testStructAndArraySqlTypes() throws InterruptedException, IOExceptio
13881382
RunQueryJobAndExpectSuccess(QueryJobConfiguration.newBuilder(createTableStatement).build());
13891383

13901384
String table =
1391-
BigQueryResource.FormatTableResource(
1385+
BigQueryResource.formatTableResource(
13921386
/* projectId= */ projectName, /* datasetId= */ DATASET, /* tableId= */ tableName);
13931387

13941388
List<GenericData.Record> rows = ReadAllRows(/* table= */ table, /* filter= */ null);
@@ -1456,7 +1450,7 @@ public void testSimpleReadWithBackgroundExecutorProvider()
14561450
client.getStub().getStubSettings().getBackgroundExecutorProvider())
14571451
.getExecutorThreadCount());
14581452
String table =
1459-
BigQueryResource.FormatTableResource(
1453+
BigQueryResource.formatTableResource(
14601454
/* projectId= */ "bigquery-public-data",
14611455
/* datasetId= */ "samples",
14621456
/* tableId= */ "shakespeare");
@@ -1500,7 +1494,7 @@ public void testUniverseDomainWithInvalidUniverseDomain() throws IOException {
15001494
BigQueryReadClient localClient = BigQueryReadClient.create(bigQueryReadSettings);
15011495

15021496
String table =
1503-
BigQueryResource.FormatTableResource(
1497+
BigQueryResource.formatTableResource(
15041498
/* projectId= */ "bigquery-public-data",
15051499
/* datasetId= */ "samples",
15061500
/* tableId= */ "shakespeare");
@@ -1535,7 +1529,7 @@ public void testInvalidUniverseDomainWithMismatchCredentials() throws IOExceptio
15351529
BigQueryReadClient localClient = BigQueryReadClient.create(bigQueryReadSettings);
15361530

15371531
String table =
1538-
BigQueryResource.FormatTableResource(
1532+
BigQueryResource.formatTableResource(
15391533
/* projectId= */ "bigquery-public-data",
15401534
/* datasetId= */ "samples",
15411535
/* tableId= */ "shakespeare");
@@ -1567,7 +1561,7 @@ public void testUniverseDomainWithMatchingDomain() throws IOException {
15671561
BigQueryReadClient localClient = BigQueryReadClient.create(bigQueryReadSettings);
15681562

15691563
String table =
1570-
BigQueryResource.FormatTableResource(
1564+
BigQueryResource.formatTableResource(
15711565
/* projectId= */ "bigquery-public-data",
15721566
/* datasetId= */ "samples",
15731567
/* tableId= */ "shakespeare");
@@ -1611,7 +1605,7 @@ public void testSimpleReadWithOtelTracing() throws IOException {
16111605
BigQueryReadClient otelClient = BigQueryReadClient.create(otelSettings);
16121606

16131607
String table =
1614-
BigQueryResource.FormatTableResource(
1608+
BigQueryResource.formatTableResource(
16151609
/* projectId= */ "bigquery-public-data",
16161610
/* datasetId= */ "samples",
16171611
/* tableId= */ "shakespeare");
@@ -1670,7 +1664,7 @@ public void testUniverseDomain() throws IOException {
16701664
BigQueryReadClient localClient = BigQueryReadClient.create(bigQueryReadSettings);
16711665

16721666
String table =
1673-
BigQueryResource.FormatTableResource(
1667+
BigQueryResource.formatTableResource(
16741668
/* projectId= */ "google-tpc-testing-environment:cloudsdk-test-project",
16751669
/* datasetId= */ "tpc_demo_dataset",
16761670
/* tableId= */ "new_table");
@@ -1712,10 +1706,8 @@ private long ReadStreamToOffset(ReadStream readStream, long rowOffset) {
17121706

17131707
long rowCount = 0;
17141708
ServerStream<ReadRowsResponse> serverStream = client.readRowsCallable().call(readRowsRequest);
1715-
Iterator<ReadRowsResponse> responseIterator = serverStream.iterator();
17161709

1717-
while (responseIterator.hasNext()) {
1718-
ReadRowsResponse response = responseIterator.next();
1710+
for (ReadRowsResponse response : serverStream) {
17191711
rowCount += response.getRowCount();
17201712
if (rowCount >= rowOffset) {
17211713
return rowOffset;
@@ -1856,8 +1848,7 @@ private Job RunQueryJobAndExpectSuccess(QueryJobConfiguration configuration)
18561848
}
18571849

18581850
static ServiceAccountCredentials loadCredentials(String credentialFile) {
1859-
try {
1860-
InputStream keyStream = new ByteArrayInputStream(credentialFile.getBytes());
1851+
try (InputStream keyStream = new ByteArrayInputStream(credentialFile.getBytes())) {
18611852
return ServiceAccountCredentials.fromStream(keyStream);
18621853
} catch (IOException e) {
18631854
fail("Couldn't create fake JSON credentials.");

0 commit comments

Comments
 (0)