Refine search
@Test public void testOf() { DiskTypeId diskTypeId = DiskTypeId.of(PROJECT, ZONE, DISK_TYPE); assertEquals(PROJECT, diskTypeId.getProject()); assertEquals(ZONE, diskTypeId.getZone()); assertEquals(DISK_TYPE, diskTypeId.getType()); assertEquals(URL, diskTypeId.getSelfLink()); diskTypeId = DiskTypeId.of(ZONE, DISK_TYPE); assertNull(diskTypeId.getProject()); assertEquals(ZONE, diskTypeId.getZone()); assertEquals(DISK_TYPE, diskTypeId.getType()); }
@Test public void testToAndFromUrl() { DiskTypeId diskTypeId = DiskTypeId.of(PROJECT, ZONE, DISK_TYPE); assertSame(diskTypeId, diskTypeId.setProjectId(PROJECT)); compareDiskTypeId(diskTypeId, DiskTypeId.fromUrl(diskTypeId.getSelfLink())); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("notMatchingUrl is not a valid disk type URL"); DiskTypeId.fromUrl("notMatchingUrl"); }
/** Returns a disk type identity given the zone identity and the disk type name. */ public static DiskTypeId of(ZoneId zoneId, String type) { return new DiskTypeId(zoneId.getProject(), zoneId.getZone(), type); }
@Override DiskTypeId setProjectId(String projectId) { if (getProject() != null) { return this; } return DiskTypeId.of(projectId, zone, type); }
@Override ScratchDiskConfiguration setProjectId(String projectId) { if (diskType.getProject() != null) { return this; } return toBuilder().setDiskType(diskType.setProjectId(projectId)).build(); }
DiskId diskId = DiskId.of(ZONE, name); DiskInfo diskInfo = DiskInfo.of(diskId, StandardDiskConfiguration.of(DiskTypeId.of(ZONE, "pd-ssd"), 100L)); Operation operation = compute.create(diskInfo); operation.waitFor(); Disk remoteDisk = compute.getDisk(diskId); resourceCleaner.add(diskId); assertNotNull(remoteDisk); StandardDiskConfiguration remoteConfiguration = remoteDisk.getConfiguration(); assertEquals(100L, (long) remoteConfiguration.getSizeGb()); assertEquals("pd-ssd", remoteConfiguration.getDiskType().getType()); assertEquals(DiskConfiguration.Type.STANDARD, remoteConfiguration.getType()); assertNull(remoteDisk.getLastAttachTimestamp()); operation.waitFor(); remoteDisk = compute.getDisk(diskId, Compute.DiskOption.fields(Compute.DiskField.SIZE_GB)); assertNotNull(remoteDisk); assertEquals(ZONE, remoteDisk.getDiskId().getZone()); remoteConfiguration = remoteDisk.getConfiguration(); assertEquals(200L, (long) remoteConfiguration.getSizeGb()); assertEquals("pd-ssd", remoteConfiguration.getDiskType().getType()); assertEquals(DiskConfiguration.Type.STANDARD, remoteConfiguration.getType()); assertNull(remoteDisk.getLastAttachTimestamp());
@Test public void testGetDiskType_Null() { EasyMock.expect( computeRpcMock.getDiskType( DISK_TYPE_ID.getZone(), DISK_TYPE_ID.getType(), EMPTY_RPC_OPTIONS)) .andReturn(null); EasyMock.replay(computeRpcMock); compute = options.getService(); assertNull(compute.getDiskType(DISK_TYPE_ID.getZone(), DISK_TYPE_ID.getType())); }
DiskId secondDiskId = DiskId.of(diskZones[1], diskNames[1]); DiskConfiguration configuration = StandardDiskConfiguration.of(DiskTypeId.of(ZONE, "pd-ssd"), 100L); Operation firstOperation = compute.create(DiskInfo.of(firstDiskId, configuration)); Operation secondOperation = compute.create(DiskInfo.of(secondDiskId, configuration)); firstOperation.waitFor(); resourceCleaner.add(firstDiskId); 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; StandardDiskConfiguration remoteConfiguration = remoteDisk.getConfiguration(); assertEquals(100L, (long) remoteConfiguration.getSizeGb()); assertEquals("pd-ssd", remoteConfiguration.getDiskType().getType()); assertEquals(DiskConfiguration.Type.STANDARD, remoteConfiguration.getType()); count++;
ImageId imageId = ImageId.of(imageName); DiskInfo diskInfo = DiskInfo.of(diskId, StandardDiskConfiguration.of(DiskTypeId.of(ZONE, "pd-ssd"), 100L)); Operation operation = compute.create(diskInfo); operation.waitFor(); Disk remoteDisk = compute.getDisk(diskId); ImageInfo imageInfo = ImageInfo.of(imageId, DiskImageConfiguration.of(diskId)); operation = compute.create(imageInfo); operation.waitFor(); resourceCleaner.add(diskId);
Operation operation = compute.create(addressInfo); operation.waitFor(); Address address = compute.getAddress(addressId); resourceCleaner.add(addressId); AttachedDisk disk2 = AttachedDisk.of( "dev1", AttachedDisk.ScratchDiskConfiguration.of(DiskTypeId.of(ZONE, DISK_TYPE))); InstanceInfo instanceInfo = InstanceInfo.newBuilder(instanceId, MachineTypeId.of(ZONE, "n1-standard-1")) .setNetworkInterfaces(networkInterface) .build(); operation = compute.create(instanceInfo); operation.waitFor();
@Test public void testListDiskTypes() { String cursor = "cursor"; compute = options.getService(); ImmutableList<DiskType> diskTypeList = ImmutableList.of(DISK_TYPE, DISK_TYPE); Tuple<String, Iterable<com.google.api.services.compute.model.DiskType>> result = Tuple.of(cursor, Iterables.transform(diskTypeList, DiskType.TO_PB_FUNCTION)); EasyMock.expect(computeRpcMock.listDiskTypes(DISK_TYPE_ID.getZone(), EMPTY_RPC_OPTIONS)) .andReturn(result); EasyMock.replay(computeRpcMock); Page<DiskType> page = compute.listDiskTypes(DISK_TYPE_ID.getZone()); assertEquals(cursor, page.getNextPageToken()); assertArrayEquals(diskTypeList.toArray(), Iterables.toArray(page.getValues(), DiskType.class)); }
private void compareDiskTypeId(DiskTypeId expected, DiskTypeId value) { assertEquals(expected, value); assertEquals(expected.getProject(), expected.getProject()); assertEquals(expected.getZone(), expected.getZone()); assertEquals(expected.getType(), expected.getType()); assertEquals(expected.getSelfLink(), expected.getSelfLink()); assertEquals(expected.hashCode(), expected.hashCode()); } }
.setNetworkInterfaces(networkInterface) .build(); Operation instanceOperation = compute.create(instanceInfo); DiskId diskId = DiskId.of(ZONE, diskName); Operation diskOperation = compute.create( DiskInfo.of(diskId, StandardDiskConfiguration.of(DiskTypeId.of(ZONE, "pd-ssd")))); instanceOperation.waitFor(); diskOperation.waitFor(); resourceCleaner.add(diskId); Instance remoteInstance = compute.getInstance(instanceId);
@Override DiskTypeId parse(String... args) throws Exception { String message; if (args.length == 2) { return DiskTypeId.of(args[0], args[1]); } else if (args.length < 2) { message = "Missing required zone and disk type id."; } else { message = "Too many arguments."; } throw new IllegalArgumentException(message); }
DiskId diskId = DiskId.of(ZONE, name); DiskInfo diskInfo = DiskInfo.of(diskId, ImageDiskConfiguration.of(IMAGE_ID)); Operation operation = compute.create(diskInfo); operation.waitFor(); Disk remoteDisk = compute.getDisk(diskId); resourceCleaner.add(diskId); assertNotNull(remoteDisk); assertEquals(DiskConfiguration.Type.IMAGE, remoteConfiguration.getType()); assertNotNull(remoteConfiguration.getSizeGb()); assertEquals("pd-standard", remoteConfiguration.getDiskType().getType()); assertNull(remoteDisk.getLastAttachTimestamp()); assertNull(remoteDisk.getLastDetachTimestamp()); remoteDisk = compute.getDisk(diskId, Compute.DiskOption.fields()); assertNotNull(remoteDisk); assertEquals(ZONE, remoteDisk.getDiskId().getZone()); assertEquals(DiskConfiguration.Type.IMAGE, remoteConfiguration.getType()); assertNull(remoteConfiguration.getSizeGb()); assertEquals("pd-standard", remoteConfiguration.getDiskType().getType()); assertNull(remoteDisk.getLastAttachTimestamp()); assertNull(remoteDisk.getLastDetachTimestamp());
@Test public void testMatchesUrl() { assertTrue(DiskTypeId.matchesUrl(DiskTypeId.of(PROJECT, ZONE, DISK_TYPE).getSelfLink())); assertFalse(DiskTypeId.matchesUrl("notMatchingUrl")); }
@Test public void testCreateDisk() { EasyMock.expect(computeRpcMock.createDisk(DISK_ID.getZone(), DISK.toPb(), EMPTY_RPC_OPTIONS)) .andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.getService(); DiskId diskId = DiskId.of("zone", "disk"); DiskTypeId diskTypeId = DiskTypeId.of("zone", "diskType"); DiskInfo disk = DISK.toBuilder() .setDiskId(diskId) .setConfiguration(StandardDiskConfiguration.of(diskTypeId)) .build(); Operation operation = compute.create(disk); assertEquals(zoneOperation, operation); }
@Test public void testSetProjectId() { DiskTypeId diskTypeId = DiskTypeId.of(PROJECT, ZONE, DISK_TYPE); assertSame(diskTypeId, diskTypeId.setProjectId(PROJECT)); compareDiskTypeId(diskTypeId, DiskTypeId.of(ZONE, DISK_TYPE).setProjectId(PROJECT)); }