@Test public void testToBuilder() { initializeExpectedJob(4); replay(bigquery); compareJob(expectedJob, expectedJob.toBuilder().build()); }
@Test public void testWaitForWithCheckingPeriod_Null() throws InterruptedException { initializeExpectedJob(2); BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; expect(bigquery.getOptions()).andReturn(mockOptions); expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()); Job runningJob = expectedJob.toBuilder().setStatus(new JobStatus(JobStatus.State.RUNNING)).build(); expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(runningJob); expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(null); replay(bigquery, mockOptions); initializeJob(); assertNull(job.waitFor(TEST_RETRY_OPTIONS)); verify(bigquery, mockOptions); }
@Test public void testWaitForWithCheckingPeriod() throws InterruptedException { initializeExpectedJob(3); BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; JobStatus status = createStrictMock(JobStatus.class); expect(status.getState()).andReturn(JobStatus.State.RUNNING); // caused by optimizing extra call to ResultRetryAlgorithm#shouldRetry() expect(status.getState()).andReturn(JobStatus.State.RUNNING); expect(status.getState()).andReturn(JobStatus.State.DONE); // caused by optimizing extra call to ResultRetryAlgorithm#shouldRetry() expect(status.getState()).andReturn(JobStatus.State.DONE); expect(bigquery.getOptions()).andReturn(mockOptions); expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()); Job runningJob = expectedJob.toBuilder().setStatus(status).build(); Job completedJob = expectedJob.toBuilder().setStatus(status).build(); expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(runningJob); expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(completedJob); expect(bigquery.getJob(JOB_INFO.getJobId())).andReturn(completedJob); replay(status, bigquery, mockOptions); initializeJob(); assertSame(completedJob, job.waitFor(TEST_RETRY_OPTIONS)); verify(status, mockOptions); }
@Test public void testIsDone_True() throws Exception { initializeExpectedJob(2); BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; JobStatus status = createStrictMock(JobStatus.class); expect(status.getState()).andReturn(JobStatus.State.DONE); expect(bigquery.getOptions()).andReturn(mockOptions); expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)) .andReturn(expectedJob.toBuilder().setStatus(status).build()); replay(status, bigquery); initializeJob(); assertTrue(job.isDone()); verify(status); }
@Test public void testIsDone_False() throws Exception { initializeExpectedJob(2); BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; JobStatus status = createStrictMock(JobStatus.class); expect(status.getState()).andReturn(JobStatus.State.RUNNING); expect(bigquery.getOptions()).andReturn(mockOptions); expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)) .andReturn(expectedJob.toBuilder().setStatus(status).build()); replay(status, bigquery); initializeJob(); assertFalse(job.isDone()); verify(status); }
@Test public void testWaitFor() throws InterruptedException { initializeExpectedJob(2); BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; JobStatus status = createStrictMock(JobStatus.class); expect(status.getState()).andReturn(JobStatus.State.DONE); // caused by optimizing extra call to ResultRetryAlgorithm#shouldRetry() expect(status.getState()).andReturn(JobStatus.State.DONE); expect(bigquery.getOptions()).andReturn(mockOptions); expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()); Job completedJob = expectedJob.toBuilder().setStatus(status).build(); expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(completedJob); expect(bigquery.getJob(JOB_INFO.getJobId())).andReturn(completedJob); replay(status, bigquery, mockOptions); initializeJob(); assertSame(completedJob, job.waitFor(TEST_RETRY_OPTIONS)); verify(status, mockOptions); }
expect(bigquery.getOptions()).andReturn(mockOptions); expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()).times(2); Job completedJob = expectedJob.toBuilder().setStatus(status).build();
expect(bigquery.getOptions()).andReturn(mockOptions); expect(mockOptions.getClock()).andReturn(CurrentMillisClock.getDefaultClock()).times(2); Job completedJob = expectedJob.toBuilder().setStatus(status).build();