Search in sources :

Example 41 with MockTime

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

the class MeteredKeyValueBytesStoreTest method before.

@Before
public void before() {
    metered = new MeteredKeyValueBytesStore<>(inner, "scope", new MockTime(), Serdes.String(), Serdes.String());
    tags.put("task-id", taskId.toString());
    tags.put("scope-id", "metered");
    metrics.config().recordLevel(Sensor.RecordingLevel.DEBUG);
    EasyMock.expect(context.metrics()).andReturn(new MockStreamsMetrics(metrics));
    EasyMock.expect(context.taskId()).andReturn(taskId);
    EasyMock.expect(inner.name()).andReturn("metered").anyTimes();
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) MockTime(org.apache.kafka.common.utils.MockTime) Before(org.junit.Before)

Example 42 with MockTime

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

the class MeteredSessionStoreTest method before.

@Before
public void before() {
    metered = new MeteredSessionStore<>(inner, "scope", Serdes.String(), Serdes.String(), new MockTime());
    tags.put("task-id", taskId.toString());
    tags.put("scope-id", "metered");
    metrics.config().recordLevel(Sensor.RecordingLevel.DEBUG);
    EasyMock.expect(context.metrics()).andReturn(new MockStreamsMetrics(metrics));
    EasyMock.expect(context.taskId()).andReturn(taskId);
    EasyMock.expect(inner.name()).andReturn("metered").anyTimes();
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) MockTime(org.apache.kafka.common.utils.MockTime) Before(org.junit.Before)

Example 43 with MockTime

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

the class FileRecordsTest method setup.

@Before
public void setup() throws IOException {
    this.fileRecords = createFileRecords(values);
    this.time = new MockTime();
}
Also used : MockTime(org.apache.kafka.common.utils.MockTime) Before(org.junit.Before)

Example 44 with MockTime

use of org.apache.kafka.common.utils.MockTime 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 45 with MockTime

use of org.apache.kafka.common.utils.MockTime 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)

Aggregations

MockTime (org.apache.kafka.common.utils.MockTime)363 Test (org.junit.Test)156 Test (org.junit.jupiter.api.Test)134 HashMap (java.util.HashMap)104 Time (org.apache.kafka.common.utils.Time)98 MockClient (org.apache.kafka.clients.MockClient)73 Cluster (org.apache.kafka.common.Cluster)73 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)65 Node (org.apache.kafka.common.Node)56 Metrics (org.apache.kafka.common.metrics.Metrics)56 TopicPartition (org.apache.kafka.common.TopicPartition)55 LogContext (org.apache.kafka.common.utils.LogContext)50 StreamsConfig (org.apache.kafka.streams.StreamsConfig)49 Before (org.junit.Before)38 Metadata (org.apache.kafka.clients.Metadata)32 MockScheduler (org.apache.kafka.common.utils.MockScheduler)31 MetadataResponse (org.apache.kafka.common.requests.MetadataResponse)30 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)30 ProducerMetadata (org.apache.kafka.clients.producer.internals.ProducerMetadata)29 Properties (java.util.Properties)27