Search in sources :

Example 1 with BoltStateHandler

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();
}
Also used : ShellStatementParser(org.neo4j.shell.parser.ShellStatementParser) Signal(sun.misc.Signal) ByteArrayInputStream(java.io.ByteArrayInputStream) BoltStateHandler(org.neo4j.shell.state.BoltStateHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 2 with BoltStateHandler

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);
}
Also used : PrintStream(java.io.PrintStream) ShellStatementParser(org.neo4j.shell.parser.ShellStatementParser) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OfflineTestShell(org.neo4j.shell.OfflineTestShell) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Logger(org.neo4j.shell.log.Logger) AnsiLogger(org.neo4j.shell.log.AnsiLogger) AnsiLogger(org.neo4j.shell.log.AnsiLogger) CommandHelper(org.neo4j.shell.commands.CommandHelper) PrettyPrinter(org.neo4j.shell.prettyprint.PrettyPrinter) ByteArrayInputStream(java.io.ByteArrayInputStream) BoltStateHandler(org.neo4j.shell.state.BoltStateHandler)

Example 3 with BoltStateHandler

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"));
}
Also used : BoltStateHandler(org.neo4j.shell.state.BoltStateHandler) Driver(org.neo4j.driver.Driver) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Session(org.neo4j.driver.Session) LinePrinter(org.neo4j.shell.prettyprint.LinePrinter) Test(org.junit.Test)

Aggregations

BoltStateHandler (org.neo4j.shell.state.BoltStateHandler)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Test (org.junit.Test)2 ShellStatementParser (org.neo4j.shell.parser.ShellStatementParser)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 Driver (org.neo4j.driver.Driver)1 Session (org.neo4j.driver.Session)1 OfflineTestShell (org.neo4j.shell.OfflineTestShell)1 CommandHelper (org.neo4j.shell.commands.CommandHelper)1 AnsiLogger (org.neo4j.shell.log.AnsiLogger)1 Logger (org.neo4j.shell.log.Logger)1 LinePrinter (org.neo4j.shell.prettyprint.LinePrinter)1 PrettyPrinter (org.neo4j.shell.prettyprint.PrettyPrinter)1 BoltResult (org.neo4j.shell.state.BoltResult)1 ListBoltResult (org.neo4j.shell.state.ListBoltResult)1 Signal (sun.misc.Signal)1