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());
}
}
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);
}
}
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);
}
}
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
}
}
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());
}
}
Aggregations