@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()); }