Search in sources :

Example 1 with SystemTime

use of org.apache.kafka.common.utils.SystemTime in project kafka by apache.

the class SensorTest method testShouldRecord.

@Test
public void testShouldRecord() {
    MetricConfig debugConfig = new MetricConfig().recordLevel(Sensor.RecordingLevel.DEBUG);
    MetricConfig infoConfig = new MetricConfig().recordLevel(Sensor.RecordingLevel.INFO);
    Sensor infoSensor = new Sensor(null, "infoSensor", null, debugConfig, new SystemTime(), 0, Sensor.RecordingLevel.INFO);
    assertTrue(infoSensor.shouldRecord());
    infoSensor = new Sensor(null, "infoSensor", null, debugConfig, new SystemTime(), 0, Sensor.RecordingLevel.DEBUG);
    assertTrue(infoSensor.shouldRecord());
    Sensor debugSensor = new Sensor(null, "debugSensor", null, infoConfig, new SystemTime(), 0, Sensor.RecordingLevel.INFO);
    assertTrue(debugSensor.shouldRecord());
    debugSensor = new Sensor(null, "debugSensor", null, infoConfig, new SystemTime(), 0, Sensor.RecordingLevel.DEBUG);
    assertFalse(debugSensor.shouldRecord());
}
Also used : SystemTime(org.apache.kafka.common.utils.SystemTime) Test(org.junit.Test)

Example 2 with SystemTime

use of org.apache.kafka.common.utils.SystemTime in project ignite by apache.

the class IgniteSourceConnectorTest method beforeTest.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTest() throws Exception {
    kafkaBroker = new TestKafkaBroker();
    WorkerConfig workerCfg = new StandaloneConfig(makeWorkerProps());
    MemoryOffsetBackingStore offBackingStore = new MemoryOffsetBackingStore();
    offBackingStore.configure(workerCfg);
    worker = new Worker(WORKER_ID, new SystemTime(), workerCfg, offBackingStore);
    worker.start();
    herder = new StandaloneHerder(worker);
    herder.start();
}
Also used : StandaloneHerder(org.apache.kafka.connect.runtime.standalone.StandaloneHerder) WorkerConfig(org.apache.kafka.connect.runtime.WorkerConfig) Worker(org.apache.kafka.connect.runtime.Worker) TestKafkaBroker(org.apache.ignite.stream.kafka.TestKafkaBroker) StandaloneConfig(org.apache.kafka.connect.runtime.standalone.StandaloneConfig) MemoryOffsetBackingStore(org.apache.kafka.connect.storage.MemoryOffsetBackingStore) SystemTime(org.apache.kafka.common.utils.SystemTime)

Example 3 with SystemTime

use of org.apache.kafka.common.utils.SystemTime in project ksql by confluentinc.

the class MetricCollectors method initialize.

// visible for testing.
// We need to call this from the MetricCollectorsTest because otherwise tests clobber each
// others metric data. We also need it from the KsqlEngineMetricsTest
public static void initialize() {
    MetricConfig metricConfig = new MetricConfig().samples(100).timeWindow(1000, TimeUnit.MILLISECONDS);
    List<MetricsReporter> reporters = new ArrayList<>();
    reporters.add(new JmxReporter("io.confluent.ksql.metrics"));
    // Replace all static contents other than Time to ensure they are cleaned for tests that are
    // not aware of the need to initialize/cleanup this test, in case test processes are reused.
    // Tests aware of the class clean everything up properly to get the state into a clean state,
    // a full, fresh instantiation here ensures something like KsqlEngineMetricsTest running after
    // another test that used MetricsCollector without running cleanUp will behave correctly.
    metrics = new Metrics(metricConfig, reporters, new SystemTime());
    collectorMap = new ConcurrentHashMap<>();
}
Also used : MetricConfig(org.apache.kafka.common.metrics.MetricConfig) Metrics(org.apache.kafka.common.metrics.Metrics) MetricsReporter(org.apache.kafka.common.metrics.MetricsReporter) ArrayList(java.util.ArrayList) JmxReporter(org.apache.kafka.common.metrics.JmxReporter) SystemTime(org.apache.kafka.common.utils.SystemTime)

Example 4 with SystemTime

use of org.apache.kafka.common.utils.SystemTime in project apache-kafka-on-k8s by banzaicloud.

