use of io.kubernetes.client.PortForward.PortForwardResult in project java by kubernetes-client.
the class PortForwardTest method testBrokenPortPassing.
@Test
public void testBrokenPortPassing() throws IOException, InterruptedException {
WebSocketStreamHandler handler = new WebSocketStreamHandler();
List<Integer> ports = new ArrayList<>();
ports.add(80);
final PortForwardResult result = new PortForwardResult(handler, ports);
String msgData = "this is a test datum";
handler.open("wss", null);
handler.bytesMessage(makeStream(new byte[] { 66 }, msgData.getBytes(StandardCharsets.UTF_8)));
final Object block = new Object();
Thread t = new Thread(() -> {
try {
result.init();
} catch (IOException ex) {
thrownException = ex;
} finally {
synchronized (block) {
block.notifyAll();
}
}
});
synchronized (block) {
t.start();
Thread.sleep(2000);
handler.close();
block.wait();
}
assertNotNull(thrownException);
assertTrue(thrownException instanceof IOException);
}
use of io.kubernetes.client.PortForward.PortForwardResult in project java by kubernetes-client.
the class PortForwardTest method testPortForwardResult.
@Test
public void testPortForwardResult() throws IOException, InterruptedException {
WebSocketStreamHandler handler = new WebSocketStreamHandler();
List<Integer> ports = new ArrayList<>();
ports.add(80);
ports.add(800);
final PortForwardResult result = new PortForwardResult(handler, ports);
String msgData = "this is a test datum";
String msgData2 = "this is a different test datum";
handler.open("wss", null);
handler.bytesMessage(makeStream(new byte[] { 0, 80, 0 }, msgData.getBytes(StandardCharsets.UTF_8)));
handler.bytesMessage(makeStream(new byte[] { 2, 32, 3 }, msgData2.getBytes(StandardCharsets.UTF_8)));
final Object block = new Object();
Thread t = new Thread(new Runnable() {
public void run() {
try {
result.init();
synchronized (block) {
block.notifyAll();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
synchronized (block) {
t.start();
block.wait();
}
InputStream is = result.getInputStream(80);
assertNotNull(is);
InputStream is2 = result.getInputStream(800);
assertNotNull(is2);
byte[] bytes = new byte[msgData.length()];
for (int i = 0; i < msgData.length(); i++) {
bytes[i] = (byte) is.read();
}
assertEquals(msgData, new String(bytes, StandardCharsets.UTF_8));
bytes = new byte[msgData2.length()];
for (int i = 0; i < msgData2.length(); i++) {
bytes[i] = (byte) is2.read();
}
assertEquals(msgData2, new String(bytes, StandardCharsets.UTF_8));
assertEquals(null, result.getInputStream(8080));
assertEquals(null, result.getErrorStream(8080));
assertEquals(null, result.getOutboundStream(8080));
}
Aggregations