@Test
  public void testCreatePod() throws Exception {
    log.info("Testing Pods ....");

    if (log.isDebugEnabled()) {
      log.debug("Creating a Pod " + pod);
    }
    Pod createPod = getClient().createPod(pod);
    assertEquals(pod.getId(), createPod.getId());
    assertNotNull(getClient().getPod(pod.getId()));
    assertEquals("Waiting", createPod.getCurrentState().getStatus());

    ExecutorService executor = Executors.newSingleThreadExecutor();
    Future<Pod> future =
        executor.submit(
            new Callable<Pod>() {
              public Pod call() throws Exception {
                Pod newPod;
                do {
                  log.info("Waiting for Pod to be ready: " + pod.getId());
                  Thread.sleep(1000);
                  newPod = getClient().getPod(pod.getId());
                  StateInfo info = newPod.getCurrentState().getInfo("master");
                  if (info.getState("waiting") != null) {
                    throw new RuntimeException("Pod is waiting due to " + info.getState("waiting"));
                  }
                } while (!"Running".equals(newPod.getCurrentState().getStatus()));
                return newPod;
              }
            });

    try {
      createPod = future.get(90, TimeUnit.SECONDS);
    } finally {
      executor.shutdownNow();
    }
    assertNotNull(createPod.getCurrentState().getInfo("master").getState("running"));
    assertNotNull(createPod.getCurrentState().getNetInfo().getState("running"));

    // test recreation from same id
    try {
      getClient().createPod(pod);
      fail("Should have thrown exception");
    } catch (Exception e) {
      // ignore
    }
    assertNotNull(getClient().getPod(pod.getId()));
  }
  @Test
  public void testCreateReplicationController() throws Exception {
    if (log.isDebugEnabled()) {
      log.debug("Creating a Replication Controller: " + contr);
    }
    getClient().createReplicationController(contr);
    assertNotNull(getClient().getReplicationController(contr.getId()));

    ExecutorService executor = Executors.newSingleThreadExecutor();
    Future<PodList> future =
        executor.submit(
            new Callable<PodList>() {
              public PodList call() throws Exception {
                PodList pods;
                do {
                  log.info("Waiting for Pods to be ready");
                  Thread.sleep(1000);
                  pods =
                      getClient()
                          .getSelectedPods(
                              ImmutableMap.of("name", "kubernetes-test-controller-selector"));
                  if (pods.isEmpty()) {
                    continue;
                  }

                  StateInfo info = pods.get(0).getCurrentState().getInfo("kubernetes-test");
                  if ((info != null) && info.getState("waiting") != null) {
                    throw new RuntimeException("Pod is waiting due to " + info.getState("waiting"));
                  }
                } while (pods.isEmpty()
                    || !FluentIterable.from(pods)
                        .allMatch(
                            new Predicate<Pod>() {
                              public boolean apply(Pod pod) {
                                return "Running".equals(pod.getCurrentState().getStatus());
                              }
                            }));
                return pods;
              }
            });

    PodList pods;
    try {
      pods = future.get(90, TimeUnit.SECONDS);
    } finally {
      executor.shutdownNow();
    }
    for (Pod pod : pods) {
      assertNotNull(pod.getCurrentState().getInfo("kubernetes-test").getState("running"));
      assertNotNull(pod.getCurrentState().getNetInfo().getState("running"));
    }

    // test recreation using same id
    try {
      getClient().createReplicationController(contr);
      fail("Should have thrown exception");
    } catch (Exception e) {
      // ignore
    }
    assertNotNull(getClient().getReplicationController(contr.getId()));

    PodList podList = getClient().getSelectedPods(contr.getLabels());
    assertNotNull(podList);
    assertNotNull(podList.getItems());
    assertEquals(contr.getDesiredState().getReplicas(), podList.getItems().size());
  }