the class SensorTest method testShouldRecord.

@Test
public void testShouldRecord() {
    MetricConfig debugConfig = new MetricConfig().recordLevel(Sensor.RecordingLevel.DEBUG);
    MetricConfig infoConfig = new MetricConfig().recordLevel(Sensor.RecordingLevel.INFO);
    Sensor infoSensor = new Sensor(null, "infoSensor", null, debugConfig, new SystemTime(), 0, Sensor.RecordingLevel.INFO);
    assertTrue(infoSensor.shouldRecord());
    infoSensor = new Sensor(null, "infoSensor", null, debugConfig, new SystemTime(), 0, Sensor.RecordingLevel.DEBUG);
    assertTrue(infoSensor.shouldRecord());
    Sensor debugSensor = new Sensor(null, "debugSensor", null, infoConfig, new SystemTime(), 0, Sensor.RecordingLevel.INFO);
    assertTrue(debugSensor.shouldRecord());
    debugSensor = new Sensor(null, "debugSensor", null, infoConfig, new SystemTime(), 0, Sensor.RecordingLevel.DEBUG);
    assertFalse(debugSensor.shouldRecord());
}
Also used : SystemTime(org.apache.kafka.common.utils.SystemTime) Test(org.junit.Test)

Example 5 with SystemTime

use of org.apache.kafka.common.utils.SystemTime in project apache-kafka-on-k8s by banzaicloud.

the class TopologyTestDriverTest method shouldReturnAllStores.

@Test
public void shouldReturnAllStores() {
    final Topology topology = setupSourceSinkTopology();
    topology.addStateStore(new KeyValueStoreBuilder<>(Stores.inMemoryKeyValueStore("store"), Serdes.ByteArray(), Serdes.ByteArray(), new SystemTime()).withLoggingDisabled());
    topology.addGlobalStore(new KeyValueStoreBuilder<>(Stores.inMemoryKeyValueStore("globalStore"), Serdes.ByteArray(), Serdes.ByteArray(), new SystemTime()).withLoggingDisabled(), "sourceProcessorName", Serdes.ByteArray().deserializer(), Serdes.ByteArray().deserializer(), "globalTopicName", "globalProcessorName", new ProcessorSupplier() {

        @Override
        public Processor get() {
            return null;
        }
    });
    testDriver = new TopologyTestDriver(topology, config);
    final Set<String> expectedStoreNames = new HashSet<>();
    expectedStoreNames.add("store");
    expectedStoreNames.add("globalStore");
    assertThat(testDriver.getAllStateStores().keySet(), equalTo(expectedStoreNames));
}
Also used : Processor(org.apache.kafka.streams.processor.Processor) KeyValueStoreBuilder(org.apache.kafka.streams.state.internals.KeyValueStoreBuilder) ProcessorSupplier(org.apache.kafka.streams.processor.ProcessorSupplier) SystemTime(org.apache.kafka.common.utils.SystemTime) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

SystemTime (org.apache.kafka.common.utils.SystemTime)20 Test (org.junit.Test)7 Test (org.junit.jupiter.api.Test)7 Properties (java.util.Properties)5 Metric (org.apache.kafka.common.Metric)4 MetricName (org.apache.kafka.common.MetricName)4 Time (org.apache.kafka.common.utils.Time)4 MetricRegistry (com.codahale.metrics.MetricRegistry)3 KafkaCruiseControlConfig (com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig)3 HashSet (java.util.HashSet)3 TopicPartition (org.apache.kafka.common.TopicPartition)3 StreamsConfig (org.apache.kafka.streams.StreamsConfig)3 LogCaptureAppender (org.apache.kafka.streams.processor.internals.testutil.LogCaptureAppender)3 KeyValueStoreBuilder (org.apache.kafka.streams.state.internals.KeyValueStoreBuilder)3 InternalMockProcessorContext (org.apache.kafka.test.InternalMockProcessorContext)3 OperationProgress (com.linkedin.kafka.cruisecontrol.async.progress.OperationProgress)2 ClusterModelStats (com.linkedin.kafka.cruisecontrol.model.ClusterModelStats)2 Map (java.util.Map)2 TestKafkaBroker (org.apache.ignite.stream.kafka.TestKafkaBroker)2 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)2