// Path: utility/src/main/java/com/comcast/viper/flume2storm/utility/test/TestCondition.java
// public interface TestCondition {
// 	/**
// 	 * @return True when the condition is fulfilled, false otherwise
// 	 */
// 	boolean evaluate();
// }
// 
// Path: utility/src/main/java/com/comcast/viper/flume2storm/utility/test/TestUtils.java
// public class TestUtils {
//   private static final int DEFAULT_RETRY_TIMEOUT = 100;
//   private static Random random = new Random();
// 
//   /**
//    * @return An ephemeral port available for test usage
//    */
//   public static int getAvailablePort() {
//     try (ServerSocket s = new ServerSocket(0)) {
//       return s.getLocalPort();
//     } catch (Exception e) {
//       throw new AssertionError("Failed to find available port", e);
//     }
//   }
// 
//   /**
//    * @param n
//    *          Max int allowed
//    * @return A random number between 1 and n
//    */
//   public static final int getRandomPositiveInt(int n) {
//     Preconditions.checkArgument(n > 1, "Cannot generate this kind of number!");
//     return random.nextInt(n - 1) + 1;
//   }
// 
//   /**
//    * Waits that the condition is fulfilled - careful, this may never return!
//    * 
//    * @param condition
//    *          The condition to evaluate. It should be fast to evaluate
//    * @throws InterruptedException
//    *           If wait is interrupted
//    */
//   public static void waitFor(final TestCondition condition) throws InterruptedException {
//     waitFor(condition, Integer.MAX_VALUE);
//   }
// 
//   /**
//    * Waits that the condition is fulfilled, for up to a specified amount of time
//    * 
//    * @param condition
//    *          The condition to evaluate. It should be fast to evaluate
//    * @param maxWaitInMs
//    *          The maximum number of milliseconds to wait
//    * @return True if the condition is fulfilled in time, false otherwise
//    * @throws InterruptedException
//    *           If wait is interrupted
//    */
//   public static boolean waitFor(final TestCondition condition, final int maxWaitInMs) throws InterruptedException {
//     return waitFor(condition, maxWaitInMs, DEFAULT_RETRY_TIMEOUT);
//   }
// 
//   /**
//    * Waits that the condition is fulfilled, for up to a specified amount of time
//    * 
//    * @param condition
//    *          The condition to evaluate. It should be fast to evaluate
//    * @param maxWaitInMs
//    *          The maximum number of milliseconds to wait
//    * @param retryTimeout
//    *          The number of milliseconds to wait before retry the test
//    * @return True if the condition is fulfilled in time, false otherwise
//    * @throws InterruptedException
//    *           If wait is interrupted
//    */
//   public static boolean waitFor(final TestCondition condition, final int maxWaitInMs, final int retryTimeout)
//       throws InterruptedException {
//     final long t0 = System.currentTimeMillis();
//     while (!condition.evaluate() && (System.currentTimeMillis() - t0) < maxWaitInMs) {
//       Thread.sleep(retryTimeout);
//     }
//     if (condition.evaluate()) {
//       return true;
//     }
//     throw new AssertionError("TestCondition did not validate in time");
//   }
// }


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import org.apache.commons.lang.StringUtils;
import com.comcast.viper.flume2storm.utility.test.TestCondition;
import com.comcast.viper.flume2storm.utility.test.TestUtils;
import com.google.common.base.Preconditions;
      final Socket sock = new Socket(host, port);
      OutputStream outstream = null;
      BufferedReader reader = null;
      try {
        outstream = sock.getOutputStream();
        outstream.write(cmd.getBytes());
        outstream.flush();

        reader = new BufferedReader(new InputStreamReader(sock.getInputStream()));
        final StringBuilder sb = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
          sb.append(line + "\n");
        }
        return sb.toString();
      } finally {
        if (outstream != null) {
          outstream.close();
        }
        sock.close();
        if (reader != null) {
          reader.close();
        }
      }
    } catch (final Exception e) {
      System.out.println(e.getMessage());
      return StringUtils.EMPTY;
    }
  }

