@Test(expected = KubernetesClientException.class)
 public void testCreateInvalidReplicationController() throws Exception {
   // create an invalid Controller
   ReplicationController bogusContr = new ReplicationController();
   bogusContr.setId("xxxxx");
   getClient().createReplicationController(bogusContr);
 }
  private ReplicationController getReplicationController() {
    ReplicationController contr = new ReplicationController();
    contr.setId("kubernetes-test-controller");
    State desiredState = new State();
    desiredState.setReplicas(2);

    Selector selector = new Selector();
    selector.setName("kubernetes-test-controller-selector");
    desiredState.setReplicaSelector(selector);

    Pod podTemplate = new Pod();
    State podState = new State();
    Manifest manifest = new Manifest();
    manifest.setId(contr.getId());
    Container container = new Container();
    container.setName("kubernetes-test");
    container.setImage(dockerImage);
    Port p = new Port();
    p.setContainerPort(80);
    container.setPorts(Collections.singletonList(p));
    container.setCommand("tail", "-f", "/dev/null");
    manifest.setContainers(Collections.singletonList(container));
    podState.setManifest(manifest);
    podTemplate.setDesiredState(podState);
    podTemplate.setLabels(ImmutableMap.of("name", selector.getName()));

    desiredState.setPodTemplate(podTemplate);
    contr.setDesiredState(desiredState);
    contr.setLabels(podTemplate.getLabels());
    return contr;
  }
  @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 testDeleteReplicationController() throws Exception {
   getClient().createReplicationController(contr);
   getClient().deleteReplicationController(contr.getId());
   assertNull(getClient().getReplicationController(contr.getId()));
 }
 @Test(expected = KubernetesClientException.class)
 public void testUpdateReplicationControllerWithBadCount() throws Exception {
   // test incorrect replica count
   getClient().createReplicationController(contr);
   getClient().updateReplicationController(contr.getId(), -1);
 }
  @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());
  }