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());
}
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));
}
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));
}
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();
}
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));
}
Aggregations