use of org.neo4j.shell.parser.ShellStatementParser 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.parser.ShellStatementParser in project neo4j by neo4j.
the class InteractiveShellRunnerTest method emptyLineIsIgnored.
@Test
public void emptyLineIsIgnored() throws Exception {
// given
String inputString = " \nCREATE (n:Person) RETURN n;\n";
InputStream inputStream = new ByteArrayInputStream(inputString.getBytes());
InteractiveShellRunner runner = new InteractiveShellRunner(cmdExecuter, txHandler, databaseManager, logger, new ShellStatementParser(), inputStream, historyFile, userMessagesHandler, connectionConfig);
// when
List<String> statements = runner.readUntilStatement();
// then
assertEquals(1, statements.size());
assertThat(statements.get(0), is("CREATE (n:Person) RETURN n;"));
}
use of org.neo4j.shell.parser.ShellStatementParser 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.parser.ShellStatementParser in project neo4j by neo4j.
the class InteractiveShellRunnerTest method emptyStringThrowsNoMoreInput.
@Test
public void emptyStringThrowsNoMoreInput() throws Exception {
// then
thrown.expect(NoMoreInputException.class);
// given
String inputString = "";
InputStream inputStream = new ByteArrayInputStream(inputString.getBytes());
InteractiveShellRunner runner = new InteractiveShellRunner(cmdExecuter, txHandler, databaseManager, logger, new ShellStatementParser(), inputStream, historyFile, userMessagesHandler, connectionConfig);
// when
runner.readUntilStatement();
}
use of org.neo4j.shell.parser.ShellStatementParser in project neo4j by neo4j.
the class InteractiveShellRunnerTest method setup.
@Before
public void setup() throws Exception {
statementParser = new ShellStatementParser();
logger = mock(Logger.class);
cmdExecuter = mock(StatementExecuter.class);
txHandler = mock(TransactionHandler.class);
databaseManager = mock(DatabaseManager.class);
connectionConfig = mock(ConnectionConfig.class);
historyFile = temp.newFile();
badLineError = new ClientException("Found a bad line");
userMessagesHandler = mock(UserMessagesHandler.class);
when(databaseManager.getActualDatabaseAsReportedByServer()).thenReturn("mydb");
when(userMessagesHandler.getWelcomeMessage()).thenReturn("Welcome to cypher-shell!");
when(userMessagesHandler.getExitMessage()).thenReturn("Exit message");
when(connectionConfig.username()).thenReturn("myusername");
doThrow(badLineError).when(cmdExecuter).execute(contains("bad"));
doReturn(System.out).when(logger).getOutputStream();
}
Aggregations