public static void setupClientId(Configuration conf) {
    if (OptionsResolver.isMultiWriter(conf)) {
      // explicit client id always has higher priority
      if (!conf.contains(FlinkOptions.WRITE_CLIENT_ID)) {
        try (ClientIds clientIds = ClientIds.builder().conf(conf).build()) {
          String clientId = clientIds.nextId(conf);
          conf.setString(FlinkOptions.WRITE_CLIENT_ID, clientId);
        }
      }
    }
  }
@Test
  void testSetupClientId() throws Exception {
    Configuration conf = getConf();
    conf.setString(FlinkOptions.WRITE_CLIENT_ID, "2");
    OptionsInference.setupClientId(conf);
    assertThat("Explicit client id has higher priority",
        conf.getString(FlinkOptions.WRITE_CLIENT_ID), is("2"));

    for (int i = 0; i < 3; i++) {
      conf = getConf();
      try (ClientIds clientIds = ClientIds.builder().conf(conf).build()) {
        OptionsInference.setupClientId(conf);
        String expectedId = i == 0 ? ClientIds.INIT_CLIENT_ID : i + "";
        assertThat("The client id should auto inc to " + expectedId,
            conf.getString(FlinkOptions.WRITE_CLIENT_ID), is(expectedId));
      }
    }

    // sleep 1 second to simulate a zombie heartbeat
    Thread.sleep(1000);
    conf = getConf();
    try (ClientIds clientIds = ClientIds.builder()
        .conf(conf)
        .heartbeatIntervalInMs(10) // max 10 milliseconds tolerable heartbeat timeout
        .numTolerableHeartbeatMisses(1). build()) {
      String nextId = clientIds.nextId(conf);
      assertThat("The inactive client id should be reused",
          nextId, is(""));
    }
  }