// 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 junit.framework.Assert;
import com.comcast.viper.flume2storm.utility.test.TestCondition;
import com.comcast.viper.flume2storm.utility.test.TestUtils;

    @Override
    public boolean evaluate() {
      return !zkClient.getState().isConnected();
    }
  }

  public static class ClientSetupCondition implements TestCondition {
    private final ZkClient zkClient;

    public ClientSetupCondition(final ZkClient zkClient) {
      this.zkClient = zkClient;
    }

    @Override
    public boolean evaluate() {
      return zkClient.getState().isSetup();
    }
  }

  public static void waitZkClientStarted(final int timeout) throws Exception {
    Assert.assertTrue(TestUtils.waitFor(new ClientStartedCondition(zkClient), timeout));
    assertZkClientStarted();
  }

  public static void waitZkClientStarted() throws Exception {
    waitZkClientStarted(TEST_TIMEOUT);
  }

  public static void waitZkClientConnected(final int timeout) throws Exception {
// 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/ZkClientTestUtils.java
import junit.framework.Assert;
import com.comcast.viper.flume2storm.utility.test.TestCondition;
import com.comcast.viper.flume2storm.utility.test.TestUtils;


    @Override
    public boolean evaluate() {
      return !zkClient.getState().isConnected();
    }
  }

  public static class ClientSetupCondition implements TestCondition {
    private final ZkClient zkClient;

    public ClientSetupCondition(final ZkClient zkClient) {
      this.zkClient = zkClient;
    }

    @Override
    public boolean evaluate() {
      return zkClient.getState().isSetup();
    }
  }

  public static void waitZkClientStarted(final int timeout) throws Exception {
    Assert.assertTrue(TestUtils.waitFor(new ClientStartedCondition(zkClient), timeout));
    assertZkClientStarted();
  }

  public static void waitZkClientStarted() throws Exception {
    waitZkClientStarted(TEST_TIMEOUT);
  }

  public static void waitZkClientConnected(final int timeout) throws Exception {
    Assert.assertTrue(TestUtils.waitFor(new ClientConnectedCondition(zkClient), timeout));