From bf5d90b48f42d98222cb24bb1efe61f21d5f4739 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 5 Apr 2016 11:55:17 +0200 Subject: [PATCH] Fix DiskInfo and configurations javadoc and test issues --- .../gcloud/compute/DiskConfiguration.java | 6 +++--- .../com/google/gcloud/compute/DiskInfo.java | 6 +++--- .../compute/ImageDiskConfiguration.java | 8 ++++---- .../compute/SnapshotDiskConfiguration.java | 12 +++++------ .../compute/StandardDiskConfiguration.java | 10 +++++----- .../google/gcloud/compute/DiskInfoTest.java | 20 +++++++++++++++++++ .../compute/ImageDiskConfigurationTest.java | 2 +- .../SnapshotDiskConfigurationTest.java | 2 +- .../StandardDiskConfigurationTest.java | 12 +++++------ 9 files changed, 49 insertions(+), 29 deletions(-) diff --git a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskConfiguration.java b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskConfiguration.java index 0426417a1402..1c17a9406801 100644 --- a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskConfiguration.java +++ b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskConfiguration.java @@ -24,9 +24,9 @@ import java.util.Objects; /** - * Base class for Google Compute Engine disk configuration. A disk can be used as primary storage + * Base class for Google Compute Engine disk configurations. A disk can be used as primary storage * for your virtual machine instances. Use {@link StandardDiskConfiguration} to create a standard - * disk given disk type and size. Use {@link ImageDiskConfiguration} to create a disk from a Compute + * disk given a disk type and size. Use {@link ImageDiskConfiguration} to create a disk from a Compute * Engine disk image. Use {@link SnapshotDiskConfiguration} to create a disk from a Compute Engine * disk snapshot. * @@ -109,7 +109,7 @@ public B sizeGb(Long sizeGb) { } /** - * Sets the identity of the disk diskType. + * Sets the identity of the disk type. */ public B diskType(DiskTypeId diskType) { this.diskType = diskType; diff --git a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskInfo.java b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskInfo.java index 6610530e6f09..bbcef7e01a2a 100644 --- a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskInfo.java +++ b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskInfo.java @@ -320,7 +320,7 @@ public List licenses() { } /** - * Returns all instances' identities this disk is attached to. + * Returns all the identities of the instances this disk is attached to. */ public List attachedInstances() { return attachedInstances; @@ -380,7 +380,7 @@ public boolean equals(Object obj) { * Returns a builder for a {@code DiskInfo} object given its identity and configuration. Use * {@link StandardDiskConfiguration} to create a simple disk given its type and size. Use * {@link SnapshotDiskConfiguration} to create a disk from a snapshot. Use - * {@link ImageDiskConfiguration} to create a disk form a disk image. + * {@link ImageDiskConfiguration} to create a disk from a disk image. */ public static Builder builder(DiskId diskId, DiskConfiguration configuration) { return new BuilderImpl().diskId(diskId).configuration(configuration); @@ -390,7 +390,7 @@ public static Builder builder(DiskId diskId, DiskConfiguration configuration) { * Returns a {@code DiskInfo} object given its identity and configuration. Use * {@link StandardDiskConfiguration} to create a simple disk given its type and size. Use * {@link SnapshotDiskConfiguration} to create a disk from a snapshot. Use - * {@link ImageDiskConfiguration} to create a disk form a disk image. + * {@link ImageDiskConfiguration} to create a disk from a disk image. */ public static DiskInfo of(DiskId diskId, DiskConfiguration configuration) { return builder(diskId, configuration).build(); diff --git a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/ImageDiskConfiguration.java b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/ImageDiskConfiguration.java index fdf616fd78ca..5eca95f9c545 100644 --- a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/ImageDiskConfiguration.java +++ b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/ImageDiskConfiguration.java @@ -48,10 +48,10 @@ private Builder() { super(Type.IMAGE); } - private Builder(ImageDiskConfiguration imageDiskConfiguration) { - super(Type.IMAGE, imageDiskConfiguration); - this.sourceImage = imageDiskConfiguration.sourceImage; - this.sourceImageId = imageDiskConfiguration.sourceImageId; + private Builder(ImageDiskConfiguration configuration) { + super(Type.IMAGE, configuration); + this.sourceImage = configuration.sourceImage; + this.sourceImageId = configuration.sourceImageId; } private Builder(Disk diskPb) { diff --git a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/SnapshotDiskConfiguration.java b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/SnapshotDiskConfiguration.java index fbe6249e331f..10b108346721 100644 --- a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/SnapshotDiskConfiguration.java +++ b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/SnapshotDiskConfiguration.java @@ -25,7 +25,7 @@ /** * A Google Compute Engine disk configuration to create a disk from a Google Compute Engine - * snaoshot. + * snapshot. * * @see Block Storage */ @@ -49,10 +49,10 @@ private Builder() { super(Type.SNAPSHOT); } - private Builder(SnapshotDiskConfiguration snapshotDiskInfo) { - super(Type.SNAPSHOT, snapshotDiskInfo); - this.sourceSnapshot = snapshotDiskInfo.sourceSnapshot; - this.sourceSnapshotId = snapshotDiskInfo.sourceSnapshotId; + private Builder(SnapshotDiskConfiguration configuration) { + super(Type.SNAPSHOT, configuration); + this.sourceSnapshot = configuration.sourceSnapshot; + this.sourceSnapshotId = configuration.sourceSnapshotId; } private Builder(Disk diskPb) { @@ -147,7 +147,7 @@ Disk toPb() { /** * Returns a builder for a {@code SnapshotDiskConfiguration} object given the snapshot identity. */ - static Builder builder(SnapshotId sourceSnapshot) { + public static Builder builder(SnapshotId sourceSnapshot) { return new Builder().sourceSnapshot(sourceSnapshot); } diff --git a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/StandardDiskConfiguration.java b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/StandardDiskConfiguration.java index 2c6563859bb3..800916988af7 100644 --- a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/StandardDiskConfiguration.java +++ b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/StandardDiskConfiguration.java @@ -21,8 +21,8 @@ import java.util.Objects; /** - * A Google Compute Engine standard persistent disk configuration. Allows to create a disk given its - * type and size. + * A Google Compute Engine standard persistent disk configuration. This class allows users to create + * a disk given its type and size. * * @see Block Storage */ @@ -40,8 +40,8 @@ private Builder() { super(Type.STANDARD); } - private Builder(StandardDiskConfiguration diskInfo) { - super(Type.STANDARD, diskInfo); + private Builder(StandardDiskConfiguration configuration) { + super(Type.STANDARD, configuration); } private Builder(Disk diskPb) { @@ -57,7 +57,7 @@ public StandardDiskConfiguration build() { } } - private StandardDiskConfiguration(StandardDiskConfiguration.Builder builder) { + private StandardDiskConfiguration(Builder builder) { super(builder); } diff --git a/gcloud-java-compute/src/test/java/com/google/gcloud/compute/DiskInfoTest.java b/gcloud-java-compute/src/test/java/com/google/gcloud/compute/DiskInfoTest.java index ba67f9b8c825..1138d8008452 100644 --- a/gcloud-java-compute/src/test/java/com/google/gcloud/compute/DiskInfoTest.java +++ b/gcloud-java-compute/src/test/java/com/google/gcloud/compute/DiskInfoTest.java @@ -71,6 +71,8 @@ public class DiskInfoTest { .description(DESCRIPTION) .licenses(LICENSES) .attachedInstances(ATTACHED_INSTANCES) + .lastAttachTimestamp(LAST_ATTACH_TIMESTAMP) + .lastDetachTimestamp(LAST_DETACH_TIMESTAMP) .build(); private static final DiskInfo SNAPSHOT_DISK_INFO = DiskInfo.builder(DISK_ID, SNAPSHOT_DISK_CONFIGURATION) @@ -119,26 +121,35 @@ public void testToBuilderIncomplete() { @Test public void testBuilder() { assertEquals(ID, DISK_INFO.id()); + assertEquals(DISK_ID, DISK_INFO.diskId()); assertEquals(DISK_CONFIGURATION, DISK_INFO.configuration()); assertEquals(CREATION_TIMESTAMP, DISK_INFO.creationTimestamp()); assertEquals(CREATION_STATUS, DISK_INFO.creationStatus()); assertEquals(DESCRIPTION, DISK_INFO.description()); assertEquals(LICENSES, DISK_INFO.licenses()); assertEquals(ATTACHED_INSTANCES, DISK_INFO.attachedInstances()); + assertEquals(LAST_ATTACH_TIMESTAMP, DISK_INFO.lastAttachTimestamp()); + assertEquals(LAST_DETACH_TIMESTAMP, DISK_INFO.lastDetachTimestamp()); assertEquals(ID, IMAGE_DISK_INFO.id()); + assertEquals(DISK_ID, IMAGE_DISK_INFO.diskId()); assertEquals(IMAGE_DISK_CONFIGURATION, IMAGE_DISK_INFO.configuration()); assertEquals(CREATION_TIMESTAMP, IMAGE_DISK_INFO.creationTimestamp()); assertEquals(CREATION_STATUS, IMAGE_DISK_INFO.creationStatus()); assertEquals(DESCRIPTION, IMAGE_DISK_INFO.description()); assertEquals(LICENSES, IMAGE_DISK_INFO.licenses()); assertEquals(ATTACHED_INSTANCES, IMAGE_DISK_INFO.attachedInstances()); + assertEquals(LAST_ATTACH_TIMESTAMP, IMAGE_DISK_INFO.lastAttachTimestamp()); + assertEquals(LAST_DETACH_TIMESTAMP, IMAGE_DISK_INFO.lastDetachTimestamp()); assertEquals(ID, SNAPSHOT_DISK_INFO.id()); + assertEquals(DISK_ID, SNAPSHOT_DISK_INFO.diskId()); assertEquals(SNAPSHOT_DISK_CONFIGURATION, SNAPSHOT_DISK_INFO.configuration()); assertEquals(CREATION_TIMESTAMP, SNAPSHOT_DISK_INFO.creationTimestamp()); assertEquals(CREATION_STATUS, SNAPSHOT_DISK_INFO.creationStatus()); assertEquals(DESCRIPTION, SNAPSHOT_DISK_INFO.description()); assertEquals(LICENSES, SNAPSHOT_DISK_INFO.licenses()); assertEquals(ATTACHED_INSTANCES, SNAPSHOT_DISK_INFO.attachedInstances()); + assertEquals(LAST_ATTACH_TIMESTAMP, SNAPSHOT_DISK_INFO.lastAttachTimestamp()); + assertEquals(LAST_DETACH_TIMESTAMP, SNAPSHOT_DISK_INFO.lastDetachTimestamp()); } @Test @@ -152,6 +163,8 @@ public void testOf() { assertNull(diskInfo.description()); assertNull(diskInfo.licenses()); assertNull(diskInfo.attachedInstances()); + assertNull(diskInfo.lastAttachTimestamp()); + assertNull(diskInfo.lastDetachTimestamp()); diskInfo = DiskInfo.of(DISK_ID, IMAGE_DISK_CONFIGURATION); assertNull(diskInfo.id()); assertEquals(DISK_ID, diskInfo.diskId()); @@ -161,6 +174,8 @@ public void testOf() { assertNull(diskInfo.description()); assertNull(diskInfo.licenses()); assertNull(diskInfo.attachedInstances()); + assertNull(diskInfo.lastAttachTimestamp()); + assertNull(diskInfo.lastDetachTimestamp()); diskInfo = DiskInfo.of(DISK_ID, SNAPSHOT_DISK_CONFIGURATION); assertNull(diskInfo.id()); assertEquals(DISK_ID, diskInfo.diskId()); @@ -170,6 +185,8 @@ public void testOf() { assertNull(diskInfo.description()); assertNull(diskInfo.licenses()); assertNull(diskInfo.attachedInstances()); + assertNull(diskInfo.lastAttachTimestamp()); + assertNull(diskInfo.lastDetachTimestamp()); } @Test @@ -238,11 +255,14 @@ public void compareDiskInfo(DiskInfo expected, DiskInfo value) { assertEquals(expected, value); assertEquals(expected.configuration(), value.configuration()); assertEquals(expected.id(), value.id()); + assertEquals(expected.diskId(), value.diskId()); assertEquals(expected.creationTimestamp(), value.creationTimestamp()); assertEquals(expected.creationStatus(), value.creationStatus()); assertEquals(expected.description(), value.description()); assertEquals(expected.licenses(), value.licenses()); assertEquals(expected.attachedInstances(), value.attachedInstances()); + assertEquals(expected.lastAttachTimestamp(), value.lastAttachTimestamp()); + assertEquals(expected.lastDetachTimestamp(), value.lastDetachTimestamp()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/gcloud-java-compute/src/test/java/com/google/gcloud/compute/ImageDiskConfigurationTest.java b/gcloud-java-compute/src/test/java/com/google/gcloud/compute/ImageDiskConfigurationTest.java index 4411ee8c358e..f388109db199 100644 --- a/gcloud-java-compute/src/test/java/com/google/gcloud/compute/ImageDiskConfigurationTest.java +++ b/gcloud-java-compute/src/test/java/com/google/gcloud/compute/ImageDiskConfigurationTest.java @@ -40,7 +40,7 @@ public class ImageDiskConfigurationTest { @Test public void testToBuilder() { compareImageDiskConfiguration(DISK_CONFIGURATION, DISK_CONFIGURATION.toBuilder().build()); - ImageId newImageId = ImageId.of("newProjet", "newImage"); + ImageId newImageId = ImageId.of("newProject", "newImage"); ImageDiskConfiguration diskConfiguration = DISK_CONFIGURATION.toBuilder() .sizeGb(24L) .sourceImage(newImageId) diff --git a/gcloud-java-compute/src/test/java/com/google/gcloud/compute/SnapshotDiskConfigurationTest.java b/gcloud-java-compute/src/test/java/com/google/gcloud/compute/SnapshotDiskConfigurationTest.java index ecbe49dc9628..a6380dca667d 100644 --- a/gcloud-java-compute/src/test/java/com/google/gcloud/compute/SnapshotDiskConfigurationTest.java +++ b/gcloud-java-compute/src/test/java/com/google/gcloud/compute/SnapshotDiskConfigurationTest.java @@ -40,7 +40,7 @@ public class SnapshotDiskConfigurationTest { @Test public void testToBuilder() { compareSnapshotDiskConfiguration(DISK_CONFIGURATION, DISK_CONFIGURATION.toBuilder().build()); - SnapshotId newSnapshot = SnapshotId.of("newProjet", "newSnapshot"); + SnapshotId newSnapshot = SnapshotId.of("newProject", "newSnapshot"); SnapshotDiskConfiguration diskConfiguration = DISK_CONFIGURATION.toBuilder() .sizeGb(24L) .sourceSnapshot(newSnapshot) diff --git a/gcloud-java-compute/src/test/java/com/google/gcloud/compute/StandardDiskConfigurationTest.java b/gcloud-java-compute/src/test/java/com/google/gcloud/compute/StandardDiskConfigurationTest.java index f5ea642b407a..702a362b6ddc 100644 --- a/gcloud-java-compute/src/test/java/com/google/gcloud/compute/StandardDiskConfigurationTest.java +++ b/gcloud-java-compute/src/test/java/com/google/gcloud/compute/StandardDiskConfigurationTest.java @@ -36,7 +36,7 @@ public class StandardDiskConfigurationTest { @Test public void testToBuilder() { - compareDefaultDiskConfiguration(DISK_CONFIGURATION, DISK_CONFIGURATION.toBuilder().build()); + compareStandardDiskConfiguration(DISK_CONFIGURATION, DISK_CONFIGURATION.toBuilder().build()); StandardDiskConfiguration diskConfiguration = DISK_CONFIGURATION.toBuilder() .sizeGb(24L) .build(); @@ -44,13 +44,13 @@ public void testToBuilder() { diskConfiguration = diskConfiguration.toBuilder() .sizeGb(SIZE) .build(); - compareDefaultDiskConfiguration(DISK_CONFIGURATION, diskConfiguration); + compareStandardDiskConfiguration(DISK_CONFIGURATION, diskConfiguration); } @Test public void testToBuilderIncomplete() { StandardDiskConfiguration diskConfiguration = StandardDiskConfiguration.of(DISK_TYPE); - compareDefaultDiskConfiguration(diskConfiguration, diskConfiguration.toBuilder().build()); + compareStandardDiskConfiguration(diskConfiguration, diskConfiguration.toBuilder().build()); } @Test @@ -64,7 +64,7 @@ public void testBuilder() { public void testToAndFromPb() { assertTrue(DiskConfiguration.fromPb(DISK_CONFIGURATION.toPb()) instanceof StandardDiskConfiguration); - compareDefaultDiskConfiguration(DISK_CONFIGURATION, + compareStandardDiskConfiguration(DISK_CONFIGURATION, DiskConfiguration.fromPb(DISK_CONFIGURATION.toPb())); } @@ -89,10 +89,10 @@ public void testSetProjectId() { StandardDiskConfiguration configuration = DISK_CONFIGURATION.toBuilder() .diskType(DiskTypeId.of(DISK_TYPE.zone(), DISK_TYPE.diskType())) .build(); - compareDefaultDiskConfiguration(DISK_CONFIGURATION, configuration.setProjectId("project")); + compareStandardDiskConfiguration(DISK_CONFIGURATION, configuration.setProjectId("project")); } - private void compareDefaultDiskConfiguration(StandardDiskConfiguration expected, + private void compareStandardDiskConfiguration(StandardDiskConfiguration expected, StandardDiskConfiguration value) { assertEquals(expected, value); assertEquals(expected.diskType(), value.diskType());