From 98d8895b71acd0ce75aa95bd62bc22431c2a965c Mon Sep 17 00:00:00 2001 From: Matt Lehman Date: Thu, 29 Aug 2024 18:05:00 -0700 Subject: [PATCH] Always set isReplace when the replace ip is set. --- .../netflix/priam/identity/InstanceIdentity.java | 2 +- .../backup/identity/InstanceIdentityTest.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/priam/src/main/java/com/netflix/priam/identity/InstanceIdentity.java b/priam/src/main/java/com/netflix/priam/identity/InstanceIdentity.java index 7fdc66172..f341380ea 100644 --- a/priam/src/main/java/com/netflix/priam/identity/InstanceIdentity.java +++ b/priam/src/main/java/com/netflix/priam/identity/InstanceIdentity.java @@ -171,7 +171,7 @@ public void setReplacedIp(String replacedIp) { throw new IllegalArgumentException( replacedIp + " is neither empty nor a valid IpV4 address"); } - if (!StringUtils.isEmpty(replacedIp)) this.isReplace = true; + this.isReplace = !StringUtils.isEmpty(replacedIp); } private static boolean isInstanceDummy(PriamInstance instance) { diff --git a/priam/src/test/java/com/netflix/priam/backup/identity/InstanceIdentityTest.java b/priam/src/test/java/com/netflix/priam/backup/identity/InstanceIdentityTest.java index 463878710..b2027dc8b 100644 --- a/priam/src/test/java/com/netflix/priam/backup/identity/InstanceIdentityTest.java +++ b/priam/src/test/java/com/netflix/priam/backup/identity/InstanceIdentityTest.java @@ -160,4 +160,20 @@ public void testIsReplace_validReplaceIp() throws Exception { identity.setReplacedIp("1.2.3.4"); Truth.assertThat(identity.isReplace()).isTrue(); } + + @Test + public void testIsReplace_nullThenValid() throws Exception { + InstanceIdentity identity = createInstanceIdentity("az1", "fakeinstancex"); + identity.setReplacedIp(null); + identity.setReplacedIp("1.2.3.4"); + Truth.assertThat(identity.isReplace()).isTrue(); + } + + @Test + public void testIsReplace_validThenNull() throws Exception { + InstanceIdentity identity = createInstanceIdentity("az1", "fakeinstancex"); + identity.setReplacedIp("1.2.3.4"); + identity.setReplacedIp(null); + Truth.assertThat(identity.isReplace()).isFalse(); + } }