本文整理汇总了Java中com.google.api.services.bigquery.model.Job.setStatus方法的典型用法代码示例。如果您正苦于以下问题:Java Job.setStatus方法的具体用法?Java Job.setStatus怎么用?Java Job.setStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.services.bigquery.model.Job
的用法示例。
在下文中一共展示了Job.setStatus方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPollJobSucceeds
import com.google.api.services.bigquery.model.Job; //导入方法依赖的package包/类
/**
* Tests that {@link BigQueryServicesImpl.JobServiceImpl#pollJob} succeeds.
*/
@Test
public void testPollJobSucceeds() throws IOException, InterruptedException {
Job testJob = new Job();
testJob.setStatus(new JobStatus().setState("DONE"));
when(response.getContentType()).thenReturn(Json.MEDIA_TYPE);
when(response.getStatusCode()).thenReturn(200);
when(response.getContent()).thenReturn(toStream(testJob));
BigQueryServicesImpl.JobServiceImpl jobService =
new BigQueryServicesImpl.JobServiceImpl(bigquery);
JobReference jobRef = new JobReference()
.setProjectId("projectId")
.setJobId("jobId");
Job job = jobService.pollJob(jobRef, Sleeper.DEFAULT, BackOff.ZERO_BACKOFF);
assertEquals(testJob, job);
verify(response, times(1)).getStatusCode();
verify(response, times(1)).getContent();
verify(response, times(1)).getContentType();
}
示例2: testPollJobFailed
import com.google.api.services.bigquery.model.Job; //导入方法依赖的package包/类
/**
* Tests that {@link BigQueryServicesImpl.JobServiceImpl#pollJob} fails.
*/
@Test
public void testPollJobFailed() throws IOException, InterruptedException {
Job testJob = new Job();
testJob.setStatus(new JobStatus().setState("DONE").setErrorResult(new ErrorProto()));
when(response.getContentType()).thenReturn(Json.MEDIA_TYPE);
when(response.getStatusCode()).thenReturn(200);
when(response.getContent()).thenReturn(toStream(testJob));
BigQueryServicesImpl.JobServiceImpl jobService =
new BigQueryServicesImpl.JobServiceImpl(bigquery);
JobReference jobRef = new JobReference()
.setProjectId("projectId")
.setJobId("jobId");
Job job = jobService.pollJob(jobRef, Sleeper.DEFAULT, BackOff.ZERO_BACKOFF);
assertEquals(testJob, job);
verify(response, times(1)).getStatusCode();
verify(response, times(1)).getContent();
verify(response, times(1)).getContentType();
}
示例3: testPollJobUnknown
import com.google.api.services.bigquery.model.Job; //导入方法依赖的package包/类
/**
* Tests that {@link BigQueryServicesImpl.JobServiceImpl#pollJob} returns UNKNOWN.
*/
@Test
public void testPollJobUnknown() throws IOException, InterruptedException {
Job testJob = new Job();
testJob.setStatus(new JobStatus());
when(response.getContentType()).thenReturn(Json.MEDIA_TYPE);
when(response.getStatusCode()).thenReturn(200);
when(response.getContent()).thenReturn(toStream(testJob));
BigQueryServicesImpl.JobServiceImpl jobService =
new BigQueryServicesImpl.JobServiceImpl(bigquery);
JobReference jobRef = new JobReference()
.setProjectId("projectId")
.setJobId("jobId");
Job job = jobService.pollJob(jobRef, Sleeper.DEFAULT, BackOff.STOP_BACKOFF);
assertEquals(null, job);
verify(response, times(1)).getStatusCode();
verify(response, times(1)).getContent();
verify(response, times(1)).getContentType();
}
示例4: testGetJobSucceeds
import com.google.api.services.bigquery.model.Job; //导入方法依赖的package包/类
@Test
public void testGetJobSucceeds() throws Exception {
Job testJob = new Job();
testJob.setStatus(new JobStatus());
when(response.getContentType()).thenReturn(Json.MEDIA_TYPE);
when(response.getStatusCode()).thenReturn(200);
when(response.getContent()).thenReturn(toStream(testJob));
BigQueryServicesImpl.JobServiceImpl jobService =
new BigQueryServicesImpl.JobServiceImpl(bigquery);
JobReference jobRef = new JobReference()
.setProjectId("projectId")
.setJobId("jobId");
Job job = jobService.getJob(jobRef, Sleeper.DEFAULT, BackOff.ZERO_BACKOFF);
assertEquals(testJob, job);
verify(response, times(1)).getStatusCode();
verify(response, times(1)).getContent();
verify(response, times(1)).getContentType();
}
示例5: startExtractJob
import com.google.api.services.bigquery.model.Job; //导入方法依赖的package包/类
@Override
public void startExtractJob(JobReference jobRef, JobConfigurationExtract extractConfig)
throws InterruptedException, IOException {
checkArgument(extractConfig.getDestinationFormat().equals("AVRO"),
"Only extract to AVRO is supported");
synchronized (allJobs) {
verifyUniqueJobId(jobRef.getJobId());
++numExtractJobCalls;
Job job = new Job();
job.setJobReference(jobRef);
job.setConfiguration(new JobConfiguration().setExtract(extractConfig));
job.setKind(" bigquery#job");
job.setStatus(new JobStatus().setState("PENDING"));
allJobs.put(jobRef.getProjectId(), jobRef.getJobId(), new JobInfo(job));
}
}
示例6: startLoadJob
import com.google.api.services.bigquery.model.Job; //导入方法依赖的package包/类
@Override
public void startLoadJob(JobReference jobRef, JobConfigurationLoad loadConfig)
throws InterruptedException, IOException {
synchronized (allJobs) {
verifyUniqueJobId(jobRef.getJobId());
Job job = new Job();
job.setJobReference(jobRef);
job.setConfiguration(new JobConfiguration().setLoad(loadConfig));
job.setKind(" bigquery#job");
job.setStatus(new JobStatus().setState("PENDING"));
// Copy the files to a new location for import, as the temporary files will be deleted by
// the caller.
if (loadConfig.getSourceUris().size() > 0) {
ImmutableList.Builder<ResourceId> sourceFiles = ImmutableList.builder();
ImmutableList.Builder<ResourceId> loadFiles = ImmutableList.builder();
for (String filename : loadConfig.getSourceUris()) {
sourceFiles.add(FileSystems.matchNewResource(filename, false /* isDirectory */));
loadFiles.add(FileSystems.matchNewResource(
filename + ThreadLocalRandom.current().nextInt(), false /* isDirectory */));
}
FileSystems.copy(sourceFiles.build(), loadFiles.build());
filesForLoadJobs.put(jobRef.getProjectId(), jobRef.getJobId(), loadFiles.build());
}
allJobs.put(jobRef.getProjectId(), jobRef.getJobId(), new JobInfo(job));
}
}
示例7: startQueryJob
import com.google.api.services.bigquery.model.Job; //导入方法依赖的package包/类
@Override
public void startQueryJob(JobReference jobRef, JobConfigurationQuery query)
throws IOException, InterruptedException {
synchronized (allJobs) {
Job job = new Job();
job.setJobReference(jobRef);
job.setConfiguration(new JobConfiguration().setQuery(query));
job.setKind(" bigquery#job");
job.setStatus(new JobStatus().setState("PENDING"));
allJobs.put(jobRef.getProjectId(), jobRef.getJobId(), new JobInfo(job));
}
}
示例8: startCopyJob
import com.google.api.services.bigquery.model.Job; //导入方法依赖的package包/类
@Override
public void startCopyJob(JobReference jobRef, JobConfigurationTableCopy copyConfig)
throws IOException, InterruptedException {
synchronized (allJobs) {
verifyUniqueJobId(jobRef.getJobId());
Job job = new Job();
job.setJobReference(jobRef);
job.setConfiguration(new JobConfiguration().setCopy(copyConfig));
job.setKind(" bigquery#job");
job.setStatus(new JobStatus().setState("PENDING"));
allJobs.put(jobRef.getProjectId(), jobRef.getJobId(), new JobInfo(job));
}
}
示例9: testCommitTaskError
import com.google.api.services.bigquery.model.Job; //导入方法依赖的package包/类
/**
* Tests the commitTask method of BigQueryOutputFormat with error set in JobStatus.
*/
@Test
public void testCommitTaskError()
throws IOException {
// Create the job result to return.
Job job = new Job();
JobStatus jobStatus = new JobStatus();
jobStatus.setState("DONE");
jobStatus.setErrorResult(null);
job.setStatus(jobStatus);
job.setJobReference(jobReference);
// Mock the return of the commit task method calls.
when(mockBigqueryJobsGet.execute()).thenReturn(job);
when(mockTaskAttemptContext.getTaskAttemptID())
.thenReturn(fakeTaskId);
when(mockBigQueryHelper.createJobReference(any(String.class), any(String.class)))
.thenReturn(jobReference);
when(mockBigQueryHelper.insertJobOrFetchDuplicate(any(String.class), any(Job.class)))
.thenReturn(job);
// Run method and verify calls.
committerInstance.commitTask(mockTaskAttemptContext);
verify(mockBigquery, times(1)).jobs();
verify(mockBigQueryHelper).insertJobOrFetchDuplicate(eq(JOB_PROJECT_ID), any(Job.class));
verify(mockBigqueryJobs).get(JOB_PROJECT_ID, jobReference.getJobId());
verify(mockBigqueryJobsGet).execute();
verify(mockBigQueryHelper, atLeastOnce()).getRawBigquery();
verify(mockTaskAttemptContext, atLeastOnce()).getTaskAttemptID();
verify(mockBigQueryHelper).createJobReference(
eq(JOB_PROJECT_ID), eq(fakeTaskId.toString()));
}
示例10: setUp
import com.google.api.services.bigquery.model.Job; //导入方法依赖的package包/类
/**
* Mocks result of BigQuery for polling for job completion.
*
* @throws IOException on IOError.
*/
@Before
public void setUp()
throws IOException {
// Set mock JobReference
mockJobReference = new JobReference();
// Create the unfinished job result.
notDoneJob = new Job();
notDoneJobStatus = new JobStatus();
notDoneJobStatus.setState("NOT DONE");
notDoneJobStatus.setErrorResult(null);
notDoneJob.setStatus(notDoneJobStatus);
notDoneJob.setJobReference(mockJobReference);
// Create the finished job result.
job = new Job();
jobStatus = new JobStatus();
jobStatus.setState("DONE");
jobStatus.setErrorResult(null);
job.setStatus(jobStatus);
job.setJobReference(mockJobReference);
// Mock BigQuery.
mockBigQuery = mock(Bigquery.class);
mockBigQueryJobs = mock(Bigquery.Jobs.class);
mockJobsGet = mock(Bigquery.Jobs.Get.class);
when(mockBigQuery.jobs()).thenReturn(mockBigQueryJobs);
when(mockBigQueryJobs.get(projectId, mockJobReference.getJobId()))
.thenReturn(mockJobsGet).thenReturn(mockJobsGet);
when(mockJobsGet.execute()).thenReturn(job);
// Constructor coverage
BigQueryUtils bigQueryUtils = new BigQueryUtils();
// Mock Progressable.
mockProgressable = mock(Progressable.class);
}
示例11: setUp
import com.google.api.services.bigquery.model.Job; //导入方法依赖的package包/类
@Before
public void setUp() throws IOException, GeneralSecurityException {
// Generate Mocks.
MockitoAnnotations.initMocks(this);
// Create Gson to parse Json.
gson = new Gson();
// Calls the .run/.call method on the future when the future is first accessed.
executorService = Executors.newCachedThreadPool();
// Set input parameters for testing.
fields = BigQueryUtils.getSchemaFromString(
"[{'name': 'Name','type': 'STRING'},{'name': 'Number','type': 'INTEGER'}]");
jobProjectId = "test_job_project";
outputProjectId = "test_output_project";
tableId = "test_table";
datasetId = "test_dataset";
taskIdentifier = "attempt_201501292132_0016_r_000033_0";
// Create the key, value pair.
bigqueryKey = new LongWritable(123);
jsonValue = new JsonObject();
jsonValue.addProperty("Name", "test name");
jsonValue.addProperty("Number", "123");
// Create the job result.
jobReference = new JobReference();
jobReference.setProjectId(jobProjectId);
jobReference.setJobId(taskIdentifier + "-12345");
jobStatus = new JobStatus();
jobStatus.setState("DONE");
jobStatus.setErrorResult(null);
jobReturn = new Job();
jobReturn.setStatus(jobStatus);
jobReturn.setJobReference(jobReference);
// Mock BigQuery.
when(mockFactory.getBigQueryHelper(any(Configuration.class))).thenReturn(mockBigQueryHelper);
when(mockBigQueryHelper.getRawBigquery()).thenReturn(mockBigQuery);
when(mockBigQuery.jobs()).thenReturn(mockBigQueryJobs);
when(mockBigQueryJobs.get(any(String.class), any(String.class)))
.thenReturn(mockJobsGet);
when(mockJobsGet.execute()).thenReturn(jobReturn);
when(mockBigQueryJobs.insert(
any(String.class), any(Job.class), any(ByteArrayContent.class)))
.thenReturn(mockInsert);
when(mockInsert.setProjectId(any(String.class))).thenReturn(mockInsert);
when(mockClientRequestHelper.getRequestHeaders(any(Insert.class)))
.thenReturn(mockHeaders);
// Mock context result
when(mockContext.getConfiguration()).thenReturn(
CredentialConfigurationUtil.getTestConfiguration());
}
示例12: testCommitTask
import com.google.api.services.bigquery.model.Job; //导入方法依赖的package包/类
/**
* Tests the commitTask method of BigQueryOutputFormat.
*/
@Test
public void testCommitTask()
throws IOException {
// Create the job result to return.
Job job = new Job();
JobStatus jobStatus = new JobStatus();
jobStatus.setState("DONE");
jobStatus.setErrorResult(null);
job.setStatus(jobStatus);
job.setJobReference(jobReference);
// Mock the return of the commit task method calls.
when(mockBigqueryJobsGet.execute()).thenReturn(job);
when(mockTaskAttemptContext.getTaskAttemptID())
.thenReturn(fakeTaskId);
when(mockBigQueryHelper.createJobReference(any(String.class), any(String.class)))
.thenReturn(jobReference);
when(mockBigQueryHelper.insertJobOrFetchDuplicate(any(String.class), any(Job.class)))
.thenReturn(job);
// Run method and verify calls.
committerInstance.commitTask(mockTaskAttemptContext);
verify(mockBigquery, times(1)).jobs();
// Verify the contents of the Job.
ArgumentCaptor<Job> jobCaptor = ArgumentCaptor.forClass(Job.class);
verify(mockBigQueryHelper).insertJobOrFetchDuplicate(eq(JOB_PROJECT_ID), jobCaptor.capture());
Job capturedJob = jobCaptor.getValue();
assertEquals(tempTableRef, capturedJob.getConfiguration().getCopy().getSourceTable());
assertEquals(finalTableRef, capturedJob.getConfiguration().getCopy().getDestinationTable());
verify(mockBigqueryJobs).get(JOB_PROJECT_ID, jobReference.getJobId());
verify(mockBigqueryJobsGet).execute();
verify(mockBigQueryHelper, atLeastOnce()).getRawBigquery();
verify(mockTaskAttemptContext, atLeastOnce()).getTaskAttemptID();
verify(mockBigQueryHelper).createJobReference(
eq(JOB_PROJECT_ID), eq(fakeTaskId.toString()));
}
示例13: setUp
import com.google.api.services.bigquery.model.Job; //导入方法依赖的package包/类
@Before
public void setUp() throws IOException {
MockitoAnnotations.initMocks(this);
Logger.getLogger(GsonBigQueryInputFormat.class).setLevel(Level.DEBUG);
// Create fake job reference.
JobReference fakeJobReference = new JobReference();
fakeJobReference.setProjectId(jobProjectId);
fakeJobReference.setJobId(jobId);
// Create the job result.
jobStatus = new JobStatus();
jobStatus.setState("DONE");
jobStatus.setErrorResult(null);
jobHandle = new Job();
jobHandle.setStatus(jobStatus);
jobHandle.setJobReference(fakeJobReference);
// Mocks for Bigquery jobs.
when(mockBigquery.jobs()).thenReturn(mockBigqueryJobs);
// Mock getting Bigquery job.
when(mockBigqueryJobs.get(any(String.class), any(String.class)))
.thenReturn(mockBigqueryJobsGet);
// Mock inserting Bigquery job.
when(mockBigqueryJobs.insert(any(String.class), any(Job.class)))
.thenReturn(mockBigqueryJobsInsert);
// Fake table.
fakeTableSchema = new TableSchema();
fakeTable = new Table().setSchema(fakeTableSchema);
// Mocks for Bigquery tables.
when(mockBigquery.tables()).thenReturn(mockBigqueryTables);
// Mocks for getting Bigquery table.
when(mockBigqueryTables.get(any(String.class), any(String.class), any(String.class)))
.thenReturn(mockBigqueryTablesGet);
// Create table reference.
tableRef = new TableReference();
tableRef.setProjectId(projectId);
tableRef.setDatasetId(datasetId);
tableRef.setTableId(tableId);
helper = new BigQueryHelper(mockBigquery);
helper.setErrorExtractor(mockErrorExtractor);
}