Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exception on shutdown of ksqlDB server (MINOR) #4483

Merged
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 @@ -145,7 +145,6 @@ public void close() {
Thread.currentThread().interrupt();
}
commandRunnerStatusMetric.close();
commandStore.close();
}

/**
Expand Down Expand Up @@ -284,6 +283,8 @@ public void run() {
if (!closed) {
throw wue;
}
} finally {
commandStore.close();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
Expand Down Expand Up @@ -85,6 +87,8 @@ public class CommandRunnerTest {
private QueuedCommand queuedCommand3;
@Mock
private ExecutorService executor;
@Captor
private ArgumentCaptor<Runnable> threadTaskCaptor;
private CommandRunner commandRunner;

@Before
Expand Down Expand Up @@ -141,9 +145,11 @@ public void shouldRunThePriorCommandsWithTerminateCorrectly() {
commandRunner.processPriorCommands();

// Then:
verify(serverState).setTerminating();
verify(commandStore).close();
verify(clusterTerminator).terminateCluster(anyList());
final InOrder inOrder = inOrder(serverState, commandStore, clusterTerminator, statementExecutor);
inOrder.verify(serverState).setTerminating();
inOrder.verify(commandStore).wakeup();
inOrder.verify(clusterTerminator).terminateCluster(anyList());

verify(statementExecutor, never()).handleRestore(any());
}

Expand Down Expand Up @@ -295,23 +301,27 @@ public void shouldSubmitTaskOnStart() {

@Test
public void shouldCloseTheCommandRunnerCorrectly() throws Exception {
// Given:
commandRunner.start();

// When:
commandRunner.close();

// Then:
final InOrder inOrder = inOrder(executor, commandStore);
inOrder.verify(commandStore).wakeup();
inOrder.verify(executor).awaitTermination(anyLong(), any());
inOrder.verify(commandStore).close();
}
inOrder.verify(commandStore, never()).close(); // commandStore must be closed by runner thread

@Test(expected = RuntimeException.class)
public void shouldThrowExceptionIfCannotCloseCommandStore() {
// Given:
doThrow(RuntimeException.class).when(commandStore).close();
final Runnable threadTask = getThreadTask();
threadTask.run();

// When:
commandRunner.close();
verify(commandStore).close();
}

private Runnable getThreadTask() {
verify(executor).execute(threadTaskCaptor.capture());
return threadTaskCaptor.getValue();
}

private void givenQueuedCommands(final QueuedCommand... cmds) {
Expand Down