Search in sources :

Example 6 with LogContext

use of org.apache.kafka.common.utils.LogContext in project apache-kafka-on-k8s by banzaicloud.

the class RocksDBStoreTest method setUp.

@Before
public void setUp() {
    rocksDBStore = new RocksDBStore("test");
    dir = TestUtils.tempDirectory();
    context = new InternalMockProcessorContext(dir, Serdes.String(), Serdes.String(), new NoOpRecordCollector(), new ThreadCache(new LogContext("testCache "), 0, new MockStreamsMetrics(new Metrics())));
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) Before(org.junit.Before)

Example 7 with LogContext

use of org.apache.kafka.common.utils.LogContext in project apache-kafka-on-k8s by banzaicloud.

the class SegmentsTest method createContext.

@Before
public void createContext() {
    stateDirectory = TestUtils.tempDirectory();
    context = new InternalMockProcessorContext(stateDirectory, Serdes.String(), Serdes.Long(), new NoOpRecordCollector(), new ThreadCache(new LogContext("testCache "), 0, new MockStreamsMetrics(new Metrics())));
    segments = new Segments(storeName, retentionPeriod, NUM_SEGMENTS);
    segmentInterval = Segments.segmentInterval(retentionPeriod, NUM_SEGMENTS);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) Before(org.junit.Before)

Example 8 with LogContext

use of org.apache.kafka.common.utils.LogContext in project apache-kafka-on-k8s by banzaicloud.

the class SslTransportLayerTest method testIOExceptionsDuringHandshake.

private void testIOExceptionsDuringHandshake(boolean failRead, boolean failWrite) throws Exception {
    server = createEchoServer(SecurityProtocol.SSL);
    TestSslChannelBuilder channelBuilder = new TestSslChannelBuilder(Mode.CLIENT);
    boolean done = false;
    for (int i = 1; i <= 100; i++) {
        int readFailureIndex = failRead ? i : Integer.MAX_VALUE;
        int flushFailureIndex = failWrite ? i : Integer.MAX_VALUE;
        String node = String.valueOf(i);
        channelBuilder.readFailureIndex = readFailureIndex;
        channelBuilder.flushFailureIndex = flushFailureIndex;
        channelBuilder.configure(sslClientConfigs);
        this.selector = new Selector(5000, new Metrics(), new MockTime(), "MetricGroup", channelBuilder, new LogContext());
        InetSocketAddress addr = new InetSocketAddress("localhost", server.port());
        selector.connect(node, addr, BUFFER_SIZE, BUFFER_SIZE);
        for (int j = 0; j < 30; j++) {
            selector.poll(1000L);
            KafkaChannel channel = selector.channel(node);
            if (channel != null && channel.ready()) {
                done = true;
                break;
            }
            if (selector.disconnected().containsKey(node)) {
                assertEquals(ChannelState.State.AUTHENTICATE, selector.disconnected().get(node).state());
                break;
            }
        }
        KafkaChannel channel = selector.channel(node);
        if (channel != null)
            assertTrue("Channel not ready or disconnected:" + channel.state().state(), channel.ready());
    }
    assertTrue("Too many invocations of read/write during SslTransportLayer.handshake()", done);
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) InetSocketAddress(java.net.InetSocketAddress) LogContext(org.apache.kafka.common.utils.LogContext) MockTime(org.apache.kafka.common.utils.MockTime)

Example 9 with LogContext

use of org.apache.kafka.common.utils.LogContext in project apache-kafka-on-k8s by banzaicloud.

the class SelectorTest method setUp.

@Before
public void setUp() throws Exception {
    Map<String, Object> configs = new HashMap<>();
    this.server = new EchoServer(SecurityProtocol.PLAINTEXT, configs);
    this.server.start();
    this.time = new MockTime();
    this.channelBuilder = new PlaintextChannelBuilder();
    this.channelBuilder.configure(configs);
    this.metrics = new Metrics();
    this.selector = new Selector(5000, this.metrics, time, "MetricGroup", channelBuilder, new LogContext());
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) HashMap(java.util.HashMap) LogContext(org.apache.kafka.common.utils.LogContext) MockTime(org.apache.kafka.common.utils.MockTime) Before(org.junit.Before)

Example 10 with LogContext

use of org.apache.kafka.common.utils.LogContext in project apache-kafka-on-k8s by banzaicloud.

the class SelectorTest method registerFailure.

@Test
public void registerFailure() throws Exception {
    ChannelBuilder channelBuilder = new PlaintextChannelBuilder() {

        @Override
        public KafkaChannel buildChannel(String id, SelectionKey key, int maxReceiveSize, MemoryPool memoryPool) throws KafkaException {
            throw new RuntimeException("Test exception");
        }

        @Override
        public void close() {
        }
    };
    Selector selector = new Selector(5000, new Metrics(), new MockTime(), "MetricGroup", channelBuilder, new LogContext());
    SocketChannel socketChannel = SocketChannel.open();
    socketChannel.configureBlocking(false);
    try {
        selector.register("1", socketChannel);
        fail("Register did not fail");
    } catch (IOException e) {
        assertTrue("Unexpected exception: " + e, e.getCause().getMessage().contains("Test exception"));
        assertFalse("Socket not closed", socketChannel.isOpen());
    }
    selector.close();
}
Also used : SelectionKey(java.nio.channels.SelectionKey) SocketChannel(java.nio.channels.SocketChannel) ServerSocketChannel(java.nio.channels.ServerSocketChannel) Metrics(org.apache.kafka.common.metrics.Metrics) LogContext(org.apache.kafka.common.utils.LogContext) IOException(java.io.IOException) MockTime(org.apache.kafka.common.utils.MockTime) MemoryPool(org.apache.kafka.common.memory.MemoryPool) SimpleMemoryPool(org.apache.kafka.common.memory.SimpleMemoryPool) Test(org.junit.Test)

Aggregations

LogContext (org.apache.kafka.common.utils.LogContext)53 Metrics (org.apache.kafka.common.metrics.Metrics)28 Test (org.junit.Test)27 Before (org.junit.Before)17 InternalMockProcessorContext (org.apache.kafka.test.InternalMockProcessorContext)14 MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)13 NoOpRecordCollector (org.apache.kafka.test.NoOpRecordCollector)10 HashMap (java.util.HashMap)8 MockTime (org.apache.kafka.common.utils.MockTime)8 InetSocketAddress (java.net.InetSocketAddress)7 Properties (java.util.Properties)7 StreamsConfig (org.apache.kafka.streams.StreamsConfig)7 TopicPartition (org.apache.kafka.common.TopicPartition)6 File (java.io.File)5 NetworkClient (org.apache.kafka.clients.NetworkClient)5 InternalStreamsBuilderTest (org.apache.kafka.streams.kstream.internals.InternalStreamsBuilderTest)5 ServerSocketChannel (java.nio.channels.ServerSocketChannel)4 SocketChannel (java.nio.channels.SocketChannel)4 Metadata (org.apache.kafka.clients.Metadata)4 MockClient (org.apache.kafka.clients.MockClient)4