Search in sources :

Example 6 with GraphDatabaseShellServer

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

the class ConfigurationIT method before.

@Before
public void before() throws Exception {
    db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().newGraphDatabase();
    server = new GraphDatabaseShellServer(db);
    client = ShellLobby.newClient(server, InterruptSignalHandler.getHandler());
}
Also used : GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Before(org.junit.Before)

Example 7 with GraphDatabaseShellServer

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

the class AppsIT method startEvenIfReferenceNodeHasBeenDeleted.

@Test
public void startEvenIfReferenceNodeHasBeenDeleted() throws Exception {
    Node node;
    try (Transaction tx = db.beginTx()) {
        node = db.createNode();
        String name = "Test";
        node.setProperty("name", name);
        tx.success();
    }
    GraphDatabaseShellServer server = new GraphDatabaseShellServer(db);
    ShellClient client = newShellClient(server);
    executeCommand(client, "pwd", Pattern.quote("(?)"));
    executeCommand(client, "ls " + node.getId(), "Test");
    executeCommand(client, "cd -a " + node.getId());
    executeCommand(client, "ls", "Test");
}
Also used : GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 8 with GraphDatabaseShellServer

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

the class StartClient method tryStartLocalServerAndClient.

private void tryStartLocalServerAndClient(File path, boolean readOnly, Args args, CtrlCHandler signalHandler) throws Exception {
    String configFile = args.get(ARG_CONFIG, null);
    final GraphDatabaseShellServer server = getGraphDatabaseShellServer(path, readOnly, configFile);
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            shutdownIfNecessary(server);
        }
    });
    if (!isCommandLine(args)) {
        out.println("NOTE: Local Neo4j graph database service at '" + path + "'");
    }
    ShellClient client = ShellLobby.newClient(server, getSessionVariablesFromArgs(args), new SystemOutput(out), signalHandler);
    grabPromptOrJustExecuteCommand(client, args);
    shutdownIfNecessary(server);
}
Also used : GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) SystemOutput(org.neo4j.shell.impl.SystemOutput)

Example 9 with GraphDatabaseShellServer

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

the class ClientIT method shouldExitMultilineModeAfterGettingWarningOrError.

@Test
public void shouldExitMultilineModeAfterGettingWarningOrError() throws ShellException, RemoteException {
    final CollectingOutput output = new CollectingOutput();
    final String message = "Test method called";
    final String prompt = "our test prompt";
    AbstractClient client = new AbstractClient(null, null) {

        @Override
        public ShellServer getServer() {
            ShellServer server = null;
            try {
                server = new GraphDatabaseShellServer(null) {

                    @Override
                    public Response interpretLine(Serializable clientId, String line, Output out) throws ShellException {
                        try {
                            out.println(message);
                        } catch (RemoteException ignored) {
                        }
                        return new Response(prompt, line.endsWith(";") ? Continuation.EXCEPTION_CAUGHT : Continuation.INPUT_INCOMPLETE);
                    }
                };
            } catch (RemoteException ignored) {
            }
            return server;
        }

        @Override
        public Output getOutput() {
            return output;
        }
    };
    client.evaluate("RETURN ");
    assertThat(client.getPrompt(), equalTo("> "));
    client.evaluate("i;");
    Set<String> messages = new HashSet<>();
    for (String s : output) {
        messages.add(s);
    }
    assertThat(messages, contains(message));
    assertThat(client.getPrompt(), equalTo(prompt));
}
Also used : Serializable(java.io.Serializable) ShellException(org.neo4j.shell.ShellException) Response(org.neo4j.shell.Response) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) ShellServer(org.neo4j.shell.ShellServer) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) Output(org.neo4j.shell.Output) RemoteException(java.rmi.RemoteException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with GraphDatabaseShellServer

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

the class ClientIT method shouldHandleNormalInput.

@Test
public void shouldHandleNormalInput() throws ShellException, RemoteException {
    final CollectingOutput output = new CollectingOutput();
    final String message = "Test method called";
    AbstractClient client = new AbstractClient(null, null) {

        @Override
        public ShellServer getServer() {
            ShellServer server = null;
            try {
                server = new GraphDatabaseShellServer(null) {

                    @Override
                    public Response interpretLine(Serializable clientId, String line, Output out) throws ShellException {
                        try {
                            out.println(message);
                        } catch (RemoteException ignored) {
                        }
                        return new Response("", Continuation.INPUT_COMPLETE);
                    }
                };
            } catch (RemoteException ignored) {
            }
            return server;
        }

        @Override
        public Output getOutput() {
            return output;
        }
    };
    client.evaluate("RETURN 1;");
    Set<String> messages = new HashSet<>();
    for (String s : output) {
        messages.add(s);
    }
    assertThat(messages, contains(message));
}
Also used : Serializable(java.io.Serializable) ShellException(org.neo4j.shell.ShellException) Response(org.neo4j.shell.Response) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) ShellServer(org.neo4j.shell.ShellServer) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) Output(org.neo4j.shell.Output) RemoteException(java.rmi.RemoteException) HashSet(java.util.HashSet) Test(org.junit.Test)

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