Search in sources :

Example 26 with Bytes

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

the class CachingWindowStoreTest method shouldIterateCacheAndStore.

@Test
public void shouldIterateCacheAndStore() throws Exception {
    final Bytes key = Bytes.wrap("1".getBytes());
    underlying.put(WindowStoreUtils.toBinaryKey(key, DEFAULT_TIMESTAMP, 0, WindowStoreUtils.INNER_SERDES), "a".getBytes());
    cachingStore.put("1", "b", DEFAULT_TIMESTAMP + WINDOW_SIZE);
    final WindowStoreIterator<String> fetch = cachingStore.fetch("1", DEFAULT_TIMESTAMP, DEFAULT_TIMESTAMP + WINDOW_SIZE);
    assertEquals(KeyValue.pair(DEFAULT_TIMESTAMP, "a"), fetch.next());
    assertEquals(KeyValue.pair(DEFAULT_TIMESTAMP + WINDOW_SIZE, "b"), fetch.next());
    assertFalse(fetch.hasNext());
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) Test(org.junit.Test)

Example 27 with Bytes

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

the class ChangeLoggingSegmentedBytesStoreTest method shouldLogPuts.

@SuppressWarnings("unchecked")
@Test
public void shouldLogPuts() throws Exception {
    final byte[] value1 = { 0 };
    final byte[] value2 = { 1 };
    final Bytes key1 = Bytes.wrap(value1);
    final Bytes key2 = Bytes.wrap(value2);
    store.put(key1, value1);
    store.put(key2, value2);
    store.flush();
    assertArrayEquals(value1, (byte[]) sent.get(key1));
    assertArrayEquals(value2, (byte[]) sent.get(key2));
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) Test(org.junit.Test)

Example 28 with Bytes

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

the class ChangeLoggingSegmentedBytesStoreTest method shouldLogRemoves.

@SuppressWarnings("unchecked")
@Test
public void shouldLogRemoves() throws Exception {
    final Bytes key1 = Bytes.wrap(new byte[] { 0 });
    final Bytes key2 = Bytes.wrap(new byte[] { 1 });
    store.remove(key1);
    store.remove(key2);
    store.flush();
    assertTrue(sent.containsKey(key1));
    assertTrue(sent.containsKey(key2));
    assertNull(sent.get(key1));
    assertNull(sent.get(key2));
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) Test(org.junit.Test)

Example 29 with Bytes

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

the class NamedCacheTest method shouldNotThrowIllegalArgumentAfterEvictingDirtyRecordAndThenPuttingNewRecordWithSameKey.

@Test
public void shouldNotThrowIllegalArgumentAfterEvictingDirtyRecordAndThenPuttingNewRecordWithSameKey() throws Exception {
    final LRUCacheEntry dirty = new LRUCacheEntry(new byte[] { 3 }, true, 0, 0, 0, "");
    final LRUCacheEntry clean = new LRUCacheEntry(new byte[] { 3 });
    final Bytes key = Bytes.wrap(new byte[] { 3 });
    cache.setListener(new ThreadCache.DirtyEntryFlushListener() {

        @Override
        public void apply(final List<ThreadCache.DirtyEntry> dirty) {
            cache.put(key, clean);
        }
    });
    cache.put(key, dirty);
    cache.evict();
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) Test(org.junit.Test)

Example 30 with Bytes

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

the class RocksDBSegmentedBytesStoreTest method shouldFindValuesWithinRange.

@Test
public void shouldFindValuesWithinRange() throws Exception {
    final String key = "a";
    bytesStore.put(serializeKey(new Windowed<>(key, new SessionWindow(0L, 0L))), serializeValue(50L));
    bytesStore.put(serializeKey(new Windowed<>(key, new SessionWindow(1000L, 1000L))), serializeValue(10L));
    final KeyValueIterator<Bytes, byte[]> results = bytesStore.fetch(Bytes.wrap(key.getBytes()), 1L, 1999L);
    assertEquals(Collections.singletonList(KeyValue.pair(new Windowed<>(key, new SessionWindow(1000L, 1000L)), 10L)), toList(results));
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) Bytes(org.apache.kafka.common.utils.Bytes) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) 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