@Override public void run(Compute compute, ZoneId zone) { for (Disk disk : compute.listDisks().iterateAll()) { System.out.println(disk); } } }
@Test public void testAggregatedListEmptyDisks() { compute = options.getService(); ImmutableList<com.google.api.services.compute.model.Disk> diskList = ImmutableList.of(); Tuple<String, Iterable<com.google.api.services.compute.model.Disk>> result = Tuple.<String, Iterable<com.google.api.services.compute.model.Disk>>of(null, diskList); EasyMock.expect(computeRpcMock.listDisks(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.replay(computeRpcMock); Page<Disk> page = compute.listDisks(); assertNull(page.getNextPageToken()); assertArrayEquals(diskList.toArray(), Iterables.toArray(page.getValues(), Disk.class)); }
@Test public void testListEmptyDisks() { compute = options.getService(); ImmutableList<com.google.api.services.compute.model.Disk> disks = ImmutableList.of(); Tuple<String, Iterable<com.google.api.services.compute.model.Disk>> result = Tuple.<String, Iterable<com.google.api.services.compute.model.Disk>>of(null, disks); EasyMock.expect(computeRpcMock.listDisks(DISK_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); Page<Disk> page = compute.listDisks(DISK_ID.getZone()); assertNull(page.getNextPageToken()); assertArrayEquals(disks.toArray(), Iterables.toArray(page.getValues(), Disk.class)); }
@Test public void testAggregatedListDisks() { String cursor = "cursor"; compute = options.getService(); ImmutableList<Disk> diskList = ImmutableList.of( new Disk(compute, new DiskInfo.BuilderImpl(DISK)), new Disk(compute, new DiskInfo.BuilderImpl(DISK))); Tuple<String, Iterable<com.google.api.services.compute.model.Disk>> result = Tuple.of(cursor, Iterables.transform(diskList, DiskInfo.TO_PB_FUNCTION)); EasyMock.expect(computeRpcMock.listDisks(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.replay(computeRpcMock); Page<Disk> page = compute.listDisks(); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(diskList.toArray(), Iterables.toArray(page.getValues(), Disk.class)); }
@Test public void testListDisks() { String cursor = "cursor"; compute = options.getService(); ImmutableList<Disk> diskList = ImmutableList.of( new Disk(compute, new DiskInfo.BuilderImpl(DISK)), new Disk(compute, new DiskInfo.BuilderImpl(DISK))); Tuple<String, Iterable<com.google.api.services.compute.model.Disk>> result = Tuple.of(cursor, Iterables.transform(diskList, DiskInfo.TO_PB_FUNCTION)); EasyMock.expect(computeRpcMock.listDisks(DISK_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); Page<Disk> page = compute.listDisks(DISK_ID.getZone()); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(diskList.toArray(), Iterables.toArray(page.getValues(), Disk.class)); }
@Test public void testAggregatedListDisksWithOptions() { String cursor = "cursor"; compute = options.getService(); ImmutableList<Disk> diskList = ImmutableList.of( new Disk(compute, new DiskInfo.BuilderImpl(DISK)), new Disk(compute, new DiskInfo.BuilderImpl(DISK))); Tuple<String, Iterable<com.google.api.services.compute.model.Disk>> result = Tuple.of(cursor, Iterables.transform(diskList, DiskInfo.TO_PB_FUNCTION)); EasyMock.expect(computeRpcMock.listDisks(DISK_LIST_OPTIONS)).andReturn(result); EasyMock.replay(computeRpcMock); Page<Disk> page = compute.listDisks( DISK_AGGREGATED_LIST_PAGE_SIZE, DISK_AGGREGATED_LIST_PAGE_TOKEN, DISK_AGGREGATED_LIST_FILTER); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(diskList.toArray(), Iterables.toArray(page.getValues(), Disk.class)); }
@Test public void testListDisksWithOptions() { String cursor = "cursor"; compute = options.getService(); ImmutableList<Disk> diskList = ImmutableList.of( new Disk(compute, new DiskInfo.BuilderImpl(DISK)), new Disk(compute, new DiskInfo.BuilderImpl(DISK))); Tuple<String, Iterable<com.google.api.services.compute.model.Disk>> result = Tuple.of(cursor, Iterables.transform(diskList, DiskInfo.TO_PB_FUNCTION)); EasyMock.expect(computeRpcMock.listDisks(DISK_ID.getZone(), DISK_LIST_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); Page<Disk> page = compute.listDisks( DISK_ID.getZone(), DISK_LIST_PAGE_SIZE, DISK_LIST_PAGE_TOKEN, DISK_LIST_FILTER); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(diskList.toArray(), Iterables.toArray(page.getValues(), Disk.class)); }
@Test public void testAggregatedListDisksNextPage() { String cursor = "cursor"; String nextCursor = "nextCursor"; compute = options.getService(); ImmutableList<Disk> diskList = ImmutableList.of( new Disk(compute, new DiskInfo.BuilderImpl(DISK)), new Disk(compute, new DiskInfo.BuilderImpl(DISK))); ImmutableList<Disk> nextDiskList = ImmutableList.of(new Disk(compute, new DiskInfo.BuilderImpl(DISK))); Tuple<String, Iterable<com.google.api.services.compute.model.Disk>> result = Tuple.of(cursor, Iterables.transform(diskList, DiskInfo.TO_PB_FUNCTION)); Tuple<String, Iterable<com.google.api.services.compute.model.Disk>> nextResult = Tuple.of(nextCursor, Iterables.transform(nextDiskList, DiskInfo.TO_PB_FUNCTION)); Map<ComputeRpc.Option, ?> nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); EasyMock.expect(computeRpcMock.listDisks(EMPTY_RPC_OPTIONS)).andReturn(result); EasyMock.expect(computeRpcMock.listDisks(nextOptions)).andReturn(nextResult); EasyMock.replay(computeRpcMock); Page<Disk> page = compute.listDisks(); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(diskList.toArray(), Iterables.toArray(page.getValues(), Disk.class)); page = page.getNextPage(); assertEquals(nextCursor, page.getNextPageToken()); assertArrayEquals(nextDiskList.toArray(), Iterables.toArray(page.getValues(), Disk.class)); }
@Test public void testListDisksNextPage() { String cursor = "cursor"; String nextCursor = "nextCursor"; compute = options.getService(); ImmutableList<Disk> diskList = ImmutableList.of( new Disk(compute, new DiskInfo.BuilderImpl(DISK)), new Disk(compute, new DiskInfo.BuilderImpl(DISK))); ImmutableList<Disk> nextDiskList = ImmutableList.of(new Disk(compute, new DiskInfo.BuilderImpl(DISK))); Tuple<String, Iterable<com.google.api.services.compute.model.Disk>> result = Tuple.of(cursor, Iterables.transform(diskList, DiskInfo.TO_PB_FUNCTION)); Tuple<String, Iterable<com.google.api.services.compute.model.Disk>> nextResult = Tuple.of(nextCursor, Iterables.transform(nextDiskList, DiskInfo.TO_PB_FUNCTION)); Map<ComputeRpc.Option, ?> nextOptions = ImmutableMap.of(ComputeRpc.Option.PAGE_TOKEN, cursor); EasyMock.expect(computeRpcMock.listDisks(DISK_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.expect(computeRpcMock.listDisks(DISK_ID.getZone(), nextOptions)).andReturn(nextResult); EasyMock.replay(computeRpcMock); Page<Disk> page = compute.listDisks(DISK_ID.getZone()); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(diskList.toArray(), Iterables.toArray(page.getValues(), Disk.class)); page = page.getNextPage(); assertEquals(nextCursor, page.getNextPageToken()); assertArrayEquals(nextDiskList.toArray(), Iterables.toArray(page.getValues(), Disk.class)); }
Compute.DiskFilter diskFilter = Compute.DiskFilter.equals(Compute.DiskField.NAME, prefix + "\\d"); Page<Disk> diskPage = compute.listDisks(Compute.DiskAggregatedListOption.filter(diskFilter)); Iterator<Disk> diskIterator = diskPage.iterateAll().iterator(); int count = 0;