@Test public void testSignalHandleDuringExecution() throws Exception { 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); Thread t = new Thread(runner::runUntilEnd); t.start(); while (!t.getState().equals(Thread.State.TIMED_WAITING)) { Thread.sleep(100L); } runner.handle(new Signal(InteractiveShellRunner.INTERRUPT_SIGNAL)); verify(fakeShell).execute("RETURN 1;"); verify(fakeShell).reset(); verify(boltStateHandler).reset(); }
@Override public void handle(final Signal signal) { if (currentlyExecuting.get()) { executer.reset(); } else { logger.printError( AnsiFormattedText.s().colorRed() .append("\nInterrupted (Note that Cypher queries must end with a ") .bold().append("semicolon. ").boldOff() .append("Type ") .bold().append(Exit.COMMAND_NAME).append(" ").boldOff() .append("to exit the shell.)") .formattedString()); resetPrompt(); } }
InteractiveShellRunner implements ShellRunner, SignalHandler { @Override public void handle(final Signal signal) { if (currentlyExecuting.get()) { executer.reset(); } else { logger.printError( AnsiFormattedText.s().colorRed() .append("\nInterrupted (Note that Cypher queries must end with a ") .bold().append("semicolon. ").boldOff() .append("Type ") .bold().append(Exit.COMMAND_NAME).append(" ").boldOff() .append("to exit the shell.)") .formattedString()); resetPrompt(); } } }
InteractiveShellRunner implements ShellRunner, SignalHandler { @Override public void handle(final Signal signal) { if (currentlyExecuting.get()) { executer.reset(); } else { logger.printError( AnsiFormattedText.s().colorRed() .append("\nInterrupted (Note that Cypher queries must end with a ") .bold().append("semicolon. ").boldOff() .append("Type ") .bold().append(Exit.COMMAND_NAME).append(" ").boldOff() .append("to exit the shell.)") .formattedString()); resetPrompt(); } } InteractiveShellRunner(@Nonnull StatementExecuter executer,
                                  @Nonnull TransactionHandler txHandler,
                                  @Nonnull DatabaseManager databaseManager,
                                  @Nonnull Logger logger,
                                  @Nonnull StatementParser statementParser,
                                  @Nonnull InputStream inputStream,
                                  @Nonnull File historyFile,
                                  @Nonnull UserMessagesHandler userMessagesHandler,
                                  @Nonnull ConnectionConfig connectionConfig); }
InteractiveShellRunner implements ShellRunner, SignalHandler { @Override public void handle(final Signal signal) { if (currentlyExecuting.get()) { executer.reset(); } else { logger.printError( AnsiFormattedText.s().colorRed() .append("\nInterrupted (Note that Cypher queries must end with a ") .bold().append("semicolon. ").boldOff() .append("Type ") .bold().append(Exit.COMMAND_NAME).append(" ").boldOff() .append("to exit the shell.)") .formattedString()); resetPrompt(); } } InteractiveShellRunner(@Nonnull StatementExecuter executer,
                                  @Nonnull TransactionHandler txHandler,
                                  @Nonnull DatabaseManager databaseManager,
                                  @Nonnull Logger logger,
                                  @Nonnull StatementParser statementParser,
                                  @Nonnull InputStream inputStream,
                                  @Nonnull File historyFile,
                                  @Nonnull UserMessagesHandler userMessagesHandler,
                                  @Nonnull ConnectionConfig connectionConfig); @Override int runUntilEnd(); @Nonnull @Override Historian getHistorian(); @Nonnull List<String> readUntilStatement(); @Override void handle(final Signal signal); }
InteractiveShellRunner implements ShellRunner, SignalHandler { @Override public void handle(final Signal signal) { if (currentlyExecuting.get()) { executer.reset(); } else { logger.printError( AnsiFormattedText.s().colorRed() .append("\nInterrupted (Note that Cypher queries must end with a ") .bold().append("semicolon. ").boldOff() .append("Type ") .bold().append(Exit.COMMAND_NAME).append(" ").boldOff() .append("to exit the shell.)") .formattedString()); resetPrompt(); } } InteractiveShellRunner(@Nonnull StatementExecuter executer,
                                  @Nonnull TransactionHandler txHandler,
                                  @Nonnull DatabaseManager databaseManager,
                                  @Nonnull Logger logger,
                                  @Nonnull StatementParser statementParser,
                                  @Nonnull InputStream inputStream,
                                  @Nonnull File historyFile,
                                  @Nonnull UserMessagesHandler userMessagesHandler,
                                  @Nonnull ConnectionConfig connectionConfig); @Override int runUntilEnd(); @Nonnull @Override Historian getHistorian(); @Nonnull List<String> readUntilStatement(); @Override void handle(final Signal signal);  }