Search in sources :

Example 11 with GraphDatabaseShellServer

use of org.neo4j.shell.kernel.GraphDatabaseShellServer in project neo4j by neo4j.

the class ShellBootstrapTest method shouldPickUpAllConfigOptions.

@Test
public void shouldPickUpAllConfigOptions() throws Exception {
    // GIVEN
    String host = "test";
    int port = 1234;
    String name = "my shell";
    Config config = Config.embeddedDefaults(stringMap(ShellSettings.remote_shell_host.name(), host, ShellSettings.remote_shell_port.name(), valueOf(port), ShellSettings.remote_shell_name.name(), name, ShellSettings.remote_shell_enabled.name(), TRUE.toString()));
    GraphDatabaseShellServer server = mock(GraphDatabaseShellServer.class);
    // WHEN
    server = new ShellBootstrap(config).enable(server);
    // THEN
    verify(server).makeRemotelyAvailable(host, port, name);
}
Also used : GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) Config(org.neo4j.kernel.configuration.Config) Test(org.junit.Test)

Example 12 with GraphDatabaseShellServer

use of org.neo4j.shell.kernel.GraphDatabaseShellServer in project neo4j by neo4j.

the class StartClientIT method testShellCloseAfterCommandExecution.

@Test
public void testShellCloseAfterCommandExecution() throws Exception {
    PrintStream out = mock(PrintStream.class);
    PrintStream err = mock(PrintStream.class);
    CtrlCHandler ctrlCHandler = mock(CtrlCHandler.class);
    final GraphDatabaseShellServer databaseShellServer = mock(GraphDatabaseShellServer.class);
    when(databaseShellServer.welcome(anyMap())).thenReturn(new Welcome(StringUtils.EMPTY, 1, StringUtils.EMPTY));
    when(databaseShellServer.interpretLine(any(Serializable.class), any(String.class), any(Output.class))).thenReturn(new Response(StringUtils.EMPTY, Continuation.INPUT_COMPLETE));
    StartClient startClient = new StartClient(out, err) {

        @Override
        protected GraphDatabaseShellServer getGraphDatabaseShellServer(File path, boolean readOnly, String configFile) throws RemoteException {
            return databaseShellServer;
        }
    };
    // when
    startClient.start(new String[] { "-path", db.getStoreDir(), "-c", "CREATE (n {foo:'bar'});" }, ctrlCHandler);
    // verify
    verify(databaseShellServer).shutdown();
}
Also used : PrintStream(java.io.PrintStream) Serializable(java.io.Serializable) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) SuppressOutput(org.neo4j.test.rule.SuppressOutput) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) Test(org.junit.Test)

Example 13 with GraphDatabaseShellServer

use of org.neo4j.shell.kernel.GraphDatabaseShellServer in project neo4j by neo4j.

the class TransactionGuardIntegrationTest method terminateLongRunningShellQuery.

@Test
public void terminateLongRunningShellQuery() throws Exception {
    GraphDatabaseAPI database = startDatabaseWithTimeout();
    GraphDatabaseShellServer shellServer = getGraphDatabaseShellServer(database);
    try {
        SameJvmClient client = getShellClient(shellServer);
        CollectingOutput commandOutput = new CollectingOutput();
        execute(shellServer, commandOutput, client.getId(), "begin Transaction");
        fakeClock.forward(3, TimeUnit.SECONDS);
        execute(shellServer, commandOutput, client.getId(), "create (n);");
        execute(shellServer, commandOutput, client.getId(), "commit");
        fail("Transaction should be already terminated.");
    } catch (ShellException e) {
        assertThat(e.getMessage(), containsString("Transaction timeout."));
    }
    assertDatabaseDoesNotHaveNodes(database);
}
Also used : SameJvmClient(org.neo4j.shell.impl.SameJvmClient) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) CollectingOutput(org.neo4j.shell.impl.CollectingOutput) ShellException(org.neo4j.shell.ShellException) Test(org.junit.Test)

