/**
  * After disabling the remote agent the value of
  * 'sun.management.JMXConnectorServer.remote.enabled' counter will become '-1'.
  *
  * @throws Exception
  */
 @Test
 public void testRemoteDisabled() throws Exception {
   while (true) {
     try {
       int[] ports = PortAllocator.allocatePorts(1);
       jcmd.start(
           "jmxremote.port=" + ports[0], "jmxremote.authenticate=false", "jmxremote.ssl=false");
       jcmd.stop();
       String v = getCounters().getProperty(REMOTE_STATUS_KEY);
       assertNotNull(v);
       assertEquals("-1", v);
       return;
     } catch (BindException e) {
       System.out.println("Failed to allocate ports. Retrying ...");
     }
   }
 }
 private Properties getCounters() throws IOException, InterruptedException {
   return jcmd.perfCounters("sun\\.management\\.JMXConnectorServer\\..*");
 }