Search in sources :

Example 6 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project apache-kafka-on-k8s by banzaicloud.

the class RocksDBStoreTest method setUp.

@Before
public void setUp() {
    rocksDBStore = new RocksDBStore("test");
    dir = TestUtils.tempDirectory();
    context = new InternalMockProcessorContext(dir, Serdes.String(), Serdes.String(), new NoOpRecordCollector(), new ThreadCache(new LogContext("testCache "), 0, new MockStreamsMetrics(new Metrics())));
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) Before(org.junit.Before)

Example 7 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project apache-kafka-on-k8s by banzaicloud.

the class RocksDBStoreTest method verifyRocksDbConfigSetterIsCalled.

@Test
public void verifyRocksDbConfigSetterIsCalled() {
    final Map<String, Object> configs = new HashMap<>();
    configs.put(StreamsConfig.APPLICATION_ID_CONFIG, "test-application");
    configs.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "test-server:9092");
    configs.put(StreamsConfig.ROCKSDB_CONFIG_SETTER_CLASS_CONFIG, MockRocksDbConfigSetter.class);
    MockRocksDbConfigSetter.called = false;
    rocksDBStore.openDB(new InternalMockProcessorContext(tempDir, new StreamsConfig(configs)));
    assertTrue(MockRocksDbConfigSetter.called);
}
Also used : HashMap(java.util.HashMap) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 8 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project apache-kafka-on-k8s by banzaicloud.

the class SegmentsTest method createContext.

@Before
public void createContext() {
    stateDirectory = TestUtils.tempDirectory();
    context = new InternalMockProcessorContext(stateDirectory, Serdes.String(), Serdes.Long(), new NoOpRecordCollector(), new ThreadCache(new LogContext("testCache "), 0, new MockStreamsMetrics(new Metrics())));
    segments = new Segments(storeName, retentionPeriod, NUM_SEGMENTS);
    segmentInterval = Segments.segmentInterval(retentionPeriod, NUM_SEGMENTS);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) Before(org.junit.Before)

Example 9 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project apache-kafka-on-k8s by banzaicloud.

the class GlobalStateManagerImplTest method before.

@Before
public void before() throws IOException {
    final Map<String, String> storeToTopic = new HashMap<>();
    storeToTopic.put(storeName1, t1.topic());
    storeToTopic.put(storeName2, t2.topic());
    storeToTopic.put(storeName3, t3.topic());
    storeToTopic.put(storeName4, t4.topic());
    store1 = new NoOpReadOnlyStore<>(storeName1, true);
    store2 = new NoOpReadOnlyStore<>(storeName2, true);
    store3 = new NoOpReadOnlyStore<>(storeName3);
    store4 = new NoOpReadOnlyStore<>(storeName4);
    topology = ProcessorTopology.withGlobalStores(Utils.<StateStore>mkList(store1, store2, store3, store4), storeToTopic);
    streamsConfig = new StreamsConfig(new Properties() {

        {
            put(StreamsConfig.APPLICATION_ID_CONFIG, "appId");
            put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "dummy:1234");
            put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
        }
    });
    stateDirectory = new StateDirectory(streamsConfig, time);
    consumer = new MockConsumer<>(OffsetResetStrategy.NONE);
    stateManager = new GlobalStateManagerImpl(new LogContext("test"), topology, consumer, stateDirectory, stateRestoreListener, streamsConfig);
    processorContext = new InternalMockProcessorContext(stateDirectory.globalStateDir(), streamsConfig);
    stateManager.setGlobalProcessorContext(processorContext);
    checkpointFile = new File(stateManager.baseDir(), ProcessorStateManager.CHECKPOINT_FILE_NAME);
}
Also used : HashMap(java.util.HashMap) StateStore(org.apache.kafka.streams.processor.StateStore) LogContext(org.apache.kafka.common.utils.LogContext) Properties(java.util.Properties) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) File(java.io.File) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Before(org.junit.Before)

Example 10 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project apache-kafka-on-k8s by banzaicloud.

the class ProcessorNodeTest method testMetrics.

@Test
public void testMetrics() {
    final StateSerdes anyStateSerde = StateSerdes.withBuiltinTypes("anyName", Bytes.class, Bytes.class);
    final Metrics metrics = new Metrics();
    final InternalMockProcessorContext context = new InternalMockProcessorContext(anyStateSerde, new RecordCollectorImpl(null, null, new LogContext("processnode-test "), new DefaultProductionExceptionHandler()), metrics);
    final ProcessorNode node = new ProcessorNode("name", new NoOpProcessor(), Collections.emptySet());
    node.init(context);
    String[] latencyOperations = { "process", "punctuate", "create", "destroy" };
    String throughputOperation = "forward";
    String groupName = "stream-processor-node-metrics";
    final Map<String, String> metricTags = new LinkedHashMap<>();
    metricTags.put("processor-node-id", node.name());
    metricTags.put("task-id", context.taskId().toString());
    for (String operation : latencyOperations) {
        assertNotNull(metrics.getSensor(operation));
    }
    assertNotNull(metrics.getSensor(throughputOperation));
    for (String opName : latencyOperations) {
        testSpecificMetrics(metrics, groupName, opName, metricTags);
    }
    assertNotNull(metrics.metrics().get(metrics.metricName(throughputOperation + "-rate", groupName, "The average number of occurrence of " + throughputOperation + " operation per second.", metricTags)));
    // test "all"
    metricTags.put("processor-node-id", "all");
    for (String opName : latencyOperations) {
        testSpecificMetrics(metrics, groupName, opName, metricTags);
    }
    assertNotNull(metrics.metrics().get(metrics.metricName(throughputOperation + "-rate", groupName, "The average number of occurrence of " + throughputOperation + " operation per second.", metricTags)));
    context.close();
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) DefaultProductionExceptionHandler(org.apache.kafka.streams.errors.DefaultProductionExceptionHandler) LogContext(org.apache.kafka.common.utils.LogContext) StateSerdes(org.apache.kafka.streams.state.StateSerdes) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

InternalMockProcessorContext (org.apache.kafka.test.InternalMockProcessorContext)21 LogContext (org.apache.kafka.common.utils.LogContext)14 NoOpRecordCollector (org.apache.kafka.test.NoOpRecordCollector)14 Metrics (org.apache.kafka.common.metrics.Metrics)13 Before (org.junit.Before)12 MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)11 Test (org.junit.Test)8 Serializer (org.apache.kafka.common.serialization.Serializer)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)4 StreamsConfig (org.apache.kafka.streams.StreamsConfig)3 StateStore (org.apache.kafka.streams.processor.StateStore)3 ProcessorRecordContext (org.apache.kafka.streams.processor.internals.ProcessorRecordContext)3 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 Bytes (org.apache.kafka.common.utils.Bytes)2 MockTime (org.apache.kafka.common.utils.MockTime)2 RecordCollector (org.apache.kafka.streams.processor.internals.RecordCollector)2 LinkedHashMap (java.util.LinkedHashMap)1