use of org.apache.kafka.common.utils.LogContext 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);
}
use of org.apache.kafka.common.utils.LogContext 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);
}
use of org.apache.kafka.common.utils.LogContext in project apache-kafka-on-k8s by banzaicloud.
the class RecordCollectorTest method testStreamPartitioner.
@Test
public void testStreamPartitioner() {
final RecordCollectorImpl collector = new RecordCollectorImpl(new MockProducer<>(cluster, true, new DefaultPartitioner(), byteArraySerializer, byteArraySerializer), "RecordCollectorTest-TestStreamPartitioner", new LogContext("RecordCollectorTest-TestStreamPartitioner "), new DefaultProductionExceptionHandler());
collector.send("topic1", "3", "0", null, stringSerializer, stringSerializer, streamPartitioner);
collector.send("topic1", "9", "0", null, stringSerializer, stringSerializer, streamPartitioner);
collector.send("topic1", "27", "0", null, stringSerializer, stringSerializer, streamPartitioner);
collector.send("topic1", "81", "0", null, stringSerializer, stringSerializer, streamPartitioner);
collector.send("topic1", "243", "0", null, stringSerializer, stringSerializer, streamPartitioner);
collector.send("topic1", "28", "0", null, stringSerializer, stringSerializer, streamPartitioner);
collector.send("topic1", "82", "0", null, stringSerializer, stringSerializer, streamPartitioner);
collector.send("topic1", "244", "0", null, stringSerializer, stringSerializer, streamPartitioner);
collector.send("topic1", "245", "0", null, stringSerializer, stringSerializer, streamPartitioner);
final Map<TopicPartition, Long> offsets = collector.offsets();
assertEquals((Long) 4L, offsets.get(new TopicPartition("topic1", 0)));
assertEquals((Long) 2L, offsets.get(new TopicPartition("topic1", 1)));
assertEquals((Long) 0L, offsets.get(new TopicPartition("topic1", 2)));
}
use of org.apache.kafka.common.utils.LogContext in project apache-kafka-on-k8s by banzaicloud.
the class RecordCollectorTest method testSpecificPartition.
@Test
public void testSpecificPartition() {
final RecordCollectorImpl collector = new RecordCollectorImpl(new MockProducer<>(cluster, true, new DefaultPartitioner(), byteArraySerializer, byteArraySerializer), "RecordCollectorTest-TestSpecificPartition", new LogContext("RecordCollectorTest-TestSpecificPartition "), new DefaultProductionExceptionHandler());
collector.send("topic1", "999", "0", 0, null, stringSerializer, stringSerializer);
collector.send("topic1", "999", "0", 0, null, stringSerializer, stringSerializer);
collector.send("topic1", "999", "0", 0, null, stringSerializer, stringSerializer);
collector.send("topic1", "999", "0", 1, null, stringSerializer, stringSerializer);
collector.send("topic1", "999", "0", 1, null, stringSerializer, stringSerializer);
collector.send("topic1", "999", "0", 2, null, stringSerializer, stringSerializer);
final Map<TopicPartition, Long> offsets = collector.offsets();
assertEquals((Long) 2L, offsets.get(new TopicPartition("topic1", 0)));
assertEquals((Long) 1L, offsets.get(new TopicPartition("topic1", 1)));
assertEquals((Long) 0L, offsets.get(new TopicPartition("topic1", 2)));
// ignore StreamPartitioner
collector.send("topic1", "999", "0", 0, null, stringSerializer, stringSerializer);
collector.send("topic1", "999", "0", 1, null, stringSerializer, stringSerializer);
collector.send("topic1", "999", "0", 2, null, stringSerializer, stringSerializer);
assertEquals((Long) 3L, offsets.get(new TopicPartition("topic1", 0)));
assertEquals((Long) 2L, offsets.get(new TopicPartition("topic1", 1)));
assertEquals((Long) 1L, offsets.get(new TopicPartition("topic1", 2)));
}
use of org.apache.kafka.common.utils.LogContext in project apache-kafka-on-k8s by banzaicloud.
the class RecordQueueTest method shouldThrowOnNegativeTimestamp.
@Test(expected = StreamsException.class)
public void shouldThrowOnNegativeTimestamp() {
final List<ConsumerRecord<byte[], byte[]>> records = Collections.singletonList(new ConsumerRecord<>("topic", 1, 1, -1L, TimestampType.CREATE_TIME, 0L, 0, 0, recordKey, recordValue));
final RecordQueue queue = new RecordQueue(new TopicPartition(topics[0], 1), new MockSourceNode<>(topics, intDeserializer, intDeserializer), new FailOnInvalidTimestamp(), new LogAndContinueExceptionHandler(), null, new LogContext());
queue.addRawRecords(records);
}
Aggregations