Search in sources :

Example 26 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project apache-kafka-on-k8s by banzaicloud.

the class CachingSessionStoreTest method setUp.

@Before
public void setUp() {
    final SessionKeySchema schema = new SessionKeySchema();
    schema.init("topic");
    final int retention = 60000;
    final int numSegments = 3;
    underlying = new RocksDBSegmentedBytesStore("test", retention, numSegments, schema);
    final RocksDBSessionStore<Bytes, byte[]> sessionStore = new RocksDBSessionStore<>(underlying, Serdes.Bytes(), Serdes.ByteArray());
    cachingStore = new CachingSessionStore<>(sessionStore, Serdes.String(), Serdes.String(), Segments.segmentInterval(retention, numSegments));
    cache = new ThreadCache(new LogContext("testCache "), MAX_CACHE_SIZE_BYTES, new MockStreamsMetrics(new Metrics()));
    context = new InternalMockProcessorContext(TestUtils.tempDirectory(), null, null, null, cache);
    context.setRecordContext(new ProcessorRecordContext(DEFAULT_TIMESTAMP, 0, 0, "topic"));
    cachingStore.init(context, cachingStore);
}
Also used : LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Bytes(org.apache.kafka.common.utils.Bytes) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) ProcessorRecordContext(org.apache.kafka.streams.processor.internals.ProcessorRecordContext) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) Before(org.junit.Before)

Example 27 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project apache-kafka-on-k8s by banzaicloud.

the class CachingWindowStoreTest method setUp.

@Before
public void setUp() {
    keySchema = new WindowKeySchema();
    final int retention = 30000;
    final int numSegments = 3;
    underlying = new RocksDBSegmentedBytesStore("test", retention, numSegments, keySchema);
    final RocksDBWindowStore<Bytes, byte[]> windowStore = new RocksDBWindowStore<>(underlying, Serdes.Bytes(), Serdes.ByteArray(), false, WINDOW_SIZE);
    cacheListener = new CachingKeyValueStoreTest.CacheFlushListenerStub<>();
    cachingStore = new CachingWindowStore<>(windowStore, Serdes.String(), Serdes.String(), WINDOW_SIZE, Segments.segmentInterval(retention, numSegments));
    cachingStore.setFlushListener(cacheListener, false);
    cache = new ThreadCache(new LogContext("testCache "), MAX_CACHE_SIZE_BYTES, new MockStreamsMetrics(new Metrics()));
    topic = "topic";
    context = new InternalMockProcessorContext(TestUtils.tempDirectory(), null, null, (RecordCollector) null, cache);
    context.setRecordContext(new ProcessorRecordContext(DEFAULT_TIMESTAMP, 0, 0, topic));
    cachingStore.init(context, cachingStore);
}
Also used : RecordCollector(org.apache.kafka.streams.processor.internals.RecordCollector) LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Bytes(org.apache.kafka.common.utils.Bytes) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) ProcessorRecordContext(org.apache.kafka.streams.processor.internals.ProcessorRecordContext) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) Before(org.junit.Before)

Example 28 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project apache-kafka-on-k8s by banzaicloud.

the class ChangeLoggingKeyValueBytesStoreTest method before.

@Before
public void before() {
    final NoOpRecordCollector collector = new NoOpRecordCollector() {

        @Override
        public <K, V> void send(final String topic, K key, V value, Integer partition, Long timestamp, Serializer<K> keySerializer, Serializer<V> valueSerializer) {
            sent.put(key, value);
        }
    };
    context = new InternalMockProcessorContext(TestUtils.tempDirectory(), Serdes.String(), Serdes.Long(), collector, new ThreadCache(new LogContext("testCache "), 0, new MockStreamsMetrics(new Metrics())));
    context.setTime(0);
    store.init(context, store);
}
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) Serializer(org.apache.kafka.common.serialization.Serializer) Before(org.junit.Before)

Example 29 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project kafka by apache.

the class ProcessorNodeTest method testTopologyLevelClassCastExceptionDirect.

