Search in sources :

Example 16 with StreamsException

use of org.apache.kafka.streams.errors.StreamsException in project apache-kafka-on-k8s by banzaicloud.

the class StreamsConfigTest method shouldSpecifyCorrectValueSerdeClassOnError.

@Test
public void shouldSpecifyCorrectValueSerdeClassOnError() {
    final Properties props = minimalStreamsConfig();
    props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, MisconfiguredSerde.class);
    final StreamsConfig config = new StreamsConfig(props);
    try {
        config.valueSerde();
        fail("Test should throw a StreamsException");
    } catch (StreamsException e) {
        assertEquals("Failed to configure value serde class org.apache.kafka.streams.StreamsConfigTest$MisconfiguredSerde", e.getMessage());
    }
}
Also used : StreamsException(org.apache.kafka.streams.errors.StreamsException) Properties(java.util.Properties) StreamsTestUtils.minimalStreamsConfig(org.apache.kafka.test.StreamsTestUtils.minimalStreamsConfig) Test(org.junit.Test)

Example 17 with StreamsException

use of org.apache.kafka.streams.errors.StreamsException in project apache-kafka-on-k8s by banzaicloud.

the class StreamsConfig method defaultValueSerde.

/**
 * Return an {@link Serde#configure(Map, boolean) configured} instance of {@link #DEFAULT_VALUE_SERDE_CLASS_CONFIG value
 * Serde class}.
 *
 * @return an configured instance of value Serde class
 */
public Serde defaultValueSerde() {
    Object valueSerdeConfigSetting = get(VALUE_SERDE_CLASS_CONFIG);
    try {
        Serde<?> serde = getConfiguredInstance(VALUE_SERDE_CLASS_CONFIG, Serde.class);
        if (serde == null) {
            valueSerdeConfigSetting = get(DEFAULT_VALUE_SERDE_CLASS_CONFIG);
            serde = getConfiguredInstance(DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serde.class);
        }
        serde.configure(originals(), false);
        return serde;
    } catch (final Exception e) {
        throw new StreamsException(String.format("Failed to configure value serde %s", valueSerdeConfigSetting), e);
    }
}
Also used : Serde(org.apache.kafka.common.serialization.Serde) StreamsException(org.apache.kafka.streams.errors.StreamsException) StreamsException(org.apache.kafka.streams.errors.StreamsException)

Example 18 with StreamsException

use of org.apache.kafka.streams.errors.StreamsException in project apache-kafka-on-k8s by banzaicloud.

the class StreamsConfig method defaultKeySerde.

/**
 * Return an {@link Serde#configure(Map, boolean) configured} instance of {@link #DEFAULT_KEY_SERDE_CLASS_CONFIG key Serde
 * class}.
 *
 * @return an configured instance of key Serde class
 */
public Serde defaultKeySerde() {
    Object keySerdeConfigSetting = get(KEY_SERDE_CLASS_CONFIG);
    try {
        Serde<?> serde = getConfiguredInstance(KEY_SERDE_CLASS_CONFIG, Serde.class);
        if (serde == null) {
            keySerdeConfigSetting = get(DEFAULT_KEY_SERDE_CLASS_CONFIG);
            serde = getConfiguredInstance(DEFAULT_KEY_SERDE_CLASS_CONFIG, Serde.class);
        }
        serde.configure(originals(), true);
        return serde;
    } catch (final Exception e) {
        throw new StreamsException(String.format("Failed to configure key serde %s", keySerdeConfigSetting), e);
    }
}
Also used : Serde(org.apache.kafka.common.serialization.Serde) StreamsException(org.apache.kafka.streams.errors.StreamsException) StreamsException(org.apache.kafka.streams.errors.StreamsException)

Example 19 with StreamsException

use of org.apache.kafka.streams.errors.StreamsException in project apache-kafka-on-k8s by banzaicloud.

the class StoreChangelogReaderTest method shouldThrowExceptionIfConsumerHasCurrentSubscription.

@Test
public void shouldThrowExceptionIfConsumerHasCurrentSubscription() {
    final StateRestorer mockRestorer = EasyMock.mock(StateRestorer.class);
    mockRestorer.setUserRestoreListener(stateRestoreListener);
    expect(mockRestorer.partition()).andReturn(new TopicPartition("sometopic", 0)).andReturn(new TopicPartition("sometopic", 0));
    EasyMock.replay(mockRestorer);
    changelogReader.register(mockRestorer);
    consumer.subscribe(Collections.singleton("sometopic"));
    try {
        changelogReader.restore(active);
        fail("Should have thrown IllegalStateException");
    } catch (final StreamsException expected) {
    // ok
    }
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) StreamsException(org.apache.kafka.streams.errors.StreamsException) Test(org.junit.Test)

Example 20 with StreamsException

use of org.apache.kafka.streams.errors.StreamsException in project apache-kafka-on-k8s by banzaicloud.

the class StreamTaskTest method shouldWrapKafkaExceptionsWithStreamsExceptionAndAddContextWhenPunctuatingStreamTime.

@Test
public void shouldWrapKafkaExceptionsWithStreamsExceptionAndAddContextWhenPunctuatingStreamTime() {
    task = createStatelessTask(false);
    task.initializeStateStores();
    task.initializeTopology();
    try {
        task.punctuate(processorStreamTime, 1, PunctuationType.STREAM_TIME, new Punctuator() {

            @Override
            public void punctuate(long timestamp) {
                throw new KafkaException("KABOOM!");
            }
        });
        fail("Should've thrown StreamsException");
    } catch (final StreamsException e) {
        final String message = e.getMessage();
        assertTrue("message=" + message + " should contain processor", message.contains("processor '" + processorStreamTime.name() + "'"));
        assertThat(task.processorContext.currentNode(), nullValue());
    }
}
Also used : Punctuator(org.apache.kafka.streams.processor.Punctuator) StreamsException(org.apache.kafka.streams.errors.StreamsException) KafkaException(org.apache.kafka.common.KafkaException) Test(org.junit.Test)

Aggregations

StreamsException (org.apache.kafka.streams.errors.StreamsException)186 Test (org.junit.Test)90 KafkaException (org.apache.kafka.common.KafkaException)41 TopicPartition (org.apache.kafka.common.TopicPartition)38 TimeoutException (org.apache.kafka.common.errors.TimeoutException)36 HashMap (java.util.HashMap)27 Map (java.util.Map)25 HashSet (java.util.HashSet)18 Properties (java.util.Properties)17 TaskId (org.apache.kafka.streams.processor.TaskId)14 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)13 StreamsConfig (org.apache.kafka.streams.StreamsConfig)12 ArrayList (java.util.ArrayList)11 ExecutionException (java.util.concurrent.ExecutionException)11 TaskMigratedException (org.apache.kafka.streams.errors.TaskMigratedException)11 IOException (java.io.IOException)10 Set (java.util.Set)10 LogContext (org.apache.kafka.common.utils.LogContext)10 MockTime (org.apache.kafka.common.utils.MockTime)10 StateStore (org.apache.kafka.streams.processor.StateStore)10