Search in sources :

Example 66 with Metrics

use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.

the class MeteredSegmentedBytesStoreTest method setUp.

@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
    final Metrics metrics = new Metrics();
    final StreamsMetrics streamsMetrics = new StreamsMetrics() {

        @Override
        public Map<MetricName, ? extends Metric> metrics() {
            return Collections.unmodifiableMap(metrics.metrics());
        }

        @Override
        public Sensor addLatencyAndThroughputSensor(String scopeName, String entityName, String operationName, Sensor.RecordingLevel recordLevel, String... tags) {
            return metrics.sensor(operationName);
        }

        @Override
        public void recordLatency(final Sensor sensor, final long startNs, final long endNs) {
            latencyRecorded.add(sensor.name());
        }

        @Override
        public Sensor addThroughputSensor(String scopeName, String entityName, String operationName, Sensor.RecordingLevel recordLevel, String... tags) {
            return metrics.sensor(operationName);
        }

        @Override
        public void recordThroughput(Sensor sensor, long value) {
            throughputRecorded.add(sensor.name());
        }

        @Override
        public void removeSensor(Sensor sensor) {
            metrics.removeSensor(sensor.name());
        }

        @Override
        public Sensor addSensor(String name, Sensor.RecordingLevel recordLevel) {
            return metrics.sensor(name);
        }

        @Override
        public Sensor addSensor(String name, Sensor.RecordingLevel recordLevel, Sensor... parents) {
            return metrics.sensor(name);
        }
    };
    final MockProcessorContext context = new MockProcessorContext(TestUtils.tempDirectory(), Serdes.String(), Serdes.Long(), new NoOpRecordCollector(), new ThreadCache("testCache", 0, streamsMetrics)) {

        @Override
        public StreamsMetrics metrics() {
            return streamsMetrics;
        }
    };
    store.init(context, store);
}
Also used : MetricName(org.apache.kafka.common.MetricName) Metrics(org.apache.kafka.common.metrics.Metrics) StreamsMetrics(org.apache.kafka.streams.StreamsMetrics) NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) StreamsMetrics(org.apache.kafka.streams.StreamsMetrics) MockProcessorContext(org.apache.kafka.test.MockProcessorContext) Sensor(org.apache.kafka.common.metrics.Sensor) Before(org.junit.Before)

Example 67 with Metrics

use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.

the class RocksDBSessionStoreTest method before.

@Before
public void before() {
    final RocksDBSegmentedBytesStore bytesStore = new RocksDBSegmentedBytesStore("session-store", 10000L, 3, new SessionKeySchema());
    sessionStore = new RocksDBSessionStore<>(bytesStore, Serdes.String(), Serdes.Long());
    final MockProcessorContext context = new MockProcessorContext(TestUtils.tempDirectory(), Serdes.String(), Serdes.Long(), new NoOpRecordCollector(), new ThreadCache("testCache", 0, new MockStreamsMetrics(new Metrics())));
    sessionStore.init(context, sessionStore);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) MockProcessorContext(org.apache.kafka.test.MockProcessorContext) Before(org.junit.Before)

Example 68 with Metrics

use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.

the class ThreadCacheTest method shouldNotClashWithOverlappingNames.

@Test
public void shouldNotClashWithOverlappingNames() throws Exception {
    final ThreadCache cache = new ThreadCache("testCache", 10000L, new MockStreamsMetrics(new Metrics()));
    final Bytes nameByte = Bytes.wrap(new byte[] { 0 });
    final Bytes name1Byte = Bytes.wrap(new byte[] { 1 });
    cache.put("name", nameByte, dirtyEntry(nameByte.get()));
    cache.put("name1", nameByte, dirtyEntry(name1Byte.get()));
    assertArrayEquals(nameByte.get(), cache.get("name", nameByte).value);
    assertArrayEquals(name1Byte.get(), cache.get("name1", nameByte).value);
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Test(org.junit.Test)

Example 69 with Metrics

use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.

the class ThreadCacheTest method shouldNotFlushCleanEntriesForNamespace.

@Test
public void shouldNotFlushCleanEntriesForNamespace() throws Exception {
    final ThreadCache cache = new ThreadCache("testCache", 100000, new MockStreamsMetrics(new Metrics()));
    final List<byte[]> received = new ArrayList<>();
    cache.addDirtyEntryFlushListener("1", new ThreadCache.DirtyEntryFlushListener() {

        @Override
        public void apply(final List<ThreadCache.DirtyEntry> dirty) {
            for (ThreadCache.DirtyEntry dirtyEntry : dirty) {
                received.add(dirtyEntry.key().get());
            }
        }
    });
    final List<byte[]> toInsert = Arrays.asList(new byte[] { 0 }, new byte[] { 1 }, new byte[] { 2 });
    for (byte[] bytes : toInsert) {
        cache.put("1", Bytes.wrap(bytes), cleanEntry(bytes));
    }
    cache.put("2", Bytes.wrap(new byte[] { 4 }), cleanEntry(new byte[] { 4 }));
    cache.flush("1");
    assertEquals(Collections.EMPTY_LIST, received);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) ArrayList(java.util.ArrayList) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Test(org.junit.Test)

Example 70 with Metrics

use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.

the class ThreadCacheTest method shouldReturnNullIfKeyIsNull.

@Test
public void shouldReturnNullIfKeyIsNull() throws Exception {
    final ThreadCache threadCache = new ThreadCache("testCache", 10, new MockStreamsMetrics(new Metrics()));
    threadCache.put("one", Bytes.wrap(new byte[] { 1 }), cleanEntry(new byte[] { 1 }));
    assertNull(threadCache.get("one", null));
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Test(org.junit.Test)

Aggregations

Metrics (org.apache.kafka.common.metrics.Metrics)103 Test (org.junit.Test)76 MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)41 HashMap (java.util.HashMap)31 StreamsConfig (org.apache.kafka.streams.StreamsConfig)28 TaskId (org.apache.kafka.streams.processor.TaskId)27 Before (org.junit.Before)22 MockTime (org.apache.kafka.common.utils.MockTime)21 TopicPartition (org.apache.kafka.common.TopicPartition)20 HashSet (java.util.HashSet)19 StreamsMetrics (org.apache.kafka.streams.StreamsMetrics)17 MockClientSupplier (org.apache.kafka.test.MockClientSupplier)17 UUID (java.util.UUID)16 PartitionAssignor (org.apache.kafka.clients.consumer.internals.PartitionAssignor)15 Bytes (org.apache.kafka.common.utils.Bytes)14 MockProcessorSupplier (org.apache.kafka.test.MockProcessorSupplier)14 KStreamBuilder (org.apache.kafka.streams.kstream.KStreamBuilder)13 SubscriptionInfo (org.apache.kafka.streams.processor.internals.assignment.SubscriptionInfo)13 MockProcessorContext (org.apache.kafka.test.MockProcessorContext)13 MockInternalTopicManager (org.apache.kafka.test.MockInternalTopicManager)11