Search in sources :

Example 11 with Bytes

use of org.apache.kafka.common.utils.Bytes in project kafka by apache.

the class CachingSessionStore method put.

@Override
public void put(final Windowed<K> key, AGG value) {
    validateStoreOpen();
    final Bytes binaryKey = SessionKeySerde.toBinary(key, keySerde.serializer());
    final LRUCacheEntry entry = new LRUCacheEntry(serdes.rawValue(value), true, context.offset(), key.window().end(), context.partition(), context.topic());
    cache.put(cacheName, binaryKey, entry);
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes)

Example 12 with Bytes

use of org.apache.kafka.common.utils.Bytes in project kafka by apache.

the class CachingWindowStore method put.

@Override
public synchronized void put(final K key, final V value, final long timestamp) {
    // since this function may not access the underlying inner store, we need to validate
    // if store is open outside as well.
    validateStoreOpen();
    final Bytes keyBytes = WindowStoreUtils.toBinaryKey(key, timestamp, 0, serdes);
    final LRUCacheEntry entry = new LRUCacheEntry(serdes.rawValue(value), true, context.offset(), timestamp, context.partition(), context.topic());
    cache.put(name, keyBytes, entry);
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes)

Example 13 with Bytes

use of org.apache.kafka.common.utils.Bytes in project kafka by apache.

the class SessionKeySerdeTest method shouldExtractKeyFromBinary.

@Test
public void shouldExtractKeyFromBinary() throws Exception {
    final Bytes serialized = SessionKeySerde.toBinary(windowedKey, serde.serializer());
    assertEquals(windowedKey, SessionKeySerde.from(serialized.get(), serde.deserializer()));
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) Test(org.junit.Test)

Example 14 with Bytes

use of org.apache.kafka.common.utils.Bytes in project kafka by apache.

the class SessionKeySerdeTest method shouldExtractKeyBytesFromBinary.

@Test
public void shouldExtractKeyBytesFromBinary() throws Exception {
    final Bytes serialized = SessionKeySerde.toBinary(windowedKey, serde.serializer());
    assertArrayEquals(key.getBytes(), SessionKeySerde.extractKeyBytes(serialized.get()));
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) Test(org.junit.Test)

Example 15 with Bytes

use of org.apache.kafka.common.utils.Bytes in project kafka by apache.

the class SessionKeySerdeTest method shouldExtractBytesKeyFromBinary.

@Test
public void shouldExtractBytesKeyFromBinary() throws Exception {
    final Bytes bytesKey = Bytes.wrap(key.getBytes());
    final Windowed<Bytes> windowedBytesKey = new Windowed<>(bytesKey, window);
    final Bytes serialized = SessionKeySerde.bytesToBinary(windowedBytesKey);
    assertEquals(windowedBytesKey, SessionKeySerde.fromBytes(serialized));
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) Bytes(org.apache.kafka.common.utils.Bytes) Test(org.junit.Test)

Aggregations

Bytes (org.apache.kafka.common.utils.Bytes)54 Test (org.junit.Test)34 Metrics (org.apache.kafka.common.metrics.Metrics)14 MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)14 Windowed (org.apache.kafka.streams.kstream.Windowed)5 ArrayList (java.util.ArrayList)4 KeyValue (org.apache.kafka.streams.KeyValue)4 SessionWindow (org.apache.kafka.streams.kstream.internals.SessionWindow)3 MockProcessorContext (org.apache.kafka.test.MockProcessorContext)3 ByteBuffer (java.nio.ByteBuffer)2 NoSuchElementException (java.util.NoSuchElementException)2 ProcessorRecordContext (org.apache.kafka.streams.processor.internals.ProcessorRecordContext)2 KeyValueIterator (org.apache.kafka.streams.state.KeyValueIterator)2 Before (org.junit.Before)2 MockProducer (org.apache.kafka.clients.producer.MockProducer)1 Serializer (org.apache.kafka.common.serialization.Serializer)1 StreamsException (org.apache.kafka.streams.errors.StreamsException)1 RecordContext (org.apache.kafka.streams.processor.internals.RecordContext)1 StateSerdes (org.apache.kafka.streams.state.StateSerdes)1