public static boolean updateHostnamePort(InstanceConfig instanceConfig, String hostname, int port) {
    boolean updated = false;
    String existingHostname = instanceConfig.getHostName();
    if (!hostname.equals(existingHostname)) {
      LOGGER.info("Updating instance: {} with hostname: {}", instanceConfig.getId(), hostname);
      instanceConfig.setHostName(hostname);
      updated = true;
    }
    String portStr = Integer.toString(port);
    String existingPortStr = instanceConfig.getPort();
    if (!portStr.equals(existingPortStr)) {
      LOGGER.info("Updating instance: {} with port: {}", instanceConfig.getId(), port);
      instanceConfig.setPort(portStr);
      updated = true;
    }
    return updated;
  }
@Test
  public void testUpdateHostName() {
    String instanceId = "Server_myInstance";
    InstanceConfig instanceConfig = new InstanceConfig(instanceId);
    assertEquals(instanceConfig.getInstanceName(), instanceId);
    assertNull(instanceConfig.getHostName());
    assertNull(instanceConfig.getPort());

    assertTrue(HelixHelper.updateHostnamePort(instanceConfig, "myHost", 1234));
    assertEquals(instanceConfig.getInstanceName(), instanceId);
    assertEquals(instanceConfig.getHostName(), "myHost");
    assertEquals(instanceConfig.getPort(), "1234");

    assertTrue(HelixHelper.updateHostnamePort(instanceConfig, "myHost2", 1234));
    assertEquals(instanceConfig.getInstanceName(), instanceId);
    assertEquals(instanceConfig.getHostName(), "myHost2");
    assertEquals(instanceConfig.getPort(), "1234");

    assertTrue(HelixHelper.updateHostnamePort(instanceConfig, "myHost2", 2345));
    assertEquals(instanceConfig.getInstanceName(), instanceId);
    assertEquals(instanceConfig.getHostName(), "myHost2");
    assertEquals(instanceConfig.getPort(), "2345");

    assertFalse(HelixHelper.updateHostnamePort(instanceConfig, "myHost2", 2345));
    assertEquals(instanceConfig.getInstanceName(), instanceId);
    assertEquals(instanceConfig.getHostName(), "myHost2");
    assertEquals(instanceConfig.getPort(), "2345");
  }