use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.
the class StreamThreadStateStoreProviderTest method before.
@Before
public void before() throws IOException {
final TopologyBuilder builder = new TopologyBuilder();
builder.addSource("the-source", "the-source");
builder.addProcessor("the-processor", new MockProcessorSupplier(), "the-source");
builder.addStateStore(Stores.create("kv-store").withStringKeys().withStringValues().inMemory().build(), "the-processor");
builder.addStateStore(Stores.create("window-store").withStringKeys().withStringValues().persistent().windowed(10, 10, 2, false).build(), "the-processor");
final Properties properties = new Properties();
final String applicationId = "applicationId";
properties.put(StreamsConfig.APPLICATION_ID_CONFIG, applicationId);
properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
stateDir = TestUtils.tempDirectory();
final String stateConfigDir = stateDir.getPath();
properties.put(StreamsConfig.STATE_DIR_CONFIG, stateConfigDir);
final StreamsConfig streamsConfig = new StreamsConfig(properties);
final MockClientSupplier clientSupplier = new MockClientSupplier();
configureRestoreConsumer(clientSupplier, "applicationId-kv-store-changelog");
configureRestoreConsumer(clientSupplier, "applicationId-window-store-changelog");
builder.setApplicationId(applicationId);
final ProcessorTopology topology = builder.build(null);
final Map<TaskId, StreamTask> tasks = new HashMap<>();
stateDirectory = new StateDirectory(applicationId, stateConfigDir, new MockTime());
taskOne = createStreamsTask(applicationId, streamsConfig, clientSupplier, topology, new TaskId(0, 0));
tasks.put(new TaskId(0, 0), taskOne);
taskTwo = createStreamsTask(applicationId, streamsConfig, clientSupplier, topology, new TaskId(0, 1));
tasks.put(new TaskId(0, 1), taskTwo);
storesAvailable = true;
thread = new StreamThread(builder, streamsConfig, clientSupplier, applicationId, "clientId", UUID.randomUUID(), new Metrics(), Time.SYSTEM, new StreamsMetadataState(builder, StreamsMetadataState.UNKNOWN_HOST), 0) {
@Override
public Map<TaskId, StreamTask> tasks() {
return tasks;
}
@Override
public boolean isInitialized() {
return storesAvailable;
}
};
provider = new StreamThreadStateStoreProvider(thread);
}
use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.
the class ThreadCacheTest method shouldSkipEntriesWhereValueHasBeenEvictedFromCache.
@Test
public void shouldSkipEntriesWhereValueHasBeenEvictedFromCache() throws Exception {
final String namespace = "streams";
final int entrySize = memoryCacheEntrySize(new byte[1], new byte[1], "");
final ThreadCache cache = new ThreadCache("testCache", entrySize * 5, new MockStreamsMetrics(new Metrics()));
cache.addDirtyEntryFlushListener(namespace, new ThreadCache.DirtyEntryFlushListener() {
@Override
public void apply(final List<ThreadCache.DirtyEntry> dirty) {
}
});
byte[][] bytes = { { 0 }, { 1 }, { 2 }, { 3 }, { 4 }, { 5 }, { 6 }, { 7 }, { 8 }, { 9 } };
for (int i = 0; i < 5; i++) {
cache.put(namespace, Bytes.wrap(bytes[i]), dirtyEntry(bytes[i]));
}
assertEquals(5, cache.size());
final ThreadCache.MemoryLRUCacheBytesIterator range = cache.range(namespace, Bytes.wrap(new byte[] { 0 }), Bytes.wrap(new byte[] { 5 }));
// should evict byte[] {0}
cache.put(namespace, Bytes.wrap(new byte[] { 6 }), dirtyEntry(new byte[] { 6 }));
assertEquals(Bytes.wrap(new byte[] { 1 }), range.peekNextKey());
}
use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.
the class NamedCacheTest method setUp.
@Before
public void setUp() throws Exception {
streamMetrics = new MockStreamsMetrics(new Metrics());
cache = new NamedCache("name", streamMetrics);
}
use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.
the class MergedSortedCacheKeyValueStoreIteratorTest method setUp.
@Before
public void setUp() throws Exception {
store = new InMemoryKeyValueStore<>(namespace, Serdes.Bytes(), Serdes.ByteArray());
cache = new ThreadCache("testCache", 10000L, new MockStreamsMetrics(new Metrics()));
}
use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.
the class MergedSortedCacheKeyValueStoreIteratorTest method shouldPeekNextKey.
@Test
public void shouldPeekNextKey() throws Exception {
final KeyValueStore<Bytes, byte[]> kv = new InMemoryKeyValueStore<>("one", Serdes.Bytes(), Serdes.ByteArray());
final ThreadCache cache = new ThreadCache("testCache", 1000000L, new MockStreamsMetrics(new Metrics()));
byte[][] bytes = { { 0 }, { 1 }, { 2 }, { 3 }, { 4 }, { 5 }, { 6 }, { 7 }, { 8 }, { 9 }, { 10 } };
final String namespace = "one";
for (int i = 0; i < bytes.length - 1; i += 2) {
kv.put(Bytes.wrap(bytes[i]), bytes[i]);
cache.put(namespace, Bytes.wrap(bytes[i + 1]), new LRUCacheEntry(bytes[i + 1]));
}
final Bytes from = Bytes.wrap(new byte[] { 2 });
final Bytes to = Bytes.wrap(new byte[] { 9 });
final KeyValueIterator<Bytes, byte[]> storeIterator = kv.range(from, to);
final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(namespace, from, to);
final MergedSortedCacheKeyValueStoreIterator<byte[], byte[]> iterator = new MergedSortedCacheKeyValueStoreIterator<>(cacheIterator, storeIterator, serdes);
final byte[][] values = new byte[8][];
int index = 0;
int bytesIndex = 2;
while (iterator.hasNext()) {
final byte[] keys = iterator.peekNextKey();
values[index++] = keys;
assertArrayEquals(bytes[bytesIndex++], keys);
iterator.next();
}
}
Aggregations