Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,6 @@ public void setUncaughtExceptionHandler(final StreamsUncaughtExceptionHandler us
}
processStreamThread(thread -> thread.setUncaughtExceptionHandler((t, e) -> { }
));

if (globalStreamThread != null) {
globalStreamThread.setUncaughtExceptionHandler((t, e) -> { }
);
}
} else {
throw new IllegalStateException("Can only set UncaughtExceptionHandler before calling start(). " +
"Current state is: " + state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ static class StateConsumer {
}

/**
* @throws IllegalStateException If store gets registered after initialized is already finished
* @throws IllegalStateException If a store gets registered after initialized is already finished
* @throws StreamsException if the store's change log does not contain the partition
*/
void initialize() {
Expand Down Expand Up @@ -431,7 +431,7 @@ private StateConsumer initialize() {
} catch (final StreamsException fatalException) {
closeStateConsumer(stateConsumer, false);
startupException = fatalException;
} catch (final Exception fatalException) {
} catch (final Throwable fatalException) {
closeStateConsumer(stateConsumer, false);
startupException = new StreamsException("Exception caught during initialization of GlobalStreamThread", fatalException);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,7 @@ public void process(final Record<Object, Object> record) {
);

baseDirectoryName = TestUtils.tempDirectory().getAbsolutePath();
final HashMap<String, Object> properties = new HashMap<>();
properties.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "blah");
properties.put(StreamsConfig.APPLICATION_ID_CONFIG, "testAppId");
properties.put(StreamsConfig.STATE_DIR_CONFIG, baseDirectoryName);
properties.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.ByteArraySerde.class.getName());
properties.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.ByteArraySerde.class.getName());
final HashMap<String, Object> properties = getStreamProperties();
config = new StreamsConfig(properties);
globalStreamThread = new GlobalStreamThread(
builder.rewriteTopology(config).buildGlobalStateTopology(),
Expand Down Expand Up @@ -407,6 +402,51 @@ public void shouldTimeOutOnGlobalConsumerInstanceId() throws Exception {
}
}

@Test
public void shouldThrowStreamsExceptionOnStartupIfThrowableOccurred() throws Exception {
final String exceptionMessage = "Throwable occurred!";
final MockConsumer<byte[], byte[]> consumer = new MockConsumer<>(AutoOffsetResetStrategy.EARLIEST.name()) {
@Override
public List<PartitionInfo> partitionsFor(final String topic) {
throw new ExceptionInInitializerError(exceptionMessage);
}
};
final StateStore globalStore = builder.globalStateStores().get(GLOBAL_STORE_NAME);
globalStreamThread = new GlobalStreamThread(
builder.buildGlobalStateTopology(),
config,
consumer,
new StateDirectory(config, time, true, false),
0,
new StreamsMetricsImpl(new Metrics(), "test-client", "processId", time),
time,
"clientId",
stateRestoreListener,
e -> { }
);

try {
globalStreamThread.start();
fail("Should have thrown StreamsException if start up failed");
} catch (final StreamsException e) {
assertThat(e.getCause(), instanceOf(Throwable.class));
assertThat(e.getCause().getMessage(), equalTo(exceptionMessage));
}
globalStreamThread.join();
assertThat(globalStore.isOpen(), is(false));
assertFalse(globalStreamThread.stillRunning());
}

private HashMap<String, Object> getStreamProperties() {
final HashMap<String, Object> properties = new HashMap<>();
properties.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "blah");
properties.put(StreamsConfig.APPLICATION_ID_CONFIG, "testAppId");
properties.put(StreamsConfig.STATE_DIR_CONFIG, baseDirectoryName);
properties.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.ByteArraySerde.class.getName());
properties.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.ByteArraySerde.class.getName());
return properties;
}

private void initializeConsumer() {
mockConsumer.updatePartitions(
GLOBAL_STORE_TOPIC_NAME,
Expand Down
Loading