@Test
 public void testGetSelectedPodsWithNonExistantLabel() throws Exception {
   PodList selectedPods = getClient().getSelectedPods(ImmutableMap.of("name", "no-match"));
   assertNotNull(selectedPods);
   assertNotNull(selectedPods.getItems());
   assertEquals(0, selectedPods.getItems().size());
 }
 @Test
 public void testGetSelectedPodsEmpty() {
   PodList selectedPods = getClient().getSelectedPods(pod.getLabels());
   assertNotNull(selectedPods);
   assertNotNull(selectedPods.getItems());
   assertEquals(0, selectedPods.getItems().size());
 }
 @Test
 public void testGetSelectedPodsWithEmptyLabel() throws Exception {
   PodList selectedPods = getClient().getSelectedPods(Collections.<String, String>emptyMap());
   PodList allPods = getClient().getAllPods();
   assertNotNull(selectedPods);
   assertNotNull(selectedPods.getItems());
   assertEquals(allPods.getItems().size(), selectedPods.getItems().size());
 }
 @Test
 public void testGetSelectedPods() throws Exception {
   getClient().createPod(pod);
   PodList selectedPods = getClient().getSelectedPods(pod.getLabels());
   assertNotNull(selectedPods);
   assertNotNull(selectedPods.getItems());
   assertEquals(1, selectedPods.getItems().size());
 }
  @Test
  public void testUpdateReplicationControllerToZero() throws Exception {
    getClient().createReplicationController(contr);
    getClient().updateReplicationController(contr.getId(), 0);

    Thread.sleep(10000);

    PodList podList = getClient().getSelectedPods(contr.getLabels());
    assertNotNull(podList);
    assertNotNull(podList.getItems());
    assertEquals(0, podList.getItems().size());
  }
 @Test
 public void testGetAllPods() throws Exception {
   if (log.isDebugEnabled()) {
     log.debug("Get all Pods ");
   }
   getClient().createPod(pod);
   PodList podList = getClient().getAllPods();
   assertNotNull(podList);
   List<Pod> currentPods;
   assertNotNull(currentPods = podList.getItems());
   boolean match = false;
   for (Pod pod2 : currentPods) {
     if (pod.getId().equals(pod2.getId())) {
       match = true;
       break;
     }
   }
   assertEquals(true, match);
 }
  @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());
  }