Search in sources :

Example 26 with MockClientSupplier

use of org.apache.kafka.test.MockClientSupplier in project kafka by apache.

the class StreamThreadStateStoreProviderTest method before.

@Before
public void before() {
    final TopologyWrapper topology = new TopologyWrapper();
    topology.addSource("the-source", topicName);
    topology.addProcessor("the-processor", new MockApiProcessorSupplier<>(), "the-source");
    topology.addStateStore(Stores.keyValueStoreBuilder(Stores.inMemoryKeyValueStore("kv-store"), Serdes.String(), Serdes.String()), "the-processor");
    topology.addStateStore(Stores.timestampedKeyValueStoreBuilder(Stores.inMemoryKeyValueStore("timestamped-kv-store"), Serdes.String(), Serdes.String()), "the-processor");
    topology.addStateStore(Stores.windowStoreBuilder(Stores.inMemoryWindowStore("window-store", Duration.ofMillis(10L), Duration.ofMillis(2L), false), Serdes.String(), Serdes.String()), "the-processor");
    topology.addStateStore(Stores.timestampedWindowStoreBuilder(Stores.inMemoryWindowStore("timestamped-window-store", Duration.ofMillis(10L), Duration.ofMillis(2L), false), Serdes.String(), Serdes.String()), "the-processor");
    topology.addStateStore(Stores.sessionStoreBuilder(Stores.inMemorySessionStore("session-store", Duration.ofMillis(10L)), Serdes.String(), Serdes.String()), "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();
    properties.put(StreamsConfig.STATE_DIR_CONFIG, stateDir.getPath());
    final StreamsConfig streamsConfig = new StreamsConfig(properties);
    final MockClientSupplier clientSupplier = new MockClientSupplier();
    configureClients(clientSupplier, "applicationId-kv-store-changelog");
    configureClients(clientSupplier, "applicationId-window-store-changelog");
    final InternalTopologyBuilder internalTopologyBuilder = topology.getInternalBuilder(applicationId);
    final ProcessorTopology processorTopology = internalTopologyBuilder.buildTopology();
    tasks = new HashMap<>();
    stateDirectory = new StateDirectory(streamsConfig, new MockTime(), true, false);
    taskOne = createStreamsTask(streamsConfig, clientSupplier, processorTopology, new TaskId(0, 0));
    taskOne.initializeIfNeeded();
    tasks.put(new TaskId(0, 0), taskOne);
    final StreamTask taskTwo = createStreamsTask(streamsConfig, clientSupplier, processorTopology, new TaskId(0, 1));
    taskTwo.initializeIfNeeded();
    tasks.put(new TaskId(0, 1), taskTwo);
    threadMock = EasyMock.createNiceMock(StreamThread.class);
    provider = new StreamThreadStateStoreProvider(threadMock);
}
Also used : ProcessorTopology(org.apache.kafka.streams.processor.internals.ProcessorTopology) TaskId(org.apache.kafka.streams.processor.TaskId) StreamThread(org.apache.kafka.streams.processor.internals.StreamThread) Properties(java.util.Properties) InternalTopologyBuilder(org.apache.kafka.streams.processor.internals.InternalTopologyBuilder) MockClientSupplier(org.apache.kafka.test.MockClientSupplier) TopologyWrapper(org.apache.kafka.streams.TopologyWrapper) MockTime(org.apache.kafka.common.utils.MockTime) StreamTask(org.apache.kafka.streams.processor.internals.StreamTask) StreamsConfig(org.apache.kafka.streams.StreamsConfig) StateDirectory(org.apache.kafka.streams.processor.internals.StateDirectory) Before(org.junit.Before)

Example 27 with MockClientSupplier

use of org.apache.kafka.test.MockClientSupplier in project kafka by apache.

the class StreamsProducerTest method shouldThrowStreamsExceptionOnEosInitError.

@Test
public void shouldThrowStreamsExceptionOnEosInitError() {
    // use `nonEosMockProducer` instead of `eosMockProducer` to avoid double Tx-Init
    nonEosMockProducer.initTransactionException = new KafkaException("KABOOM!");
    final KafkaClientSupplier clientSupplier = new MockClientSupplier() {

        @Override
        public Producer<byte[], byte[]> getProducer(final Map<String, Object> config) {
            return nonEosMockProducer;
        }
    };
    final StreamsProducer streamsProducer = new StreamsProducer(eosAlphaConfig, "threadId", clientSupplier, new TaskId(0, 0), null, logContext, mockTime);
    final StreamsException thrown = assertThrows(StreamsException.class, streamsProducer::initTransaction);
    assertThat(thrown.getCause(), is(nonEosMockProducer.initTransactionException));
    assertThat(thrown.getMessage(), is("Error encountered trying to initialize transactions [test]"));
}
Also used : TaskId(org.apache.kafka.streams.processor.TaskId) KafkaClientSupplier(org.apache.kafka.streams.KafkaClientSupplier) MockClientSupplier(org.apache.kafka.test.MockClientSupplier) StreamsException(org.apache.kafka.streams.errors.StreamsException) KafkaException(org.apache.kafka.common.KafkaException) Utils.mkMap(org.apache.kafka.common.utils.Utils.mkMap) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 28 with MockClientSupplier

use of org.apache.kafka.test.MockClientSupplier in project kafka by apache.

the class StreamsProducerTest method shouldFailOnEosInitFatal.

@Test
public void shouldFailOnEosInitFatal() {
    // use `nonEosMockProducer` instead of `eosMockProducer` to avoid double Tx-Init
    nonEosMockProducer.initTransactionException = new RuntimeException("KABOOM!");
    final KafkaClientSupplier clientSupplier = new MockClientSupplier() {

        @Override
        public Producer<byte[], byte[]> getProducer(final Map<String, Object> config) {
            return nonEosMockProducer;
        }
    };
    final StreamsProducer streamsProducer = new StreamsProducer(eosAlphaConfig, "threadId", clientSupplier, new TaskId(0, 0), null, logContext, mockTime);
    final RuntimeException thrown = assertThrows(RuntimeException.class, streamsProducer::initTransaction);
    assertThat(thrown.getMessage(), is("KABOOM!"));
}
Also used : TaskId(org.apache.kafka.streams.processor.TaskId) KafkaClientSupplier(org.apache.kafka.streams.KafkaClientSupplier) MockClientSupplier(org.apache.kafka.test.MockClientSupplier) Utils.mkMap(org.apache.kafka.common.utils.Utils.mkMap) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

MockClientSupplier (org.apache.kafka.test.MockClientSupplier)28 Test (org.junit.Test)23 TaskId (org.apache.kafka.streams.processor.TaskId)19 StreamsConfig (org.apache.kafka.streams.StreamsConfig)17 HashMap (java.util.HashMap)16 Metrics (org.apache.kafka.common.metrics.Metrics)16 MockTime (org.apache.kafka.common.utils.MockTime)16 StreamsMetrics (org.apache.kafka.streams.StreamsMetrics)14 TopicPartition (org.apache.kafka.common.TopicPartition)13 HashSet (java.util.HashSet)12 Map (java.util.Map)10 Set (java.util.Set)9 Collection (java.util.Collection)8 TopologyBuilder (org.apache.kafka.streams.processor.TopologyBuilder)8 KStreamBuilder (org.apache.kafka.streams.kstream.KStreamBuilder)7 Properties (java.util.Properties)5 Utils.mkMap (org.apache.kafka.common.utils.Utils.mkMap)5 PartitionInfo (org.apache.kafka.common.PartitionInfo)4 MockProcessorSupplier (org.apache.kafka.test.MockProcessorSupplier)4 Before (org.junit.Before)4