/**
   * Each subsequent re-enablement of the remote agent must keep the value of
   * 'sun.management.JMXConnectorServer.remote.enabled' counter in sync with the actual version of
   * the associated remote connector perf counters.
   *
   * @throws Exception
   */
  @Test
  public void testRemoteReEnabled() throws Exception {
    while (true) {
      try {
        int[] ports = PortAllocator.allocatePorts(1);
        jcmd.start(
            "jmxremote.port=" + ports[0], "jmxremote.authenticate=false", "jmxremote.ssl=false");
        jcmd.stop();
        jcmd.start(
            "jmxremote.port=" + ports[0], "jmxremote.authenticate=false", "jmxremote.ssl=false");

        String v = getCounters().getProperty(REMOTE_STATUS_KEY);
        assertNotNull(v);
        assertEquals("1", v);
        return;
      } catch (BindException e) {
        System.out.println("Failed to allocate ports. Retrying ...");
      }
    }
  }