Search in sources :

Example 31 with ShellException

use of org.neo4j.shell.ShellException 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 32 with ShellException

use of org.neo4j.shell.ShellException 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)

Example 33 with ShellException

use of org.neo4j.shell.ShellException 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)

Aggregations

ShellException (org.neo4j.shell.ShellException)33 RemoteException (java.rmi.RemoteException)12 Node (org.neo4j.graphdb.Node)6 Test (org.junit.Test)5 Relationship (org.neo4j.graphdb.Relationship)4 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)4 GraphDatabaseShellServer (org.neo4j.shell.kernel.GraphDatabaseShellServer)4 Serializable (java.io.Serializable)3 Kernel (org.neo4j.jmx.Kernel)3 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)3 Response (org.neo4j.shell.Response)3 Session (org.neo4j.shell.Session)3 ShellServer (org.neo4j.shell.ShellServer)3 JSONException (org.neo4j.shell.util.json.JSONException)3 ManagementFactory.getPlatformMBeanServer (java.lang.management.ManagementFactory.getPlatformMBeanServer)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 MBeanServer (javax.management.MBeanServer)2 Label (org.neo4j.graphdb.Label)2 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)2