use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class WindowStoreUtilsTest method testSerialization.
@Test
public void testSerialization() throws Exception {
final String key = "key1";
final long timestamp = 99L;
final int seqNum = 3;
Bytes bytes = WindowStoreUtils.toBinaryKey(key, timestamp, seqNum, serdes);
final String parsedKey = WindowStoreUtils.keyFromBinaryKey(bytes.get(), serdes);
final long parsedTs = WindowStoreUtils.timestampFromBinaryKey(bytes.get());
final int parsedSeqNum = WindowStoreUtils.sequenceNumberFromBinaryKey(bytes.get());
assertEquals(key, parsedKey);
assertEquals(timestamp, parsedTs);
assertEquals(seqNum, parsedSeqNum);
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class FilteredCacheIteratorTest method shouldPeekNextKey.
@Test
public void shouldPeekNextKey() throws Exception {
while (allIterator.hasNext()) {
final Bytes nextKey = allIterator.peekNextKey();
final KeyValue<Bytes, LRUCacheEntry> next = allIterator.next();
assertThat(next.key, equalTo(nextKey));
}
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class MergedSortedCacheKeyValueStoreIteratorTest method shouldNotHaveNextIfAllCachedItemsDeleted.
@Test
public void shouldNotHaveNextIfAllCachedItemsDeleted() throws Exception {
final byte[][] bytes = { { 0 }, { 1 }, { 2 } };
for (byte[] aByte : bytes) {
Bytes aBytes = Bytes.wrap(aByte);
store.put(aBytes, aByte);
cache.put(namespace, aBytes, new LRUCacheEntry(null));
}
assertFalse(createIterator().hasNext());
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class MergedSortedCacheWrappedWindowStoreIteratorTest method shouldPeekNextKey.
@Test
public void shouldPeekNextKey() throws Exception {
windowStoreKvPairs.add(KeyValue.pair(10L, "a".getBytes()));
cache.put(namespace, WindowStoreUtils.toBinaryKey("a", 0, 0, stateSerdes), new LRUCacheEntry("b".getBytes()));
Bytes fromBytes = WindowStoreUtils.toBinaryKey("a", 0, 0, stateSerdes);
Bytes toBytes = WindowStoreUtils.toBinaryKey("a", 100, 0, stateSerdes);
final KeyValueIterator<Long, byte[]> storeIterator = new DelegatingPeekingKeyValueIterator<>("store", new KeyValueIteratorStub<>(windowStoreKvPairs.iterator()));
final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(namespace, fromBytes, toBytes);
final MergedSortedCacheWindowStoreIterator<byte[]> iterator = new MergedSortedCacheWindowStoreIterator<>(cacheIterator, storeIterator, new StateSerdes<>("name", Serdes.Long(), Serdes.ByteArray()));
assertThat(iterator.peekNextKey(), equalTo(0L));
iterator.next();
assertThat(iterator.peekNextKey(), equalTo(10L));
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class MergedSortedCacheWrappedWindowStoreIteratorTest method shouldIterateOverValueFromBothIterators.
@Test
public void shouldIterateOverValueFromBothIterators() throws Exception {
final List<KeyValue<Long, byte[]>> expectedKvPairs = new ArrayList<>();
for (long t = 0; t < 100; t += 20) {
final byte[] v1Bytes = String.valueOf(t).getBytes();
final KeyValue<Long, byte[]> v1 = KeyValue.pair(t, v1Bytes);
windowStoreKvPairs.add(v1);
expectedKvPairs.add(KeyValue.pair(t, v1Bytes));
final Bytes keyBytes = WindowStoreUtils.toBinaryKey("a", t + 10, 0, stateSerdes);
final byte[] valBytes = String.valueOf(t + 10).getBytes();
expectedKvPairs.add(KeyValue.pair(t + 10, valBytes));
cache.put(namespace, keyBytes, new LRUCacheEntry(valBytes));
}
Bytes fromBytes = WindowStoreUtils.toBinaryKey("a", 0, 0, stateSerdes);
Bytes toBytes = WindowStoreUtils.toBinaryKey("a", 100, 0, stateSerdes);
final KeyValueIterator<Long, byte[]> storeIterator = new DelegatingPeekingKeyValueIterator<>("store", new KeyValueIteratorStub<>(windowStoreKvPairs.iterator()));
final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(namespace, fromBytes, toBytes);
final MergedSortedCacheWindowStoreIterator<byte[]> iterator = new MergedSortedCacheWindowStoreIterator<>(cacheIterator, storeIterator, new StateSerdes<>("name", Serdes.Long(), Serdes.ByteArray()));
int index = 0;
while (iterator.hasNext()) {
final KeyValue<Long, byte[]> next = iterator.next();
final KeyValue<Long, byte[]> expected = expectedKvPairs.get(index++);
assertArrayEquals(expected.value, next.value);
assertEquals(expected.key, next.key);
}
}
Aggregations