use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class MeteredTimestampedKeyValueStoreTest method shouldDelegateInit.
@Test
public void shouldDelegateInit() {
final KeyValueStore<Bytes, byte[]> inner = mock(InMemoryKeyValueStore.class);
final MeteredTimestampedKeyValueStore<String, String> outer = new MeteredTimestampedKeyValueStore<>(inner, STORE_TYPE, new MockTime(), Serdes.String(), new ValueAndTimestampSerde<>(Serdes.String()));
expect(inner.name()).andStubReturn("store");
inner.init((StateStoreContext) context, outer);
expectLastCall();
replay(inner, context);
outer.init((StateStoreContext) context, outer);
verify(inner);
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class MeteredTimestampedKeyValueStoreTest method shouldDelegateDeprecatedInit.
@SuppressWarnings("deprecation")
@Test
public void shouldDelegateDeprecatedInit() {
final KeyValueStore<Bytes, byte[]> inner = mock(InMemoryKeyValueStore.class);
final MeteredTimestampedKeyValueStore<String, String> outer = new MeteredTimestampedKeyValueStore<>(inner, STORE_TYPE, new MockTime(), Serdes.String(), new ValueAndTimestampSerde<>(Serdes.String()));
expect(inner.name()).andStubReturn("store");
inner.init((ProcessorContext) context, outer);
expectLastCall();
replay(inner, context);
outer.init((ProcessorContext) context, outer);
verify(inner);
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class MeteredWindowStoreTest method shouldDelegateDeprecatedInit.
@SuppressWarnings("deprecation")
@Test
public void shouldDelegateDeprecatedInit() {
final WindowStore<Bytes, byte[]> inner = mock(WindowStore.class);
final MeteredWindowStore<String, String> outer = new MeteredWindowStore<>(inner, // any size
WINDOW_SIZE_MS, STORE_TYPE, new MockTime(), Serdes.String(), new SerdeThatDoesntHandleNull());
expect(inner.name()).andStubReturn("store");
inner.init((ProcessorContext) context, outer);
expectLastCall();
replay(inner);
outer.init((ProcessorContext) context, outer);
verify(inner);
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class RocksDBTimestampedStoreTest method shouldMigrateDataFromDefaultToTimestampColumnFamily.
@Test
public void shouldMigrateDataFromDefaultToTimestampColumnFamily() throws Exception {
prepareOldStore();
try (final LogCaptureAppender appender = LogCaptureAppender.createAndRegister(RocksDBTimestampedStore.class)) {
rocksDBStore.init((StateStoreContext) context, rocksDBStore);
assertThat(appender.getMessages(), hasItem("Opening store " + DB_NAME + " in upgrade mode"));
}
// approx: 7 entries on old CF, 0 in new CF
assertThat(rocksDBStore.approximateNumEntries(), is(7L));
// get()
// should be no-op on both CF
assertThat(rocksDBStore.get(new Bytes("unknown".getBytes())), new IsNull<>());
// approx: 7 entries on old CF, 0 in new CF
assertThat(rocksDBStore.approximateNumEntries(), is(7L));
// should migrate key1 from old to new CF
// must return timestamp plus value, ie, it's not 1 byte but 9 bytes
assertThat(rocksDBStore.get(new Bytes("key1".getBytes())).length, is(8 + 1));
// one delete on old CF, one put on new CF
// approx: 6 entries on old CF, 1 in new CF
assertThat(rocksDBStore.approximateNumEntries(), is(7L));
// put()
// should migrate key2 from old to new CF with new value
rocksDBStore.put(new Bytes("key2".getBytes()), "timestamp+22".getBytes());
// one delete on old CF, one put on new CF
// approx: 5 entries on old CF, 2 in new CF
assertThat(rocksDBStore.approximateNumEntries(), is(7L));
// should delete key3 from old and new CF
rocksDBStore.put(new Bytes("key3".getBytes()), null);
// count is off by one, due to two delete operations (even if one does not delete anything)
// approx: 4 entries on old CF, 1 in new CF
assertThat(rocksDBStore.approximateNumEntries(), is(5L));
// should add new key8 to new CF
rocksDBStore.put(new Bytes("key8".getBytes()), "timestamp+88888888".getBytes());
// one delete on old CF, one put on new CF
// approx: 3 entries on old CF, 2 in new CF
assertThat(rocksDBStore.approximateNumEntries(), is(5L));
// putIfAbsent()
// should migrate key4 from old to new CF with old value
assertThat(rocksDBStore.putIfAbsent(new Bytes("key4".getBytes()), "timestamp+4444".getBytes()).length, is(8 + 4));
// one delete on old CF, one put on new CF
// approx: 2 entries on old CF, 3 in new CF
assertThat(rocksDBStore.approximateNumEntries(), is(5L));
// should add new key11 to new CF
assertThat(rocksDBStore.putIfAbsent(new Bytes("key11".getBytes()), "timestamp+11111111111".getBytes()), new IsNull<>());
// one delete on old CF, one put on new CF
// approx: 1 entries on old CF, 4 in new CF
assertThat(rocksDBStore.approximateNumEntries(), is(5L));
// should not delete key5 but migrate to new CF
assertThat(rocksDBStore.putIfAbsent(new Bytes("key5".getBytes()), null).length, is(8 + 5));
// one delete on old CF, one put on new CF
// approx: 0 entries on old CF, 5 in new CF
assertThat(rocksDBStore.approximateNumEntries(), is(5L));
// should be no-op on both CF
assertThat(rocksDBStore.putIfAbsent(new Bytes("key12".getBytes()), null), new IsNull<>());
// two delete operation, however, only one is counted because old CF count was zero before already
// approx: 0 entries on old CF, 4 in new CF
assertThat(rocksDBStore.approximateNumEntries(), is(4L));
// delete()
// should delete key6 from old and new CF
assertThat(rocksDBStore.delete(new Bytes("key6".getBytes())).length, is(8 + 6));
// two delete operation, however, only one is counted because old CF count was zero before already
// approx: 0 entries on old CF, 3 in new CF
assertThat(rocksDBStore.approximateNumEntries(), is(3L));
iteratorsShouldNotMigrateData();
assertThat(rocksDBStore.approximateNumEntries(), is(3L));
rocksDBStore.close();
verifyOldAndNewColumnFamily();
}
use of org.apache.kafka.common.utils.Bytes in project kafka by apache.
the class RocksDBTimestampedStoreTest method shouldOpenNewStoreInRegularMode.
@Test
public void shouldOpenNewStoreInRegularMode() {
try (final LogCaptureAppender appender = LogCaptureAppender.createAndRegister(RocksDBTimestampedStore.class)) {
rocksDBStore.init((StateStoreContext) context, rocksDBStore);
assertThat(appender.getMessages(), hasItem("Opening store " + DB_NAME + " in regular mode"));
}
try (final KeyValueIterator<Bytes, byte[]> iterator = rocksDBStore.all()) {
assertThat(iterator.hasNext(), is(false));
}
}
Aggregations