Search in sources :

Example 11 with TestCondition

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");
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) InetSocketAddress(java.net.InetSocketAddress) TestCondition(org.apache.kafka.test.TestCondition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MockTime(org.apache.kafka.common.utils.MockTime)

Aggregations

TestCondition (org.apache.kafka.test.TestCondition)11 Test (org.junit.Test)7 KafkaStreams (org.apache.kafka.streams.KafkaStreams)5 KStreamBuilder (org.apache.kafka.streams.kstream.KStreamBuilder)5 Metrics (org.apache.kafka.common.metrics.Metrics)4 Field (java.lang.reflect.Field)3 StreamsConfig (org.apache.kafka.streams.StreamsConfig)3 DefaultKafkaClientSupplier (org.apache.kafka.streams.processor.internals.DefaultKafkaClientSupplier)3 StreamThread (org.apache.kafka.streams.processor.internals.StreamThread)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)1 MockTime (org.apache.kafka.common.utils.MockTime)1 KafkaStreamsTest (org.apache.kafka.streams.KafkaStreamsTest)1 KeyValue (org.apache.kafka.streams.KeyValue)1 InvalidStateStoreException (org.apache.kafka.streams.errors.InvalidStateStoreException)1