@Test
public void testTopologyLevelClassCastExceptionDirect() {
    final Metrics metrics = new Metrics();
    final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, "test-client", StreamsConfig.METRICS_LATEST, new MockTime());
    final InternalMockProcessorContext<Object, Object> context = new InternalMockProcessorContext<>(streamsMetrics);
    final ProcessorNode<Object, Object, Object, Object> node = new ProcessorNode<>("pname", new ClassCastProcessor(), Collections.emptySet());
    node.init(context);
    final StreamsException se = assertThrows(StreamsException.class, () -> node.process(new Record<>("aKey", "aValue", 0)));
    assertThat(se.getCause(), instanceOf(ClassCastException.class));
    assertThat(se.getMessage(), containsString("default Serdes"));
    assertThat(se.getMessage(), containsString("input types"));
    assertThat(se.getMessage(), containsString("pname"));
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) StreamsException(org.apache.kafka.streams.errors.StreamsException) Record(org.apache.kafka.streams.processor.api.Record) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.Test)

Example 30 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project kafka by apache.

the class RecordQueueTest method shouldThrowOnNegativeTimestamp.

@Test
public void shouldThrowOnNegativeTimestamp() {
    final List<ConsumerRecord<byte[], byte[]>> records = Collections.singletonList(new ConsumerRecord<>("topic", 1, 1, -1L, TimestampType.CREATE_TIME, 0, 0, recordKey, recordValue, new RecordHeaders(), Optional.empty()));
    final RecordQueue queue = new RecordQueue(new TopicPartition("topic", 1), mockSourceNodeWithMetrics, new FailOnInvalidTimestamp(), new LogAndContinueExceptionHandler(), new InternalMockProcessorContext(), new LogContext());
    final StreamsException exception = assertThrows(StreamsException.class, () -> queue.addRawRecords(records));
    assertThat(exception.getMessage(), equalTo("Input record ConsumerRecord(topic = topic, partition = 1, " + "leaderEpoch = null, offset = 1, CreateTime = -1, serialized key size = 0, serialized value size = 0, " + "headers = RecordHeaders(headers = [], isReadOnly = false), key = 1, value = 10) has invalid (negative) " + "timestamp. Possibly because a pre-0.10 producer client was used to write this record to Kafka without " + "embedding a timestamp, or because the input topic was created before upgrading the Kafka cluster to 0.10+. " + "Use a different TimestampExtractor to process this data."));
}
Also used : RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) TopicPartition(org.apache.kafka.common.TopicPartition) StreamsException(org.apache.kafka.streams.errors.StreamsException) FailOnInvalidTimestamp(org.apache.kafka.streams.processor.FailOnInvalidTimestamp) LogContext(org.apache.kafka.common.utils.LogContext) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) LogAndContinueExceptionHandler(org.apache.kafka.streams.errors.LogAndContinueExceptionHandler) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Test(org.junit.Test)

Aggregations

InternalMockProcessorContext (org.apache.kafka.test.InternalMockProcessorContext)44 Test (org.junit.Test)23 LogContext (org.apache.kafka.common.utils.LogContext)20 Metrics (org.apache.kafka.common.metrics.Metrics)19 Before (org.junit.Before)17 MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)14 NoOpRecordCollector (org.apache.kafka.test.NoOpRecordCollector)14 StreamsConfig (org.apache.kafka.streams.StreamsConfig)10 Properties (java.util.Properties)8 Bytes (org.apache.kafka.common.utils.Bytes)8 StateStore (org.apache.kafka.streams.processor.StateStore)7 File (java.io.File)6 MockTime (org.apache.kafka.common.utils.MockTime)6 ProcessorRecordContext (org.apache.kafka.streams.processor.internals.ProcessorRecordContext)6 ArrayList (java.util.ArrayList)5 RecordHeaders (org.apache.kafka.common.header.internals.RecordHeaders)5 Serializer (org.apache.kafka.common.serialization.Serializer)5 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)4 MetricName (org.apache.kafka.common.MetricName)4 HashMap (java.util.HashMap)3