use of org.neo4j.shell.state.BoltStateHandler in project neo4j by neo4j.
the class InteractiveShellRunnerTest method testSignalHandleDuringExecution.
@Test
public void testSignalHandleDuringExecution() throws Exception {
// given
BoltStateHandler boltStateHandler = mock(BoltStateHandler.class);
FakeInterruptableShell fakeShell = spy(new FakeInterruptableShell(logger, boltStateHandler));
InputStream inputStream = new ByteArrayInputStream("RETURN 1;\n".getBytes());
InteractiveShellRunner runner = new InteractiveShellRunner(fakeShell, fakeShell, fakeShell, logger, new ShellStatementParser(), inputStream, historyFile, userMessagesHandler, connectionConfig);
// during
Thread t = new Thread(runner::runUntilEnd);
t.start();
// wait until execution has begun
while (!t.getState().equals(Thread.State.TIMED_WAITING)) {
Thread.sleep(100L);
}
// when
runner.handle(new Signal(InteractiveShellRunner.INTERRUPT_SIGNAL));
// then
verify(fakeShell).execute("RETURN 1;");
verify(fakeShell).reset();
verify(boltStateHandler).reset();
}
use of org.neo4j.shell.state.BoltStateHandler in project neo4j by neo4j.
the class InteractiveShellRunnerTest method setupInteractiveTestShellRunner.
private TestInteractiveShellRunner setupInteractiveTestShellRunner(String input) throws Exception {
// NOTE: Tests using this will test a bit more of the stack using OfflineTestShell
ByteArrayOutputStream output = new ByteArrayOutputStream();
ByteArrayOutputStream error = new ByteArrayOutputStream();
BoltStateHandler mockedBoltStateHandler = mock(BoltStateHandler.class);
when(mockedBoltStateHandler.getProtocolVersion()).thenReturn("");
final PrettyPrinter mockedPrettyPrinter = mock(PrettyPrinter.class);
Logger logger = new AnsiLogger(false, Format.VERBOSE, new PrintStream(output), new PrintStream(error));
OfflineTestShell offlineTestShell = new OfflineTestShell(logger, mockedBoltStateHandler, mockedPrettyPrinter);
CommandHelper commandHelper = new CommandHelper(logger, Historian.empty, offlineTestShell);
offlineTestShell.setCommandHelper(commandHelper);
InputStream inputStream = new ByteArrayInputStream(input.getBytes());
InteractiveShellRunner runner = new InteractiveShellRunner(offlineTestShell, offlineTestShell, offlineTestShell, logger, new ShellStatementParser(), inputStream, historyFile, userMessagesHandler, connectionConfig);
return new TestInteractiveShellRunner(runner, output, error, mockedBoltStateHandler);
}
use of org.neo4j.shell.state.BoltStateHandler in project neo4j by neo4j.
the class CypherShellTest method executeShouldPrintResult.
@Test
public void executeShouldPrintResult() throws CommandException {
Driver mockedDriver = mock(Driver.class);
Session session = mock(Session.class);
BoltResult result = mock(ListBoltResult.class);
BoltStateHandler boltStateHandler = mock(BoltStateHandler.class);
when(boltStateHandler.isConnected()).thenReturn(true);
when(boltStateHandler.runCypher(anyString(), anyMap())).thenReturn(Optional.of(result));
doAnswer(a -> {
((LinePrinter) a.getArguments()[1]).printOut("999");
return null;
}).when(mockedPrettyPrinter).format(any(BoltResult.class), anyObject());
when(mockedDriver.session()).thenReturn(session);
OfflineTestShell shell = new OfflineTestShell(logger, boltStateHandler, mockedPrettyPrinter);
shell.execute("RETURN 999");
verify(logger).printOut(contains("999"));
}
Aggregations