// Path: utility/src/main/java/com/comcast/viper/flume2storm/utility/test/TestCondition.java
// public interface TestCondition {
// 	/**
// 	 * @return True when the condition is fulfilled, false otherwise
// 	 */
// 	boolean evaluate();
// }
// 
// Path: utility/src/main/java/com/comcast/viper/flume2storm/utility/test/TestUtils.java
// public class TestUtils {
//   private static final int DEFAULT_RETRY_TIMEOUT = 100;
//   private static Random random = new Random();
// 
//   /**
//    * @return An ephemeral port available for test usage
//    */
//   public static int getAvailablePort() {
//     try (ServerSocket s = new ServerSocket(0)) {
//       return s.getLocalPort();
//     } catch (Exception e) {
//       throw new AssertionError("Failed to find available port", e);
//     }
//   }
// 
//   /**
//    * @param n
//    *          Max int allowed
//    * @return A random number between 1 and n
//    */
//   public static final int getRandomPositiveInt(int n) {
//     Preconditions.checkArgument(n > 1, "Cannot generate this kind of number!");
//     return random.nextInt(n - 1) + 1;
//   }
// 
//   /**
//    * Waits that the condition is fulfilled - careful, this may never return!
//    * 
//    * @param condition
//    *          The condition to evaluate. It should be fast to evaluate
//    * @throws InterruptedException
//    *           If wait is interrupted
//    */
//   public static void waitFor(final TestCondition condition) throws InterruptedException {
//     waitFor(condition, Integer.MAX_VALUE);
//   }
// 
//   /**
//    * Waits that the condition is fulfilled, for up to a specified amount of time
//    * 
//    * @param condition
//    *          The condition to evaluate. It should be fast to evaluate
//    * @param maxWaitInMs
//    *          The maximum number of milliseconds to wait
//    * @return True if the condition is fulfilled in time, false otherwise
//    * @throws InterruptedException
//    *           If wait is interrupted
//    */
//   public static boolean waitFor(final TestCondition condition, final int maxWaitInMs) throws InterruptedException {
//     return waitFor(condition, maxWaitInMs, DEFAULT_RETRY_TIMEOUT);
//   }
// 
//   /**
//    * Waits that the condition is fulfilled, for up to a specified amount of time
//    * 
//    * @param condition
//    *          The condition to evaluate. It should be fast to evaluate
//    * @param maxWaitInMs
//    *          The maximum number of milliseconds to wait
//    * @param retryTimeout
//    *          The number of milliseconds to wait before retry the test
//    * @return True if the condition is fulfilled in time, false otherwise
//    * @throws InterruptedException
//    *           If wait is interrupted
//    */
//   public static boolean waitFor(final TestCondition condition, final int maxWaitInMs, final int retryTimeout)
//       throws InterruptedException {
//     final long t0 = System.currentTimeMillis();
//     while (!condition.evaluate() && (System.currentTimeMillis() - t0) < maxWaitInMs) {
//       Thread.sleep(retryTimeout);
//     }
//     if (condition.evaluate()) {
//       return true;
//     }
//     throw new AssertionError("TestCondition did not validate in time");
//   }
// }


// Path: dynamic-location-service/src/test/java/com/comcast/viper/flume2storm/zookeeper/ZkTestUtils.java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import org.apache.commons.lang.StringUtils;
import com.comcast.viper.flume2storm.utility.test.TestCondition;
import com.comcast.viper.flume2storm.utility.test.TestUtils;
import com.google.common.base.Preconditions;

      final Socket sock = new Socket(host, port);
      OutputStream outstream = null;
      BufferedReader reader = null;
      try {
        outstream = sock.getOutputStream();
        outstream.write(cmd.getBytes());
        outstream.flush();

        reader = new BufferedReader(new InputStreamReader(sock.getInputStream()));
        final StringBuilder sb = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
          sb.append(line + "\n");
        }
        return sb.toString();
      } finally {
        if (outstream != null) {
          outstream.close();
        }
        sock.close();
        if (reader != null) {
          reader.close();
        }
      }
    } catch (final Exception e) {
      System.out.println(e.getMessage());
      return StringUtils.EMPTY;
    }
  }

  public static final TestCondition ZK_IS_ON = new TestCondition() {