Refine search
@Test public void testExtractDataUris() throws Exception { initializeExpectedTable(2); expect(bigquery.getOptions()).andReturn(mockOptions); Job expectedJob = new Job(serviceMockReturnsOptions, new JobInfo.BuilderImpl(EXTRACT_JOB_INFO)); expect(bigquery.create(EXTRACT_JOB_INFO)).andReturn(expectedJob); replay(bigquery); initializeTable(); Job job = table.extract("CSV", ImmutableList.of("URI")); assertSame(expectedJob, job); }
@Test public void testGetJob() { EasyMock.expect(bigqueryRpcMock.getJob(PROJECT, JOB, null, EMPTY_RPC_OPTIONS)) .andReturn(COMPLETE_COPY_JOB.toPb()); EasyMock.replay(bigqueryRpcMock); bigquery = options.getService(); Job job = bigquery.getJob(JOB); assertEquals(new Job(bigquery, new JobInfo.BuilderImpl(COMPLETE_COPY_JOB)), job); }
@Before public void setUp() { rpcFactoryMock = createMock(BigQueryRpcFactory.class); bigqueryRpcMock = createMock(BigQueryRpc.class); bigqueryFactoryMock = createMock(BigQueryFactory.class); bigqueryMock = createMock(BigQuery.class); expect(bigqueryMock.getOptions()).andReturn(options).anyTimes(); replay(bigqueryMock); job = new Job(bigqueryMock, new JobInfo.BuilderImpl(JOB_INFO)); expect(rpcFactoryMock.create(anyObject(BigQueryOptions.class))).andReturn(bigqueryRpcMock); expect(bigqueryFactoryMock.create(anyObject(BigQueryOptions.class))) .andReturn(bigqueryMock) .anyTimes(); replay(rpcFactoryMock, bigqueryFactoryMock); options = BigQueryOptions.newBuilder() .setProjectId("projectid") .setServiceRpcFactory(rpcFactoryMock) .setServiceFactory(bigqueryFactoryMock) .build(); }
private void initializeExpectedJob(int optionsCalls, JobInfo jobInfo) { expect(serviceMockReturnsOptions.getOptions()).andReturn(mockOptions).times(optionsCalls); replay(serviceMockReturnsOptions); bigquery = createStrictMock(BigQuery.class); expectedJob = new Job(serviceMockReturnsOptions, new JobInfo.BuilderImpl(jobInfo)); }
@Test public void testReload() throws Exception { initializeExpectedJob(4); JobInfo updatedInfo = JOB_INFO.toBuilder().setEtag("etag").build(); Job expectedJob = new Job(serviceMockReturnsOptions, new JobInfo.BuilderImpl(updatedInfo)); expect(bigquery.getOptions()).andReturn(mockOptions); expect(bigquery.getJob(JOB_INFO.getJobId())).andReturn(expectedJob); replay(bigquery); initializeJob(); Job updatedJob = job.reload(); compareJob(expectedJob, updatedJob); }
@Test public void testListJobs() { bigquery = options.getService(); ImmutableList<Job> jobList = ImmutableList.of( new Job(bigquery, new JobInfo.BuilderImpl(COMPLETE_QUERY_JOB)), new Job(bigquery, new JobInfo.BuilderImpl(COMPLETE_LOAD_JOB))); Tuple<String, Iterable<com.google.api.services.bigquery.model.Job>> result = Tuple.of( CURSOR, Iterables.transform( jobList, new Function<Job, com.google.api.services.bigquery.model.Job>() { @Override public com.google.api.services.bigquery.model.Job apply(Job job) { return job.toPb(); } })); EasyMock.expect(bigqueryRpcMock.listJobs(PROJECT, EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.replay(bigqueryRpcMock); Page<Job> page = bigquery.listJobs(); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(jobList.toArray(), Iterables.toArray(page.getValues(), Job.class)); }
@Test public void testCreateJobWithProjectId() { JobInfo jobInfo = JobInfo.newBuilder(QUERY_JOB_CONFIGURATION.setProjectId(OTHER_PROJECT)) .setJobId(JobId.of(OTHER_PROJECT, JOB)) .build(); Capture<Map<BigQueryRpc.Option, Object>> capturedOptions = Capture.newInstance(); EasyMock.expect(bigqueryRpcMock.create(eq(jobInfo.toPb()), capture(capturedOptions))) .andReturn(jobInfo.toPb()); EasyMock.replay(bigqueryRpcMock); BigQueryOptions bigQueryOptions = createBigQueryOptionsForProject(OTHER_PROJECT, rpcFactoryMock); bigquery = bigQueryOptions.getService(); Job job = bigquery.create(jobInfo, JOB_OPTION_FIELDS); assertEquals(new Job(bigquery, new JobInfo.BuilderImpl(jobInfo)), job); String selector = (String) capturedOptions.getValue().get(JOB_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("jobReference")); assertTrue(selector.contains("configuration")); assertTrue(selector.contains("user_email")); assertEquals(37, selector.length()); }
ImmutableList<Job> jobList = ImmutableList.of( new Job(bigquery, new JobInfo.BuilderImpl(COMPLETE_QUERY_JOB)), new Job(bigquery, new JobInfo.BuilderImpl(COMPLETE_LOAD_JOB))); Tuple<String, Iterable<com.google.api.services.bigquery.model.Job>> result = Tuple.of( EasyMock.expect(bigqueryRpcMock.listJobs(eq(PROJECT), capture(capturedOptions))) .andReturn(result); EasyMock.replay(bigqueryRpcMock); Page<Job> page = bigquery.listJobs(JOB_LIST_OPTION_FIELD); assertEquals(CURSOR, page.getNextPageToken()); assertArrayEquals(jobList.toArray(), Iterables.toArray(page.getValues(), Job.class));
static Job fromPb(BigQuery bigquery, com.google.api.services.bigquery.model.Job jobPb) { return new Job(bigquery, new JobInfo.BuilderImpl(jobPb)); } }
Builder(BigQuery bigquery, JobConfiguration configuration) { this.bigquery = bigquery; this.infoBuilder = new JobInfo.BuilderImpl(); this.infoBuilder.setConfiguration(configuration); }
@Override Builder setEtag(String etag) { infoBuilder.setEtag(etag); return this; }
Builder(Job job) { this.bigquery = job.bigquery; this.infoBuilder = new JobInfo.BuilderImpl(job); }
@Override public Builder setConfiguration(JobConfiguration configuration) { infoBuilder.setConfiguration(configuration); return this; }
/** * Returns a builder for a {@code JobInfo} object given the job configuration. Use {@link * CopyJobConfiguration} for a job that copies an existing table. Use {@link * ExtractJobConfiguration} for a job that exports a table to Google Cloud Storage. Use {@link * LoadJobConfiguration} for a job that loads data from Google Cloud Storage into a table. Use * {@link QueryJobConfiguration} for a job that runs a query. */ public static Builder newBuilder(JobConfiguration configuration) { return new BuilderImpl().setConfiguration(configuration); }
static JobInfo fromPb(Job jobPb) { return new BuilderImpl(jobPb).build(); } }
/** Returns a builder for the job object. */ public Builder toBuilder() { return new BuilderImpl(this); }
@Override Builder generatedId(String generatedId) { infoBuilder.generatedId(generatedId); return this; }
Builder(BigQuery bigquery, JobConfiguration configuration) { this.bigquery = bigquery; this.infoBuilder = new JobInfo.BuilderImpl(); this.infoBuilder.setConfiguration(configuration); }
/** * Returns a builder for a {@code JobInfo} object given the job configuration. Use {@link * CopyJobConfiguration} for a job that copies an existing table. Use {@link * ExtractJobConfiguration} for a job that exports a table to Google Cloud Storage. Use {@link * LoadJobConfiguration} for a job that loads data from Google Cloud Storage into a table. Use * {@link QueryJobConfiguration} for a job that runs a query. */ public static Builder newBuilder(JobConfiguration configuration) { return new BuilderImpl().setConfiguration(configuration); }
static JobInfo fromPb(Job jobPb) { return new BuilderImpl(jobPb).build(); } }