public static InstanceConfig toHelixInstanceConfig(Instance instance) {
    InstanceConfig instanceConfig = new InstanceConfig(getHelixInstanceId(instance));
    instanceConfig.setInstanceEnabled(true);
    updateHelixInstanceConfig(instanceConfig, instance);
    return instanceConfig;
  }
@Test
  public void testToHelixInstanceConfig() {
    Instance instance = new Instance("localhost", 1234, InstanceType.CONTROLLER, null, null, 0, 0, 0, 0, false);
    InstanceConfig instanceConfig = InstanceUtils.toHelixInstanceConfig(instance);
    assertEquals(instanceConfig.getInstanceName(), "Controller_localhost_1234");
    assertTrue(instanceConfig.getInstanceEnabled());
    assertEquals(instanceConfig.getHostName(), "localhost");
    assertEquals(instanceConfig.getPort(), "1234");
    assertTrue(instanceConfig.getTags().isEmpty());
    ZNRecord znRecord = instanceConfig.getRecord();
    assertNull(znRecord.getMapField(InstanceUtils.POOL_KEY));
    assertNull(znRecord.getSimpleField(CommonConstants.Helix.Instance.GRPC_PORT_KEY));
    assertNull(znRecord.getSimpleField(CommonConstants.Helix.Instance.ADMIN_PORT_KEY));
    assertNull(znRecord.getSimpleField(CommonConstants.Helix.Instance.MULTI_STAGE_QUERY_ENGINE_SERVICE_PORT_KEY));
    assertNull(znRecord.getSimpleField(CommonConstants.Helix.Instance.MULTI_STAGE_QUERY_ENGINE_MAILBOX_PORT_KEY));
    assertNull(znRecord.getSimpleField(CommonConstants.Helix.QUERIES_DISABLED));

    List<String> tags = Collections.singletonList("DefaultTenant_BROKER");
    instance = new Instance("localhost", 2345, InstanceType.BROKER, tags, null, 0, 0, 0, 0, false);
    instanceConfig = InstanceUtils.toHelixInstanceConfig(instance);
    assertEquals(instanceConfig.getInstanceName(), "Broker_localhost_2345");
    assertTrue(instanceConfig.getInstanceEnabled());
    assertEquals(instanceConfig.getHostName(), "localhost");
    assertEquals(instanceConfig.getPort(), "2345");
    assertEquals(instanceConfig.getTags(), tags);
    znRecord = instanceConfig.getRecord();
    assertNull(znRecord.getMapField(InstanceUtils.POOL_KEY));
    assertNull(znRecord.getSimpleField(CommonConstants.Helix.Instance.GRPC_PORT_KEY));
    assertNull(znRecord.getSimpleField(CommonConstants.Helix.Instance.ADMIN_PORT_KEY));
    assertNull(znRecord.getSimpleField(CommonConstants.Helix.Instance.MULTI_STAGE_QUERY_ENGINE_SERVICE_PORT_KEY));
    assertNull(znRecord.getSimpleField(CommonConstants.Helix.Instance.MULTI_STAGE_QUERY_ENGINE_MAILBOX_PORT_KEY));
    assertNull(znRecord.getSimpleField(CommonConstants.Helix.QUERIES_DISABLED));

    tags = Arrays.asList("T1_OFFLINE", "T2_REALTIME");
    Map<String, Integer> poolMap = new TreeMap<>();
    poolMap.put("T1_OFFLINE", 0);
    poolMap.put("T2_REALTIME", 1);
    instance = new Instance("localhost", 3456, InstanceType.SERVER, tags, poolMap, 123, 234, 345, 456, true);
    instanceConfig = InstanceUtils.toHelixInstanceConfig(instance);
    assertEquals(instanceConfig.getInstanceName(), "Server_localhost_3456");
    assertTrue(instanceConfig.getInstanceEnabled());
    assertEquals(instanceConfig.getHostName(), "localhost");
    assertEquals(instanceConfig.getPort(), "3456");
    assertEquals(instanceConfig.getTags(), tags);
    znRecord = instanceConfig.getRecord();
    Map<String, String> expectedPoolMap = new TreeMap<>();
    expectedPoolMap.put("T1_OFFLINE", "0");
    expectedPoolMap.put("T2_REALTIME", "1");
    assertEquals(znRecord.getMapField(InstanceUtils.POOL_KEY), expectedPoolMap);
    assertEquals(znRecord.getSimpleField(CommonConstants.Helix.Instance.GRPC_PORT_KEY), "123");
    assertEquals(znRecord.getSimpleField(CommonConstants.Helix.Instance.ADMIN_PORT_KEY), "234");
    assertEquals(znRecord.getSimpleField(CommonConstants.Helix.Instance.MULTI_STAGE_QUERY_ENGINE_SERVICE_PORT_KEY),
        "345");
    assertEquals(znRecord.getSimpleField(CommonConstants.Helix.Instance.MULTI_STAGE_QUERY_ENGINE_MAILBOX_PORT_KEY),
        "456");
    assertEquals(znRecord.getSimpleField(CommonConstants.Helix.QUERIES_DISABLED), "true");

    tags = Collections.singletonList("minion_untagged");
    instance = new Instance("localhost", 4567, InstanceType.MINION, tags, null, 0, 0, 0, 0, false);
    instanceConfig = InstanceUtils.toHelixInstanceConfig(instance);
    assertEquals(instanceConfig.getInstanceName(), "Minion_localhost_4567");
    assertTrue(instanceConfig.getInstanceEnabled());
    assertEquals(instanceConfig.getHostName(), "localhost");
    assertEquals(instanceConfig.getPort(), "4567");
    assertEquals(instanceConfig.getTags(), tags);
    znRecord = instanceConfig.getRecord();
    assertNull(znRecord.getMapField(InstanceUtils.POOL_KEY));
    assertNull(znRecord.getSimpleField(CommonConstants.Helix.Instance.GRPC_PORT_KEY));
    assertNull(znRecord.getSimpleField(CommonConstants.Helix.Instance.ADMIN_PORT_KEY));
    assertNull(znRecord.getSimpleField(CommonConstants.Helix.Instance.MULTI_STAGE_QUERY_ENGINE_SERVICE_PORT_KEY));
    assertNull(znRecord.getSimpleField(CommonConstants.Helix.Instance.MULTI_STAGE_QUERY_ENGINE_MAILBOX_PORT_KEY));
    assertNull(znRecord.getSimpleField(CommonConstants.Helix.QUERIES_DISABLED));
  }