Skip to content

Commit a5a7650

Browse files
committed
fix unittests
1 parent 63f01c1 commit a5a7650

2 files changed

Lines changed: 11 additions & 19 deletions

File tree

java-bigquery/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryStatementTest.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public void testExecSlowQueryPath() throws SQLException, InterruptedException {
214214
.build();
215215
Job job = getJobMock(tableResult, queryJobConfiguration, StatementType.SELECT);
216216

217-
doReturn(job).when(bigquery).create(any(JobInfo.class));
217+
doReturn(job).when(bigquery).queryWithTimeout(any(), any(), any());
218218

219219
doReturn(jobIdWrapper)
220220
.when(bigQueryStatementSpy)
@@ -299,14 +299,14 @@ public void setQueryTimeoutTest() throws Exception {
299299
QueryJobConfiguration.newBuilder(query).setJobTimeoutMs(10000L).build();
300300

301301
Job job = getJobMock(result, jobConfiguration, StatementType.SELECT);
302-
doReturn(job).when(bigquery).create(any(JobInfo.class));
302+
doReturn(job).when(bigquery).queryWithTimeout(any(), any(), any());
303303

304304
doReturn(jsonResultSet).when(bigQueryStatementSpy).processJsonResultSet(result);
305-
ArgumentCaptor<JobInfo> captor = ArgumentCaptor.forClass(JobInfo.class);
305+
ArgumentCaptor<QueryJobConfiguration> captor = ArgumentCaptor.forClass(QueryJobConfiguration.class);
306306

307307
bigQueryStatementSpy.runQuery(query, jobConfiguration);
308-
verify(bigquery).create(captor.capture());
309-
QueryJobConfiguration jobConfig = captor.getValue().getConfiguration();
308+
verify(bigquery).queryWithTimeout(captor.capture(), any(), any());
309+
QueryJobConfiguration jobConfig = captor.getValue();
310310
assertEquals(3000L, jobConfig.getJobTimeoutMs().longValue());
311311
}
312312

@@ -395,23 +395,16 @@ public void testJoblessQuery() throws SQLException, InterruptedException {
395395
TableResult tableResultJobfulMock = mock(TableResult.class);
396396
QueryJobConfiguration jobConf = QueryJobConfiguration.newBuilder("SELECT 1").build();
397397
Job jobMock = getJobMock(tableResultJobfulMock, jobConf, StatementType.SELECT);
398-
ArgumentCaptor<JobInfo> jobfulCaptor = ArgumentCaptor.forClass(JobInfo.class);
399-
doReturn(jobMock).when(bigquery).create(jobfulCaptor.capture());
398+
doReturn(jobMock)
399+
.when(bigquery)
400+
.queryWithTimeout(any(QueryJobConfiguration.class), any(), any());
400401
doReturn(mock(BigQueryJsonResultSet.class))
401402
.when(jobfulStatementSpy)
402403
.processJsonResultSet(tableResultJobfulMock);
403404

404405
jobfulStatementSpy.executeQuery("SELECT 1");
405406

406-
verify(bigquery).create(any(JobInfo.class));
407-
assertTrue(
408-
jobfulCaptor.getAllValues().stream()
409-
.noneMatch(
410-
jobInfo ->
411-
Boolean.TRUE.equals(
412-
((QueryJobConfiguration) jobInfo.getConfiguration()).dryRun())));
413-
verify(bigquery, Mockito.never())
414-
.queryWithTimeout(any(QueryJobConfiguration.class), any(), any());
407+
verify(bigquery).queryWithTimeout(any(QueryJobConfiguration.class), any(), any());
415408
}
416409

417410
@Test
@@ -424,7 +417,7 @@ public void testCloseCancelsJob() throws SQLException, InterruptedException {
424417
QueryJobConfiguration.newBuilder(query).setPriority(Priority.BATCH).build();
425418
Job job = getJobMock(tableResult, queryJobConfiguration, StatementType.SELECT);
426419

427-
doReturn(job).when(bigquery).create(any(JobInfo.class));
420+
doReturn(job).when(bigquery).queryWithTimeout(any(), any(), any());
428421
doReturn(false).when(bigQueryStatementSpy).useReadAPI(eq(tableResult));
429422
doReturn(mock(JobId.class)).when(tableResult).getJobId();
430423
Mockito.when(job.getQueryResults(any(QueryResultsOption.class)))

java-bigquery/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITAuthTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ public class ITAuthTests extends ITBase {
4949
static final String PROJECT_ID = ServiceOptions.getDefaultProjectId();
5050

5151
private JsonObject getAuthJson() throws IOException {
52-
final String secret =
53-
"{ \"type\": \"service_account\", \"project_id\": \"bigquery-devtools-drivers\", \"private_key_id\": \"639684ac492aa88005b51c742fe696485b42c283\", \"private_key\": \"-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDCYKmx1Prmdtym\n1nfJxrl7fh5ew9HG17GgnU12Npl4llWwiyZQqr9OKnzyhtQJuYlx4EKti112kzOt\nUUicOhq1wuq0mOsHwJsQaQu4AENN4Xi7qXtxPV9w8lrf73mLQ4wSwIHv2LvDtf7B\nUSP0pwv8hAtEHFCp9TNdXqE+NCuBoGObp7vyv2iN230y6mLRyqgjjPfSgu1mdsfQ\ntqMthVTzn3AxTnAdpaNzWlQrRq8MnMt3eVr53hwRJ1tb7zVq1TfxgiQjgvXK9iEa\nbVSy4c8Sc1qvAGA6CmdHBpQ64iJgIou9FprVRgAzKdQrC1vRbb371nSwmIXL74c+\nQ5Ry+ol/AgMBAAECggEAEUYFzofexBxL/4ePnZ7LXO4YRNOiEMmaP2u7NoYjnVO+\nybGT9hc2aPvdnq/cqACU9km3ozR/Wco7DWvrx/Zh6UUpFmOAf2/eV9b985wSXxlq\nYULudWG+2YqwCLZ/VqDqEcCJy4a3KO1Ddmp/h35Q0l/poGPjxzbDGckPCzgXpa0z\nZNdIcuhcH9muyh+mzGm3UMHtsddv1KDCSkTncJXsI6JR7IWyvro2LOVJp6uGeXRr\nYTdMfNPPrK5rYG+qM3yCnbhil7brSyn+q45rNgkEfvn4vTFfT90YgaXYXj9HQyWH\nqtWJoc6QseDTetYTLq4fioH8xJqs6NmMrP5umccOAQKBgQDyLsPvb3NnjCHyheN6\nk2URTk2D3fT0zakvHuODePokEv3tQh/2lJvqVNBQ/JDvEyQuU8vijLnOngL2zWFq\n6dZ9UuGPV8UhIcSAwH6/9GHzRJjxa2gFurlCzJU+1eaDdvnw9ILKVNl3TdYsbjMx\n0/Q9L5cR/yv0/flfNRlKmTMZwwKBgQDNd6xbiZdMmhW7vUV1x4Rez+sgGOaDUb6F\n7JXcppf+hfkt4uP1HvlU8FIp/1yDRabRo49UYHgmCyNV1oISGgTKWIRvhEpbmjEx\nsJC+vwRRm0h9WD/kSgY5oeZYBxu676EYqFk+mK3U1RWHk6IY5ulnzZZGRX4U3o6H\nZYMY9l2ZlQKBgB4knfSGPanssij6aybNg63UvickkCGMG3um75BklVW6G2rVaR8K\nviE7bzY1SWDIVB+EBINtGo9R8XKAe5iQBEdS8ooh1YJbLpcL3nrL0wkxR4v831Sf\nOgHLbuQEQY2pWFCaTlEaoHqN8JNVIAAarnKTIs11oiX7Gne0JzK2wLp7AoGAVJui\nGvOWnRGaP3vaHXzyMkS2ErqOOacwqF9a+siTMFkk2dNjgW2myGZJv0eLZfcJkawj\nemBbOXc+rrstRpz2OginSHCWWhAtj8OgZxurgJtMB2mOrcgZtiPIAZmzvo+sq8Wv\nMkqW0lyIiBKwHkb/+CG9buRw3dEjqfeQO3g/5N0CgYEAxQKxZxDO/j12coY0Es6a\nd1krdB49TFYUhdS8gAJDTeOQgOCJZqa69jbkKHF1DWKSBLObhpA2QsSEk7yUAdTv\nerZAHnf09FqNWe6kBs+WU/urIF+FREprseIbCYZULCjuGDPUVkmapHIy3irwYFZO\nxHP5FrM7GoTRpY5p9P1BDK0=\n-----END PRIVATE KEY-----\n\", \"client_email\": \"github-actions@bigquery-devtools-drivers.iam.gserviceaccount.com\", \"client_id\": \"114365723126486061952\", \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\", \"token_uri\": \"https://oauth2.googleapis.com/token\", \"auth_provider_x509_cert_url\": \"https://www.googleapis.com/oauth2/v1/certs\", \"client_x509_cert_url\": \"https://www.googleapis.com/robot/v1/metadata/x509/github-actions%40bigquery-devtools-drivers.iam.gserviceaccount.com\", \"universe_domain\": \"googleapis.com\" }"; // requireEnvVar("SA_SECRET");
52+
final String secret = requireEnvVar("SA_SECRET");
5453
JsonObject authJson;
5554
// Supporting both formats of SA_SECRET:
5655
// - Local runs can point to a json file

0 commit comments

Comments
 (0)