forked from googleapis/java-bigquery
/
JobTest.java
519 lines (475 loc) · 21.2 KB
/
JobTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
/*
* Copyright 2015 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.bigquery;
import static com.google.common.collect.ObjectArrays.concat;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.google.api.core.CurrentMillisClock;
import com.google.api.gax.paging.Page;
import com.google.cloud.RetryOption;
import com.google.cloud.bigquery.JobStatistics.CopyStatistics;
import com.google.cloud.bigquery.JobStatistics.QueryStatistics;
import com.google.cloud.bigquery.JobStatus.State;
import com.google.common.collect.ImmutableList;
import java.util.Collections;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.MockitoRule;
import org.threeten.bp.Duration;
@RunWith(MockitoJUnitRunner.class)
public class JobTest {
private static final JobId JOB_ID = JobId.of("project", "job");
private static final TableId TABLE_ID1 = TableId.of("dataset", "table1");
private static final TableId TABLE_ID2 = TableId.of("dataset", "table2");
private static final String ETAG = "etag";
private static final String GENERATED_ID = "id";
private static final String SELF_LINK = "selfLink";
private static final String EMAIL = "email";
private static final JobStatus JOB_STATUS = new JobStatus(JobStatus.State.DONE);
private static final JobStatistics COPY_JOB_STATISTICS =
CopyStatistics.newBuilder().setCreationTimestamp(1L).setEndTime(3L).setStartTime(2L).build();
private static final CopyJobConfiguration COPY_CONFIGURATION =
CopyJobConfiguration.of(TABLE_ID1, TABLE_ID2);
private static final JobInfo JOB_INFO =
JobInfo.newBuilder(COPY_CONFIGURATION)
.setJobId(JOB_ID)
.setStatistics(COPY_JOB_STATISTICS)
.setJobId(JOB_ID)
.setEtag(ETAG)
.setGeneratedId(GENERATED_ID)
.setSelfLink(SELF_LINK)
.setUserEmail(EMAIL)
.setStatus(JOB_STATUS)
.build();
private static final RetryOption[] TEST_RETRY_OPTIONS =
new RetryOption[] {
RetryOption.totalTimeout(Duration.ofSeconds(3)),
RetryOption.initialRetryDelay(Duration.ofMillis(1L)),
RetryOption.jittered(false),
RetryOption.retryDelayMultiplier(1.0)
};
@Rule public MockitoRule rule;
private BigQuery bigquery;
private BigQueryOptions mockOptions;
private Job expectedJob;
private Job job;
@Before
public void setUp() {
bigquery = mock(BigQuery.class);
mockOptions = mock(BigQueryOptions.class);
when(bigquery.getOptions()).thenReturn(mockOptions);
expectedJob = new Job(bigquery, new JobInfo.BuilderImpl(JOB_INFO));
job = new Job(bigquery, new JobInfo.BuilderImpl(JOB_INFO));
}
@Test
public void testBuilder() {
Job builtJob =
new Job.Builder(bigquery, COPY_CONFIGURATION)
.setJobId(JOB_ID)
.setStatistics(COPY_JOB_STATISTICS)
.setJobId(JOB_ID)
.setEtag(ETAG)
.setGeneratedId(GENERATED_ID)
.setSelfLink(SELF_LINK)
.setUserEmail(EMAIL)
.setStatus(JOB_STATUS)
.build();
assertEquals(ETAG, builtJob.getEtag());
assertEquals(GENERATED_ID, builtJob.getGeneratedId());
assertEquals(SELF_LINK, builtJob.getSelfLink());
assertEquals(EMAIL, builtJob.getUserEmail());
assertEquals(JOB_ID, builtJob.getJobId());
assertEquals(JOB_STATUS, builtJob.getStatus());
assertEquals(COPY_CONFIGURATION, builtJob.getConfiguration());
assertEquals(COPY_JOB_STATISTICS, builtJob.getStatistics());
assertSame(bigquery, builtJob.getBigQuery());
}
@Test
public void testToBuilder() {
compareJob(expectedJob, expectedJob.toBuilder().build());
}
@Test
public void testExists_True() {
BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields()};
when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(expectedJob);
assertTrue(job.exists());
verify(bigquery).getJob(JOB_INFO.getJobId(), expectedOptions);
}
@Test
public void testExists_False() {
BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields()};
when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(null);
assertFalse(job.exists());
verify(bigquery).getJob(JOB_INFO.getJobId(), expectedOptions);
}
@Test
public void testIsDone_True() {
BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)};
Job job = expectedJob.toBuilder().setStatus(new JobStatus(JobStatus.State.DONE)).build();
when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(job);
assertTrue(job.isDone());
verify(bigquery).getJob(JOB_INFO.getJobId(), expectedOptions);
}
@Test
public void testIsDone_False() {
BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)};
Job job = expectedJob.toBuilder().setStatus(new JobStatus(JobStatus.State.RUNNING)).build();
when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(job);
assertFalse(job.isDone());
verify(bigquery).getJob(JOB_INFO.getJobId(), expectedOptions);
}
@Test
public void testIsDone_NotExists() {
BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)};
when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(null);
assertTrue(job.isDone());
verify(bigquery).getJob(JOB_INFO.getJobId(), expectedOptions);
}
@Test
public void testWaitFor() throws InterruptedException {
BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)};
JobStatus status = mock(JobStatus.class);
when(status.getState()).thenReturn(JobStatus.State.DONE);
// caused by optimizing extra call to ResultRetryAlgorithm#shouldRetry()
when(status.getState()).thenReturn(JobStatus.State.DONE);
when(mockOptions.getClock()).thenReturn(CurrentMillisClock.getDefaultClock());
Job completedJob = expectedJob.toBuilder().setStatus(status).build();
when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(completedJob);
when(bigquery.getJob(JOB_INFO.getJobId())).thenReturn(completedJob);
assertSame(completedJob, job.waitFor(TEST_RETRY_OPTIONS));
verify(mockOptions).getClock();
verify(bigquery).getJob(JOB_INFO.getJobId(), expectedOptions);
verify(bigquery).getJob(JOB_INFO.getJobId());
}
@Test
public void testWaitForAndGetQueryResultsEmpty() throws InterruptedException {
QueryJobConfiguration jobConfig =
QueryJobConfiguration.newBuilder("CREATE VIEW").setDestinationTable(TABLE_ID1).build();
QueryStatistics jobStatistics =
QueryStatistics.newBuilder()
.setCreationTimestamp(1L)
.setEndTime(3L)
.setStartTime(2L)
.build();
JobInfo jobInfo =
JobInfo.newBuilder(jobConfig)
.setJobId(JOB_ID)
.setStatistics(jobStatistics)
.setJobId(JOB_ID)
.setEtag(ETAG)
.setGeneratedId(GENERATED_ID)
.setSelfLink(SELF_LINK)
.setUserEmail(EMAIL)
.setStatus(JOB_STATUS)
.build();
when(mockOptions.getClock()).thenReturn(CurrentMillisClock.getDefaultClock());
Job completedJob =
expectedJob.toBuilder().setStatus(new JobStatus(JobStatus.State.RUNNING)).build();
QueryResponse completedQuery =
QueryResponse.newBuilder()
.setCompleted(true)
.setTotalRows(0)
.setSchema(Schema.of())
.setErrors(ImmutableList.<BigQueryError>of())
.build();
when(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS))
.thenReturn(completedQuery);
when(bigquery.getJob(JOB_INFO.getJobId())).thenReturn(completedJob);
when(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS))
.thenReturn(completedQuery);
when(bigquery.getJob(JOB_INFO.getJobId())).thenReturn(completedJob);
job = this.job.toBuilder().setConfiguration(jobConfig).build();
assertThat(job.waitFor(TEST_RETRY_OPTIONS)).isSameInstanceAs(completedJob);
assertThat(job.getQueryResults().iterateAll()).isEmpty();
verify(bigquery, times(2)).getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS);
verify(bigquery).getJob(JOB_INFO.getJobId());
}
@Test
public void testWaitForAndGetQueryResultsEmptyWithSchema() throws InterruptedException {
QueryJobConfiguration jobConfig =
QueryJobConfiguration.newBuilder("CREATE VIEW").setDestinationTable(TABLE_ID1).build();
QueryStatistics jobStatistics =
QueryStatistics.newBuilder()
.setCreationTimestamp(1L)
.setEndTime(3L)
.setStartTime(2L)
.build();
JobInfo jobInfo =
JobInfo.newBuilder(jobConfig)
.setJobId(JOB_ID)
.setStatistics(jobStatistics)
.setJobId(JOB_ID)
.setEtag(ETAG)
.setGeneratedId(GENERATED_ID)
.setSelfLink(SELF_LINK)
.setUserEmail(EMAIL)
.setStatus(JOB_STATUS)
.build();
JobStatus status = mock(JobStatus.class);
when(bigquery.getOptions()).thenReturn(mockOptions);
when(mockOptions.getClock()).thenReturn(CurrentMillisClock.getDefaultClock());
Job completedJob =
expectedJob.toBuilder().setStatus(new JobStatus(JobStatus.State.RUNNING)).build();
QueryResponse completedQuery =
QueryResponse.newBuilder()
.setCompleted(true)
.setTotalRows(0)
.setSchema(Schema.of(Field.of("field1", LegacySQLTypeName.BOOLEAN)))
.setErrors(ImmutableList.<BigQueryError>of())
.build();
when(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS))
.thenReturn(completedQuery);
when(bigquery.getJob(JOB_INFO.getJobId())).thenReturn(completedJob);
when(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS))
.thenReturn(completedQuery);
job = this.job.toBuilder().setConfiguration(jobConfig).build();
assertThat(job.waitFor(TEST_RETRY_OPTIONS)).isSameInstanceAs(completedJob);
assertThat(job.getQueryResults().getSchema())
.isEqualTo(Schema.of(Field.of("field1", LegacySQLTypeName.BOOLEAN)));
verify(bigquery, times(2)).getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS);
verify(bigquery).getJob(JOB_INFO.getJobId());
}
@Test
public void testWaitForAndGetQueryResults() throws InterruptedException {
QueryJobConfiguration jobConfig =
QueryJobConfiguration.newBuilder("SELECT 1").setDestinationTable(TABLE_ID1).build();
QueryStatistics jobStatistics =
QueryStatistics.newBuilder()
.setCreationTimestamp(1L)
.setEndTime(3L)
.setStartTime(2L)
.build();
JobInfo jobInfo =
JobInfo.newBuilder(jobConfig)
.setJobId(JOB_ID)
.setStatistics(jobStatistics)
.setJobId(JOB_ID)
.setEtag(ETAG)
.setGeneratedId(GENERATED_ID)
.setSelfLink(SELF_LINK)
.setUserEmail(EMAIL)
.setStatus(JOB_STATUS)
.build();
JobStatus status = mock(JobStatus.class);
when(bigquery.getOptions()).thenReturn(mockOptions);
when(mockOptions.getClock()).thenReturn(CurrentMillisClock.getDefaultClock());
Job completedJob =
expectedJob.toBuilder().setStatus(new JobStatus(JobStatus.State.RUNNING)).build();
// TODO(pongad): remove when we bump gax to 1.15.
Page<FieldValueList> singlePage =
new Page<FieldValueList>() {
@Override
public boolean hasNextPage() {
return false;
}
@Override
public String getNextPageToken() {
return "";
}
@Override
public Page<FieldValueList> getNextPage() {
return null;
}
@Override
public Iterable<FieldValueList> iterateAll() {
return Collections.emptyList();
}
@Override
public Iterable<FieldValueList> getValues() {
return Collections.emptyList();
}
};
TableResult result = new TableResult(Schema.of(), 1, singlePage);
QueryResponse completedQuery =
QueryResponse.newBuilder()
.setCompleted(true)
.setTotalRows(1) // Lies to force call of listTableData().
.setSchema(Schema.of(Field.of("_f0", LegacySQLTypeName.INTEGER)))
.setErrors(ImmutableList.<BigQueryError>of())
.build();
when(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS))
.thenReturn(completedQuery);
when(bigquery.getJob(JOB_INFO.getJobId())).thenReturn(completedJob);
when(bigquery.getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS))
.thenReturn(completedQuery);
when(bigquery.listTableData(eq(TABLE_ID1), any(Schema.class))).thenReturn(result);
job = this.job.toBuilder().setConfiguration(jobConfig).build();
assertThat(job.waitFor(TEST_RETRY_OPTIONS)).isSameInstanceAs(completedJob);
assertThat(job.getQueryResults().iterateAll()).hasSize(0);
verify(bigquery, times(2)).getQueryResults(jobInfo.getJobId(), Job.DEFAULT_QUERY_WAIT_OPTIONS);
verify(bigquery).getJob(JOB_INFO.getJobId());
}
@Test
public void testWaitForAndGetQueryResults_Unsupported() throws InterruptedException {
try {
job.getQueryResults();
Assert.fail();
} catch (UnsupportedOperationException expected) {
Assert.assertNotNull(expected.getMessage());
}
}
@Test
public void testWaitFor_Null() throws InterruptedException {
BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)};
when(mockOptions.getClock()).thenReturn(CurrentMillisClock.getDefaultClock());
when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(null);
assertNull(job.waitFor(TEST_RETRY_OPTIONS));
verify(bigquery).getJob(JOB_INFO.getJobId(), expectedOptions);
}
@Test
public void testWaitForWithCheckingPeriod() throws InterruptedException {
BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)};
JobStatus status = mock(JobStatus.class);
when(status.getState()).thenReturn(JobStatus.State.RUNNING);
// caused by optimizing extra call to ResultRetryAlgorithm#shouldRetry()
when(status.getState()).thenReturn(JobStatus.State.RUNNING);
when(status.getState()).thenReturn(JobStatus.State.DONE);
// caused by optimizing extra call to ResultRetryAlgorithm#shouldRetry()
when(status.getState()).thenReturn(JobStatus.State.DONE);
when(mockOptions.getClock()).thenReturn(CurrentMillisClock.getDefaultClock());
Job runningJob = expectedJob.toBuilder().setStatus(status).build();
Job completedJob = expectedJob.toBuilder().setStatus(status).build();
when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(runningJob);
when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(completedJob);
when(bigquery.getJob(JOB_INFO.getJobId())).thenReturn(completedJob);
assertSame(completedJob, job.waitFor(TEST_RETRY_OPTIONS));
verify(mockOptions).getClock();
verify(bigquery).getJob(JOB_INFO.getJobId(), expectedOptions);
verify(bigquery).getJob(JOB_INFO.getJobId());
}
@Test
public void testWaitForWithCheckingPeriod_Null() throws InterruptedException {
BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)};
when(mockOptions.getClock()).thenReturn(CurrentMillisClock.getDefaultClock());
Job runningJob =
expectedJob.toBuilder().setStatus(new JobStatus(JobStatus.State.RUNNING)).build();
when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(runningJob);
when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(null);
assertNull(job.waitFor(TEST_RETRY_OPTIONS));
verify(mockOptions).getClock();
verify(bigquery).getJob(JOB_INFO.getJobId(), expectedOptions);
}
@Test
public void testWaitForWithTimeout() throws InterruptedException {
BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)};
when(mockOptions.getClock()).thenReturn(CurrentMillisClock.getDefaultClock());
Job runningJob =
expectedJob.toBuilder().setStatus(new JobStatus(JobStatus.State.RUNNING)).build();
when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(runningJob);
when(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).thenReturn(runningJob);
try {
job.waitFor(concat(TEST_RETRY_OPTIONS, RetryOption.totalTimeout(Duration.ofMillis(3))));
Assert.fail();
} catch (BigQueryException expected) {
Assert.assertNotNull(expected.getMessage());
}
}
@Test
public void testReload() {
JobInfo updatedInfo = JOB_INFO.toBuilder().setEtag("etag").build();
Job expectedJob = new Job(bigquery, new JobInfo.BuilderImpl(updatedInfo));
when(bigquery.getJob(JOB_INFO.getJobId())).thenReturn(expectedJob);
Job updatedJob = job.reload();
compareJob(expectedJob, updatedJob);
verify(bigquery).getJob(JOB_INFO.getJobId());
}
@Test
public void testReloadJobException() {
JobInfo updatedInfo = JOB_INFO.toBuilder().setEtag("etag").build();
Job expectedJob = new Job(bigquery, new JobInfo.BuilderImpl(updatedInfo));
BigQueryError bigQueryError = new BigQueryError("invalidQuery", "US", "invalidQuery");
expectedJob =
expectedJob.toBuilder().setStatus(new JobStatus(State.DONE, bigQueryError, null)).build();
ImmutableList<BigQueryError> bigQueryErrorList = ImmutableList.of(bigQueryError);
JobException jobException = new JobException(expectedJob.getJobId(), bigQueryErrorList);
when(bigquery.getJob(JOB_INFO.getJobId())).thenReturn(expectedJob).thenThrow(jobException);
try {
job.reload();
fail("JobException expected");
} catch (JobException e) {
assertNotNull(e.getErrors());
}
}
@Test
public void testReloadNull() {
when(bigquery.getJob(JOB_INFO.getJobId())).thenReturn(null);
assertNull(job.reload());
verify(bigquery).getJob(JOB_INFO.getJobId());
}
@Test
public void testReloadWithOptions() {
JobInfo updatedInfo = JOB_INFO.toBuilder().setEtag("etag").build();
Job expectedJob = new Job(bigquery, new JobInfo.BuilderImpl(updatedInfo));
when(bigquery.getJob(JOB_INFO.getJobId(), BigQuery.JobOption.fields())).thenReturn(expectedJob);
Job updatedJob = job.reload(BigQuery.JobOption.fields());
compareJob(expectedJob, updatedJob);
verify(bigquery).getJob(JOB_INFO.getJobId(), BigQuery.JobOption.fields());
}
@Test
public void testCancel() {
when(bigquery.cancel(JOB_INFO.getJobId())).thenReturn(true);
assertTrue(job.cancel());
verify(bigquery).cancel(JOB_INFO.getJobId());
}
@Test
public void testBigQuery() {
assertSame(bigquery, expectedJob.getBigQuery());
}
@Test
public void testToAndFromPb() {
compareJob(expectedJob, Job.fromPb(bigquery, expectedJob.toPb()));
}
@Test
public void testToAndFromPbWithoutConfiguration() {
assertNotEquals(expectedJob, bigquery);
compareJob(expectedJob, Job.fromPb(bigquery, expectedJob.toPb()));
}
private void compareJob(Job expected, Job value) {
assertEquals(expected, value);
compareJobInfo(expected, value);
assertEquals(expected.getBigQuery().getOptions(), value.getBigQuery().getOptions());
}
private void compareJobInfo(JobInfo expected, JobInfo value) {
assertEquals(expected, value);
assertEquals(expected.hashCode(), value.hashCode());
assertEquals(expected.toString(), value.toString());
assertEquals(expected.getEtag(), value.getEtag());
assertEquals(expected.getGeneratedId(), value.getGeneratedId());
assertEquals(expected.getJobId(), value.getJobId());
assertEquals(expected.getSelfLink(), value.getSelfLink());
assertEquals(expected.getStatus(), value.getStatus());
assertEquals(expected.getStatistics(), value.getStatistics());
assertEquals(expected.getUserEmail(), value.getUserEmail());
assertEquals(expected.getConfiguration(), value.getConfiguration());
}
}