use of org.apache.kafka.common.utils.LogContext in project apache-kafka-on-k8s by banzaicloud.
the class SslSelectorTest method testDisconnectWithIntermediateBufferedBytes.
@Test
public void testDisconnectWithIntermediateBufferedBytes() throws Exception {
int requestSize = 100 * 1024;
final String node = "0";
String request = TestUtils.randomString(requestSize);
this.selector.close();
this.channelBuilder = new TestSslChannelBuilder(Mode.CLIENT);
this.channelBuilder.configure(sslClientConfigs);
this.selector = new Selector(5000, metrics, time, "MetricGroup", channelBuilder, new LogContext());
connect(node, new InetSocketAddress("localhost", server.port));
selector.send(createSend(node, request));
TestUtils.waitForCondition(new TestCondition() {
@Override
public boolean conditionMet() {
try {
selector.poll(0L);
return selector.channel(node).hasBytesBuffered();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}, 2000L, "Failed to reach socket state with bytes buffered");
selector.close(node);
verifySelectorEmpty();
}
use of org.apache.kafka.common.utils.LogContext in project apache-kafka-on-k8s by banzaicloud.
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, new LogContext());
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");
}
use of org.apache.kafka.common.utils.LogContext in project apache-kafka-on-k8s by banzaicloud.
the class SslTransportLayerTest method testNetworkThreadTimeRecorded.
/**
* Tests that time spent on the network thread is accumulated on each channel
*/
@Test
public void testNetworkThreadTimeRecorded() throws Exception {
selector.close();
this.selector = new Selector(NetworkReceive.UNLIMITED, 5000, new Metrics(), Time.SYSTEM, "MetricGroup", new HashMap<String, String>(), false, true, channelBuilder, MemoryPool.NONE, new LogContext());
String node = "0";
server = createEchoServer(SecurityProtocol.SSL);
InetSocketAddress addr = new InetSocketAddress("localhost", server.port());
selector.connect(node, addr, BUFFER_SIZE, BUFFER_SIZE);
String message = TestUtils.randomString(1024 * 1024);
NetworkTestUtils.waitForChannelReady(selector, node);
KafkaChannel channel = selector.channel(node);
assertTrue("SSL handshake time not recorded", channel.getAndResetNetworkThreadTimeNanos() > 0);
assertEquals("Time not reset", 0, channel.getAndResetNetworkThreadTimeNanos());
selector.mute(node);
selector.send(new NetworkSend(node, ByteBuffer.wrap(message.getBytes())));
while (selector.completedSends().isEmpty()) {
selector.poll(100L);
}
long sendTimeNanos = channel.getAndResetNetworkThreadTimeNanos();
assertTrue("Send time not recorded: " + sendTimeNanos, sendTimeNanos > 0);
assertEquals("Time not reset", 0, channel.getAndResetNetworkThreadTimeNanos());
assertFalse("Unexpected bytes buffered", channel.hasBytesBuffered());
assertEquals(0, selector.completedReceives().size());
selector.unmute(node);
while (selector.completedReceives().isEmpty()) {
selector.poll(100L);
assertEquals(0, selector.numStagedReceives(channel));
}
long receiveTimeNanos = channel.getAndResetNetworkThreadTimeNanos();
assertTrue("Receive time not recorded: " + receiveTimeNanos, receiveTimeNanos > 0);
}
Aggregations