/** An empty {@code TableResult} to avoid making API requests to unlistable tables. */ @InternalApi("Exposed for testing") public EmptyTableResult() { super(null, 0, new PageImpl<FieldValueList>(null, "", null)); } }
ChangeRequestPageFetcher( String zoneName, DnsOptions serviceOptions, String cursor, Map<DnsRpc.Option, ?> optionMap) { this.zoneName = zoneName; this.requestOptions = PageImpl.nextRequestOptions(DnsRpc.Option.PAGE_TOKEN, cursor, optionMap); this.serviceOptions = serviceOptions; }
@Override public boolean hasNextPage() { return getNextPageToken() != null && !getNextPageToken().equals(""); }
@Test public void testList() throws Exception { initializeExpectedBucket(4); PageImpl<Blob> expectedBlobPage = new PageImpl<>(null, "c", blobResults); expect(storage.getOptions()).andReturn(mockOptions); expect(storage.list(BUCKET_INFO.getName())).andReturn(expectedBlobPage); replay(storage); initializeBucket(); Page<Blob> blobPage = bucket.list(); Iterator<Blob> blobInfoIterator = blobPage.getValues().iterator(); Iterator<Blob> blobIterator = blobPage.getValues().iterator(); while (blobInfoIterator.hasNext() && blobIterator.hasNext()) { assertEquals(blobInfoIterator.next(), blobIterator.next()); } assertFalse(blobInfoIterator.hasNext()); assertFalse(blobIterator.hasNext()); assertEquals(expectedBlobPage.getNextPageToken(), blobPage.getNextPageToken()); }
@Test public void testPage() { final PageImpl<String> nextResult = new PageImpl<>(null, "c", NEXT_VALUES); PageImpl.NextPageFetcher<String> fetcher = new TestPageFetcher(nextResult); PageImpl<String> result = new PageImpl<>(fetcher, "c", VALUES); assertEquals(nextResult, result.getNextPage()); assertEquals("c", result.getNextPageToken()); assertEquals(VALUES, result.getValues()); }
@Test public void testIterateAll() { final PageImpl<String> nextResult = new PageImpl<>(null, "c", NEXT_VALUES); PageImpl.NextPageFetcher<String> fetcher = new TestPageFetcher(nextResult); PageImpl<String> result = new PageImpl<>(fetcher, "c", VALUES); assertEquals(ALL_VALUES, ImmutableList.copyOf(result.iterateAll())); } }
@Test public void testList() throws Exception { initializeExpectedDataset(4); List<Table> tableResults = ImmutableList.of( new Table(serviceMockReturnsOptions, new Table.BuilderImpl(TABLE_INFO1)), new Table(serviceMockReturnsOptions, new Table.BuilderImpl(TABLE_INFO2)), new Table(serviceMockReturnsOptions, new Table.BuilderImpl(TABLE_INFO3))); PageImpl<Table> expectedPage = new PageImpl<>(null, "c", tableResults); expect(bigquery.getOptions()).andReturn(mockOptions); expect(bigquery.listTables(DATASET_INFO.getDatasetId())).andReturn(expectedPage); replay(bigquery); initializeDataset(); Page<Table> tablePage = dataset.list(); assertArrayEquals( tableResults.toArray(), Iterables.toArray(tablePage.getValues(), Table.class)); assertEquals(expectedPage.getNextPageToken(), tablePage.getNextPageToken()); }
@Override public Page<S> getNextPage() { Paginated<T> nextPage = runWithRetries( new Callable<Paginated<T>>() { @Override public Paginated<T> call() { return getNextPage(nextPageToken); } }); this.nextPageToken = nextPage.getNextPageToken(); List<S> results = new ArrayList<>(); for (T proto : nextPage.getResults()) { results.add(fromProto(proto)); } return new PageImpl<S>(this, nextPageToken, results); }
DiskTypePageFetcher( String zone, ComputeOptions serviceOptions, String cursor, Map<ComputeRpc.Option, ?> optionMap) { this.requestOptions = PageImpl.nextRequestOptions(ComputeRpc.Option.PAGE_TOKEN, cursor, optionMap); this.serviceOptions = serviceOptions; this.zone = zone; }
@Test public void testListWithOptions() throws Exception { initializeExpectedDataset(4); List<Table> tableResults = ImmutableList.of( new Table(serviceMockReturnsOptions, new Table.BuilderImpl(TABLE_INFO1)), new Table(serviceMockReturnsOptions, new Table.BuilderImpl(TABLE_INFO2)), new Table(serviceMockReturnsOptions, new Table.BuilderImpl(TABLE_INFO3))); PageImpl<Table> expectedPage = new PageImpl<>(null, "c", tableResults); expect(bigquery.getOptions()).andReturn(mockOptions); expect(bigquery.listTables(DATASET_INFO.getDatasetId(), BigQuery.TableListOption.pageSize(10L))) .andReturn(expectedPage); replay(bigquery); initializeDataset(); Page<Table> tablePage = dataset.list(BigQuery.TableListOption.pageSize(10L)); assertArrayEquals( tableResults.toArray(), Iterables.toArray(tablePage.getValues(), Table.class)); assertEquals(expectedPage.getNextPageToken(), tablePage.getNextPageToken()); }
@Override public boolean hasNextPage() { return getNextPageToken() != null && !getNextPageToken().equals(""); }
private static Page<Job> listJobs( final BigQueryOptions serviceOptions, final Map<BigQueryRpc.Option, ?> optionsMap) { Tuple<String, Iterable<com.google.api.services.bigquery.model.Job>> result = runWithRetries( new Callable<Tuple<String, Iterable<com.google.api.services.bigquery.model.Job>>>() { @Override public Tuple<String, Iterable<com.google.api.services.bigquery.model.Job>> call() { return serviceOptions .getBigQueryRpcV2() .listJobs(serviceOptions.getProjectId(), optionsMap); } }, serviceOptions.getRetrySettings(), EXCEPTION_HANDLER, serviceOptions.getClock()); String cursor = result.x(); Iterable<Job> jobs = Iterables.transform( result.y(), new Function<com.google.api.services.bigquery.model.Job, Job>() { @Override public Job apply(com.google.api.services.bigquery.model.Job job) { return Job.fromPb(serviceOptions.getService(), job); } }); return new PageImpl<>(new JobPageFetcher(serviceOptions, cursor, optionsMap), cursor, jobs); }
ZonePageFetcher( ComputeOptions serviceOptions, String cursor, Map<ComputeRpc.Option, ?> optionMap) { this.requestOptions = PageImpl.nextRequestOptions(ComputeRpc.Option.PAGE_TOKEN, cursor, optionMap); this.serviceOptions = serviceOptions; }
return new PageImpl<>(new ZonePageFetcher(serviceOptions, cursor, optionsMap), cursor, zones); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e);
ImagePageFetcher( String project, ComputeOptions serviceOptions, String cursor, Map<ComputeRpc.Option, ?> optionMap) { this.requestOptions = PageImpl.nextRequestOptions(ComputeRpc.Option.PAGE_TOKEN, cursor, optionMap); this.serviceOptions = serviceOptions; this.project = project; }
return new PageImpl<>( new BucketPageFetcher(serviceOptions, cursor, optionsMap), cursor, buckets); } catch (RetryHelperException e) {
DiskPageFetcher( String zone, ComputeOptions serviceOptions, String cursor, Map<ComputeRpc.Option, ?> optionMap) { this.requestOptions = PageImpl.nextRequestOptions(ComputeRpc.Option.PAGE_TOKEN, cursor, optionMap); this.serviceOptions = serviceOptions; this.zone = zone; }
return new PageImpl<>( new SnapshotPageFetcher(serviceOptions, cursor, optionsMap), cursor, snapshots); } catch (RetryHelper.RetryHelperException e) {
AggregatedSubnetworkPageFetcher( ComputeOptions serviceOptions, String cursor, Map<ComputeRpc.Option, ?> optionMap) { this.requestOptions = PageImpl.nextRequestOptions(ComputeRpc.Option.PAGE_TOKEN, cursor, optionMap); this.serviceOptions = serviceOptions; }
private static Page<Disk> listDisks( final ComputeOptions serviceOptions, final Map<ComputeRpc.Option, ?> optionsMap) { try { Tuple<String, Iterable<com.google.api.services.compute.model.Disk>> result = runWithRetries( new Callable<Tuple<String, Iterable<com.google.api.services.compute.model.Disk>>>() { @Override public Tuple<String, Iterable<com.google.api.services.compute.model.Disk>> call() { return serviceOptions.getComputeRpcV1().listDisks(optionsMap); } }, serviceOptions.getRetrySettings(), EXCEPTION_HANDLER, serviceOptions.getClock()); String cursor = result.x(); Iterable<Disk> disks = Iterables.transform( result.y() == null ? ImmutableList.<com.google.api.services.compute.model.Disk>of() : result.y(), diskFromPb(serviceOptions)); return new PageImpl<>( new AggregatedDiskPageFetcher(serviceOptions, cursor, optionsMap), cursor, disks); } catch (RetryHelper.RetryHelperException e) { throw ComputeException.translateAndThrow(e); } }