Search in sources :

Example 1 with ExecProcess

use of io.kubernetes.client.Exec.ExecProcess in project java by kubernetes-client.

the class ExecTest method testExecProcess.

@Test
public void testExecProcess() throws IOException, InterruptedException {
    final ExecProcess process = new ExecProcess(client);
    process.getHandler().open("wss", null);
    String msgData = "This is the stdout message";
    String errData = "This is the stderr message";
    process.getHandler().bytesMessage(makeStream(1, msgData.getBytes(StandardCharsets.UTF_8)));
    process.getHandler().bytesMessage(makeStream(2, errData.getBytes(StandardCharsets.UTF_8)));
    final ByteArrayOutputStream stdout = new ByteArrayOutputStream();
    final ByteArrayOutputStream stderr = new ByteArrayOutputStream();
    CountDownLatch cLatch = new CountDownLatch(2);
    Thread t1 = asyncCopy(process.getInputStream(), stdout, cLatch);
    Thread t2 = asyncCopy(process.getErrorStream(), stderr, cLatch);
    process.getHandler().bytesMessage(makeStream(3, OUTPUT_EXIT0.getBytes(StandardCharsets.UTF_8)));
    cLatch.await();
    process.destroy();
    assertEquals(msgData, stdout.toString());
    assertEquals(errData, stderr.toString());
    assertEquals(false, process.isAlive());
    assertEquals(0, process.exitValue());
}
Also used : ExecProcess(io.kubernetes.client.Exec.ExecProcess) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

ExecProcess (io.kubernetes.client.Exec.ExecProcess)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1