/** Example of cancelling a job. */ // [TARGET cancel()] public boolean cancel() { // [START ] if (job.cancel()) { return true; // job successfully cancelled } else { // job not found } // [END ] return false; } }
@Test public void testCancel() throws Exception { initializeExpectedJob(1); expect(bigquery.getOptions()).andReturn(mockOptions); expect(bigquery.cancel(JOB_INFO.getJobId())).andReturn(true); replay(bigquery); initializeJob(); assertTrue(job.cancel()); }
@Test public void testCancelJob() throws InterruptedException, TimeoutException { String destinationTableName = "test_cancel_query_job_table"; String query = "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID.getTable(); TableId destinationTable = TableId.of(DATASET, destinationTableName); QueryJobConfiguration configuration = QueryJobConfiguration.newBuilder(query) .setDefaultDataset(DatasetId.of(DATASET)) .setDestinationTable(destinationTable) .build(); Job remoteJob = bigquery.create(JobInfo.of(configuration)); assertTrue(remoteJob.cancel()); remoteJob = remoteJob.waitFor(); assertNull(remoteJob.getStatus().getError()); }