Search in sources :

Example 1 with KafkaClientSupplier

use of org.apache.kafka.streams.KafkaClientSupplier in project kafka by apache.

the class StreamsProducerTest method shouldThrowTimeoutExceptionOnEosInitTxTimeout.

@Test
public void shouldThrowTimeoutExceptionOnEosInitTxTimeout() {
    // use `nonEosMockProducer` instead of `eosMockProducer` to avoid double Tx-Init
    nonEosMockProducer.initTransactionException = new TimeoutException("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 TimeoutException thrown = assertThrows(TimeoutException.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) TimeoutException(org.apache.kafka.common.errors.TimeoutException) Test(org.junit.Test)

Example 2 with KafkaClientSupplier

use of org.apache.kafka.streams.KafkaClientSupplier in project kafka by apache.

the class StreamsUpgradeTest method buildStreams.

public static KafkaStreams buildStreams(final Properties streamsProperties) {
    final StreamsBuilder builder = new StreamsBuilder();
    final KStream<Void, Void> dataStream = builder.stream("data");
    dataStream.process(SmokeTestUtil.printProcessorSupplier("data"));
    dataStream.to("echo");
    final Properties config = new Properties();
    config.setProperty(StreamsConfig.APPLICATION_ID_CONFIG, "StreamsUpgradeTest");
    config.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 1000L);
    config.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.ByteArraySerde.class.getName());
    config.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.ByteArraySerde.class.getName());
    final KafkaClientSupplier kafkaClientSupplier;
    if (streamsProperties.containsKey("test.future.metadata")) {
        kafkaClientSupplier = new FutureKafkaClientSupplier();
    } else {
        kafkaClientSupplier = new DefaultKafkaClientSupplier();
    }
    config.putAll(streamsProperties);
    return new KafkaStreams(builder.build(), config, kafkaClientSupplier);
}
Also used : StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) KafkaStreams(org.apache.kafka.streams.KafkaStreams) DefaultKafkaClientSupplier(org.apache.kafka.streams.processor.internals.DefaultKafkaClientSupplier) DefaultKafkaClientSupplier(org.apache.kafka.streams.processor.internals.DefaultKafkaClientSupplier) KafkaClientSupplier(org.apache.kafka.streams.KafkaClientSupplier) Properties(java.util.Properties)

Example 3 with KafkaClientSupplier

use of org.apache.kafka.streams.KafkaClientSupplier 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 4 with KafkaClientSupplier

use of org.apache.kafka.streams.KafkaClientSupplier 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

KafkaClientSupplier (org.apache.kafka.streams.KafkaClientSupplier)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Utils.mkMap (org.apache.kafka.common.utils.Utils.mkMap)3 TaskId (org.apache.kafka.streams.processor.TaskId)3 MockClientSupplier (org.apache.kafka.test.MockClientSupplier)3 Test (org.junit.Test)3 Properties (java.util.Properties)1 KafkaException (org.apache.kafka.common.KafkaException)1 TimeoutException (org.apache.kafka.common.errors.TimeoutException)1 KafkaStreams (org.apache.kafka.streams.KafkaStreams)1 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)1 StreamsException (org.apache.kafka.streams.errors.StreamsException)1 DefaultKafkaClientSupplier (org.apache.kafka.streams.processor.internals.DefaultKafkaClientSupplier)1