use of org.apache.kafka.test.TestCondition in project kafka by apache.
the class SslTransportLayerTest method testClose.
private void testClose(SecurityProtocol securityProtocol, ChannelBuilder clientChannelBuilder) throws Exception {
String node = "0";
server = createEchoServer(securityProtocol);
clientChannelBuilder.configure(sslClientConfigs);
this.selector = new Selector(5000, new Metrics(), new MockTime(), "MetricGroup", clientChannelBuilder);
InetSocketAddress addr = new InetSocketAddress("localhost", server.port());
selector.connect(node, addr, BUFFER_SIZE, BUFFER_SIZE);
NetworkTestUtils.waitForChannelReady(selector, node);
final ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
server.outputChannel(Channels.newChannel(bytesOut));
server.selector().muteAll();
byte[] message = TestUtils.randomString(100).getBytes();
int count = 20;
final int totalSendSize = count * (message.length + 4);
for (int i = 0; i < count; i++) {
selector.send(new NetworkSend(node, ByteBuffer.wrap(message)));
do {
selector.poll(0L);
} while (selector.completedSends().isEmpty());
}
server.selector().unmuteAll();
selector.close(node);
TestUtils.waitForCondition(new TestCondition() {
@Override
public boolean conditionMet() {
return bytesOut.toByteArray().length == totalSendSize;
}
}, 5000, "All requests sent were not processed");
}
Aggregations