use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.
the class ThreadCacheTest method shouldNotFlushAfterDelete.
@Test
public void shouldNotFlushAfterDelete() throws Exception {
final Bytes key = Bytes.wrap(new byte[] { 0 });
final ThreadCache cache = new ThreadCache("testCache", 10000L, new MockStreamsMetrics(new Metrics()));
final List<ThreadCache.DirtyEntry> received = new ArrayList<>();
final String namespace = "namespace";
cache.addDirtyEntryFlushListener(namespace, new ThreadCache.DirtyEntryFlushListener() {
@Override
public void apply(final List<ThreadCache.DirtyEntry> dirty) {
received.addAll(dirty);
}
});
cache.put(namespace, key, dirtyEntry(key.get()));
assertEquals(key.get(), cache.delete(namespace, key).value);
// flushing should have no further effect
cache.flush(namespace);
assertEquals(0, received.size());
assertEquals(cache.flushes(), 1);
}
use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.
the class ThreadCacheTest method shouldEvictAfterPutIfAbsent.
@Test
public void shouldEvictAfterPutIfAbsent() throws Exception {
final List<ThreadCache.DirtyEntry> received = new ArrayList<>();
final String namespace = "namespace";
final ThreadCache cache = new ThreadCache("testCache", 1, new MockStreamsMetrics(new Metrics()));
cache.addDirtyEntryFlushListener(namespace, new ThreadCache.DirtyEntryFlushListener() {
@Override
public void apply(final List<ThreadCache.DirtyEntry> dirty) {
received.addAll(dirty);
}
});
cache.putIfAbsent(namespace, Bytes.wrap(new byte[] { 0 }), dirtyEntry(new byte[] { 5 }));
cache.putIfAbsent(namespace, Bytes.wrap(new byte[] { 1 }), dirtyEntry(new byte[] { 6 }));
cache.putIfAbsent(namespace, Bytes.wrap(new byte[] { 1 }), dirtyEntry(new byte[] { 6 }));
assertEquals(cache.evicts(), 3);
assertEquals(received.size(), 3);
}
use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.
the class FetcherTest method testFetchMaxPollRecords.
@Test
public void testFetchMaxPollRecords() {
Fetcher<byte[], byte[]> fetcher = createFetcher(subscriptions, new Metrics(time), 2);
List<ConsumerRecord<byte[], byte[]>> records;
subscriptions.assignFromUser(singleton(tp));
subscriptions.seek(tp, 1);
client.prepareResponse(matchesOffset(tp, 1), fetchResponse(this.records, Errors.NONE, 100L, 0));
client.prepareResponse(matchesOffset(tp, 4), fetchResponse(this.nextRecords, Errors.NONE, 100L, 0));
assertEquals(1, fetcher.sendFetches());
consumerClient.poll(0);
records = fetcher.fetchedRecords().get(tp);
assertEquals(2, records.size());
assertEquals(3L, subscriptions.position(tp).longValue());
assertEquals(1, records.get(0).offset());
assertEquals(2, records.get(1).offset());
assertEquals(0, fetcher.sendFetches());
consumerClient.poll(0);
records = fetcher.fetchedRecords().get(tp);
assertEquals(1, records.size());
assertEquals(4L, subscriptions.position(tp).longValue());
assertEquals(3, records.get(0).offset());
assertTrue(fetcher.sendFetches() > 0);
consumerClient.poll(0);
records = fetcher.fetchedRecords().get(tp);
assertEquals(2, records.size());
assertEquals(6L, subscriptions.position(tp).longValue());
assertEquals(4, records.get(0).offset());
assertEquals(5, records.get(1).offset());
}
use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.
the class ConsumerCoordinatorTest method testProtocolMetadataOrder.
@Test
public void testProtocolMetadataOrder() {
RoundRobinAssignor roundRobin = new RoundRobinAssignor();
RangeAssignor range = new RangeAssignor();
try (Metrics metrics = new Metrics(time)) {
ConsumerCoordinator coordinator = buildCoordinator(metrics, Arrays.<PartitionAssignor>asList(roundRobin, range), ConsumerConfig.DEFAULT_EXCLUDE_INTERNAL_TOPICS, false);
List<ProtocolMetadata> metadata = coordinator.metadata();
assertEquals(2, metadata.size());
assertEquals(roundRobin.name(), metadata.get(0).name());
assertEquals(range.name(), metadata.get(1).name());
}
try (Metrics metrics = new Metrics(time)) {
ConsumerCoordinator coordinator = buildCoordinator(metrics, Arrays.<PartitionAssignor>asList(range, roundRobin), ConsumerConfig.DEFAULT_EXCLUDE_INTERNAL_TOPICS, false);
List<ProtocolMetadata> metadata = coordinator.metadata();
assertEquals(2, metadata.size());
assertEquals(range.name(), metadata.get(0).name());
assertEquals(roundRobin.name(), metadata.get(1).name());
}
}
use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.
the class ConsumerCoordinatorTest method testAutoCommitDynamicAssignmentRebalance.
@Test
public void testAutoCommitDynamicAssignmentRebalance() {
final String consumerId = "consumer";
ConsumerCoordinator coordinator = buildCoordinator(new Metrics(), assignors, ConsumerConfig.DEFAULT_EXCLUDE_INTERNAL_TOPICS, true);
subscriptions.subscribe(singleton(topic1), rebalanceListener);
client.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
coordinator.ensureCoordinatorReady();
// haven't joined, so should not cause a commit
time.sleep(autoCommitIntervalMs);
consumerClient.poll(0);
client.prepareResponse(joinGroupFollowerResponse(1, consumerId, "leader", Errors.NONE));
client.prepareResponse(syncGroupResponse(singletonList(t1p), Errors.NONE));
coordinator.joinGroupIfNeeded();
subscriptions.seek(t1p, 100);
client.prepareResponse(offsetCommitResponse(Collections.singletonMap(t1p, Errors.NONE)));
time.sleep(autoCommitIntervalMs);
coordinator.poll(time.milliseconds());
assertEquals(100L, subscriptions.committed(t1p).offset());
}
Aggregations