StorageDiff extends AbstractResourceDiff { @Override public boolean isEmpty() { return isEmpty; } StorageDiff(Storage current, Storage desired, int currentReplicas, int desiredReplicas); private  StorageDiff(Storage current, Storage desired, int currentReplicas, int desiredReplicas, String volumeDesc); @Override boolean isEmpty(); boolean changesType(); boolean shrinkSize();  }
@Test public void testPersistentDiffWithOverridesChangesToExistingOverrides() { Storage persistent = new PersistentClaimStorageBuilder() .withStorageClass("gp2-ssd") .withDeleteClaim(false) .withId(0) .withSize("100Gi") .withOverrides( new PersistentClaimStorageOverrideBuilder() .withBroker(0) .withStorageClass("gp2-ssd-az1") .build(), new PersistentClaimStorageOverrideBuilder() .withBroker(1) .withStorageClass("gp2-ssd-az2") .build()) .build(); Storage persistent2 = new PersistentClaimStorageBuilder() .withStorageClass("gp2-ssd") .withDeleteClaim(false) .withId(0) .withSize("100Gi") .withOverrides( new PersistentClaimStorageOverrideBuilder() .withBroker(0) .withStorageClass("gp2-ssd-az1") .build(), new PersistentClaimStorageOverrideBuilder() .withBroker(1) .withStorageClass("new-sc") .build()) .build(); assertThat(new StorageDiff(persistent, persistent, 2, 2).isEmpty(), is(true)); assertThat(new StorageDiff(persistent2, persistent2, 2, 2).isEmpty(), is(true)); assertThat(new StorageDiff(persistent, persistent2, 1, 1).isEmpty(), is(true)); assertThat(new StorageDiff(persistent, persistent2, 1, 2).isEmpty(), is(true)); assertThat(new StorageDiff(persistent, persistent2, 2, 2).isEmpty(), is(false)); assertThat(new StorageDiff(persistent, persistent2, 2, 1).isEmpty(), is(true)); }
@Test public void testPersistentDiffWithOverridesBeingAdded() { Storage persistent = new PersistentClaimStorageBuilder() .withStorageClass("gp2-ssd") .withDeleteClaim(false) .withId(0) .withSize("100Gi") .build(); Storage persistent2 = new PersistentClaimStorageBuilder() .withStorageClass("gp2-ssd") .withDeleteClaim(false) .withId(0) .withSize("100Gi") .withOverrides( new PersistentClaimStorageOverrideBuilder() .withBroker(0) .withStorageClass("gp2-ssd-az1") .build()) .build(); Storage persistent3 = new PersistentClaimStorageBuilder() .withStorageClass("gp2-ssd") .withDeleteClaim(false) .withId(0) .withSize("100Gi") .withOverrides( new PersistentClaimStorageOverrideBuilder() .withBroker(0) .withStorageClass("gp2-ssd-az1") .build(), new PersistentClaimStorageOverrideBuilder() .withBroker(1) .withStorageClass("gp2-ssd-az2") .build()) .build(); assertThat(new StorageDiff(persistent, persistent, 2, 2).isEmpty(), is(true)); assertThat(new StorageDiff(persistent2, persistent2, 2, 2).isEmpty(), is(true)); assertThat(new StorageDiff(persistent3, persistent3, 2, 2).isEmpty(), is(true)); assertThat(new StorageDiff(persistent, persistent2, 2, 2).isEmpty(), is(false)); assertThat(new StorageDiff(persistent, persistent3, 2, 2).isEmpty(), is(false)); assertThat(new StorageDiff(persistent2, persistent3, 2, 2).isEmpty(), is(false)); assertThat(new StorageDiff(persistent2, persistent3, 1, 2).isEmpty(), is(true)); assertThat(new StorageDiff(persistent2, persistent3, 2, 1).isEmpty(), is(true)); assertThat(new StorageDiff(persistent2, persistent3, 1, 1).isEmpty(), is(true)); }
@Test public void testPersistentDiffWithOverridesBeingRemoved() { Storage persistent = new PersistentClaimStorageBuilder() .withStorageClass("gp2-ssd") .withDeleteClaim(false) .withId(0) .withSize("100Gi") .build(); Storage persistent2 = new PersistentClaimStorageBuilder() .withStorageClass("gp2-ssd") .withDeleteClaim(false) .withId(0) .withSize("100Gi") .withOverrides( new PersistentClaimStorageOverrideBuilder() .withBroker(0) .withStorageClass("gp2-ssd-az1") .build()) .build(); Storage persistent3 = new PersistentClaimStorageBuilder() .withStorageClass("gp2-ssd") .withDeleteClaim(false) .withId(0) .withSize("100Gi") .withOverrides( new PersistentClaimStorageOverrideBuilder() .withBroker(0) .withStorageClass("gp2-ssd-az1") .build(), new PersistentClaimStorageOverrideBuilder() .withBroker(1) .withStorageClass("gp2-ssd-az2") .build()) .build(); assertThat(new StorageDiff(persistent, persistent, 2, 2).isEmpty(), is(true)); assertThat(new StorageDiff(persistent2, persistent2, 2, 2).isEmpty(), is(true)); assertThat(new StorageDiff(persistent3, persistent3, 2, 2).isEmpty(), is(true)); assertThat(new StorageDiff(persistent3, persistent, 2, 2).isEmpty(), is(false)); assertThat(new StorageDiff(persistent3, persistent2, 2, 2).isEmpty(), is(false)); assertThat(new StorageDiff(persistent2, persistent, 2, 2).isEmpty(), is(false)); assertThat(new StorageDiff(persistent3, persistent2, 1, 2).isEmpty(), is(true)); assertThat(new StorageDiff(persistent3, persistent2, 2, 1).isEmpty(), is(true)); assertThat(new StorageDiff(persistent3, persistent2, 1, 1).isEmpty(), is(true)); }
@Test public void testPersistentDiffWithOverridesBeingAddedAndRemoved() { Storage persistent = new PersistentClaimStorageBuilder() .withStorageClass("gp2-ssd") .withDeleteClaim(false) .withId(0) .withSize("100Gi") .withOverrides( new PersistentClaimStorageOverrideBuilder() .withBroker(0) .withStorageClass("gp2-ssd-az1") .build()) .build(); Storage persistent2 = new PersistentClaimStorageBuilder() .withStorageClass("gp2-ssd") .withDeleteClaim(false) .withId(0) .withSize("100Gi") .withOverrides( new PersistentClaimStorageOverrideBuilder() .withBroker(1) .withStorageClass("gp2-ssd-az2") .build()) .build(); assertThat(new StorageDiff(persistent, persistent, 2, 2).isEmpty(), is(true)); assertThat(new StorageDiff(persistent2, persistent2, 2, 2).isEmpty(), is(true)); assertThat(new StorageDiff(persistent2, persistent, 2, 2).isEmpty(), is(false)); assertThat(new StorageDiff(persistent, persistent2, 2, 2).isEmpty(), is(false)); assertThat(new StorageDiff(persistent, persistent2, 1, 2).isEmpty(), is(false)); assertThat(new StorageDiff(persistent2, persistent, 1, 2).isEmpty(), is(false)); }