Example 14 with GraphDatabaseShellServer

use of org.neo4j.shell.kernel.GraphDatabaseShellServer in project neo4j by neo4j.

the class TransactionGuardIntegrationTest method getGraphDatabaseShellServer.

private GraphDatabaseShellServer getGraphDatabaseShellServer(GraphDatabaseAPI database) throws RemoteException {
    GraphDatabaseShellServer shellServer = new GraphDatabaseShellServer(database);
    cleanupRule.add(shellServer);
    return shellServer;
}
Also used : GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer)

Example 15 with GraphDatabaseShellServer

use of org.neo4j.shell.kernel.GraphDatabaseShellServer in project neo4j by neo4j.

the class ShellQueryLoggingIT method setup.

@Before
public void setup() throws Exception {
    server = new GraphDatabaseShellServer(db.getGraphDatabaseAPI());
    SystemOutput output = new SystemOutput(new PrintWriter(out));
    client = ShellLobby.newClient(server, new HashMap<>(), output, action -> () -> {
    });
    // clear the output (remove the welcome message)
    out.getBuffer().setLength(0);
}
Also used : Statement(org.junit.runners.model.Statement) TestRule(org.junit.rules.TestRule) EphemeralFileSystemRule(org.neo4j.test.rule.fs.EphemeralFileSystemRule) Settings(org.neo4j.kernel.configuration.Settings) ShellLobby(org.neo4j.shell.ShellLobby) HashMap(java.util.HashMap) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) DatabaseRule(org.neo4j.test.rule.DatabaseRule) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Assert.assertThat(org.junit.Assert.assertThat) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) After(org.junit.After) SystemOutput(org.neo4j.shell.impl.SystemOutput) QueryLoggerIT.readAllLines(org.neo4j.kernel.impl.query.QueryLoggerIT.readAllLines) Transaction(org.neo4j.graphdb.Transaction) Before(org.junit.Before) PrintWriter(java.io.PrintWriter) ImpermanentDatabaseRule(org.neo4j.test.rule.ImpermanentDatabaseRule) Result(org.neo4j.graphdb.Result) Matchers.allOf(org.hamcrest.Matchers.allOf) StringWriter(java.io.StringWriter) TestDirectory(org.neo4j.test.rule.TestDirectory) IOException(java.io.IOException) Test(org.junit.Test) File(java.io.File) List(java.util.List) Rule(org.junit.Rule) ShellException(org.neo4j.shell.ShellException) Matchers.contains(org.hamcrest.Matchers.contains) ShellClient(org.neo4j.shell.ShellClient) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) RuleChain.outerRule(org.junit.rules.RuleChain.outerRule) Matchers.containsString(org.hamcrest.Matchers.containsString) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) SystemOutput(org.neo4j.shell.impl.SystemOutput) HashMap(java.util.HashMap) PrintWriter(java.io.PrintWriter) Before(org.junit.Before)

Aggregations

GraphDatabaseShellServer (org.neo4j.shell.kernel.GraphDatabaseShellServer)15 Test (org.junit.Test)9 File (java.io.File)5 ShellException (org.neo4j.shell.ShellException)5 Serializable (java.io.Serializable)3 RemoteException (java.rmi.RemoteException)3 Before (org.junit.Before)3 SystemOutput (org.neo4j.shell.impl.SystemOutput)3 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)3 HashSet (java.util.HashSet)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)2 Output (org.neo4j.shell.Output)2 Response (org.neo4j.shell.Response)2 RmiPublicationIT.createDefaultConfigFile (org.neo4j.shell.RmiPublicationIT.createDefaultConfigFile)2 ShellServer (org.neo4j.shell.ShellServer)2 SameJvmClient (org.neo4j.shell.impl.SameJvmClient)2 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 PrintWriter (java.io.PrintWriter)1