use of io.aklivity.zilla.runtime.engine.test.annotation.Configuration in project zilla by aklivity.
the class ServerIT method shouldReceiveServerSentDataAndEnd.
@Test
@Configuration("server.json")
@Specification({ "${app}/server.sent.data.then.end/server" // No support for "read closed" in k3po tcp
})
public void shouldReceiveServerSentDataAndEnd() throws Exception {
k3po.start();
try (SocketChannel channel = SocketChannel.open()) {
channel.connect(new InetSocketAddress("127.0.0.1", 8080));
ByteBuffer buf = ByteBuffer.allocate(256);
channel.read(buf);
buf.flip();
assertEquals("server data", UTF_8.decode(buf).toString());
buf.rewind();
int len = channel.read(buf);
assertEquals(-1, len);
k3po.finish();
}
}
use of io.aklivity.zilla.runtime.engine.test.annotation.Configuration in project zilla by aklivity.
the class ServerIT method shouldReceiveClientSentDataAndEnd.
@Test
@Configuration("server.json")
@Specification({ "${app}/client.sent.data.then.end/server" // No support for "write close" in k3po tcp
})
public void shouldReceiveClientSentDataAndEnd() throws Exception {
k3po.start();
try (SocketChannel channel = SocketChannel.open()) {
channel.connect(new InetSocketAddress("127.0.0.1", 8080));
channel.write(UTF_8.encode("client data"));
channel.shutdownOutput();
k3po.finish();
}
}
use of io.aklivity.zilla.runtime.engine.test.annotation.Configuration in project zilla by aklivity.
the class ServerIT method shouldReceiveDataAfterSendingEnd.
@Test
@Configuration("server.json")
@Specification({ "${app}/server.sent.end.then.received.data/server" // No support for "read closed" in k3po tcp
})
public void shouldReceiveDataAfterSendingEnd() throws Exception {
k3po.start();
try (SocketChannel channel = SocketChannel.open()) {
channel.connect(new InetSocketAddress("127.0.0.1", 8080));
ByteBuffer buf = ByteBuffer.allocate(256);
int len = channel.read(buf);
buf.flip();
assertEquals(-1, len);
channel.write(UTF_8.encode("client data"));
k3po.finish();
}
}
use of io.aklivity.zilla.runtime.engine.test.annotation.Configuration in project zilla by aklivity.
the class ServerPartialWriteIT method shouldHandleEndOfStreamWithPendingWrite.
@Test
@Configuration("server.json")
@Specification({ "${server}/server.sent.data.then.end/server" })
public void shouldHandleEndOfStreamWithPendingWrite() throws Exception {
AtomicBoolean endWritten = new AtomicBoolean(false);
OnDataHelper.fragmentWrites(concat(of(5), generate(() -> 0)));
HandleWriteHelper.fragmentWrites(generate(() -> endWritten.get() ? ALL : 0));
k3po.start();
try (SocketChannel channel = SocketChannel.open()) {
channel.connect(new InetSocketAddress("127.0.0.1", 8080));
k3po.awaitBarrier("END_WRITTEN");
endWritten.set(true);
ByteBuffer buf = ByteBuffer.allocate("server data".length() + 10);
boolean closed = false;
do {
int len = channel.read(buf);
if (len == -1) {
closed = true;
break;
}
} while (buf.position() < "server data".length());
buf.flip();
assertEquals("server data", UTF_8.decode(buf).toString());
if (!closed) {
buf.rewind();
closed = channel.read(buf) == -1;
}
assertTrue("Stream was not closed", closed);
k3po.finish();
}
}
use of io.aklivity.zilla.runtime.engine.test.annotation.Configuration in project zilla by aklivity.
the class ServerPartialWriteIT method shouldPartiallyWriteWhenMoreDataArrivesWhileAwaitingSocketWritable.
@Test
@Configuration("server.json")
@Specification({ "${server}/server.sent.data.multiple.frames/server", "${client}/server.sent.data.multiple.frames/client" })
public void shouldPartiallyWriteWhenMoreDataArrivesWhileAwaitingSocketWritable() throws Exception {
// processData will be called for each of the two data frames. Make the first and second
// each do a partial write, then write nothing until handleWrite is called after the
// second processData call, when we write everything.
AtomicBoolean finishWrite = new AtomicBoolean(false);
OnDataHelper.fragmentWrites(concat(of(5), generate(() -> finishWrite.getAndSet(true) ? 0 : 15)));
HandleWriteHelper.fragmentWrites(generate(() -> finishWrite.get() ? ALL : 0));
k3po.finish();
}
Aggregations