Skip to content

Commit

Permalink
Merge pull request #1026 from rohanKanojia/issue975
Browse files Browse the repository at this point in the history
  • Loading branch information
fusesource-ci authored Mar 13, 2018
2 parents 25ba0c6 + 3902fd7 commit 30af800
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import io.fabric8.kubernetes.api.model.PodBuilder;
import io.fabric8.kubernetes.api.model.PodList;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.ExecListener;
import io.fabric8.kubernetes.client.dsl.ExecWatch;
import okhttp3.Response;
import org.apache.commons.lang.RandomStringUtils;
import org.arquillian.cube.kubernetes.api.Session;
import org.arquillian.cube.kubernetes.impl.requirement.RequiresKubernetes;
Expand All @@ -32,6 +35,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayOutputStream;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import static junit.framework.TestCase.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -120,6 +127,43 @@ public void delete() {
assertTrue(client.pods().inNamespace(currentNamespace).delete(pod1));
}

@Test
public void log() throws InterruptedException {
client.pods().inNamespace(currentNamespace).withName(pod1.getMetadata().getName()).waitUntilReady(10, TimeUnit.MINUTES);
String log = client.pods().inNamespace(currentNamespace).withName(pod1.getMetadata().getName()).getLog();
assertNotNull(log);
}

@Test
public void exec() throws InterruptedException {
client.pods().inNamespace(currentNamespace).withName(pod1.getMetadata().getName()).waitUntilReady(10, TimeUnit.MINUTES);
final CountDownLatch execLatch = new CountDownLatch(1);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ExecWatch execWatch = client.pods().inNamespace(currentNamespace).withName(pod1.getMetadata().getName())
.writingOutput(out).withTTY().usingListener(new ExecListener() {
@Override
public void onOpen(Response response) {
logger.info("Shell was opened");
}

@Override
public void onFailure(Throwable throwable, Response response) {
logger.info("Shell barfed");
execLatch.countDown();
}

@Override
public void onClose(int i, String s) {
logger.info("Shell closed");
execLatch.countDown();
}
}).exec("date");

execLatch.await(5, TimeUnit.MINUTES);
assertNotNull(execWatch);
assertNotNull(out.toString());
}

@After
public void cleanup() throws InterruptedException {
client.pods().inNamespace(currentNamespace).withName(pod1.getMetadata().getName()).delete();
Expand Down

0 comments on commit 30af800

Please sign in to comment.