Search in sources :

Example 11 with ShellException

use of org.neo4j.shell.ShellException in project neo4j by neo4j.

the class GraphDatabaseShellServer method unbindAndRegisterTransaction.

public void unbindAndRegisterTransaction(Serializable clientId) throws ShellException {
    try {
        ThreadToStatementContextBridge threadToStatementContextBridge = getThreadToStatementContextBridge();
        KernelTransaction tx = threadToStatementContextBridge.getTopLevelTransactionBoundToThisThread(false);
        threadToStatementContextBridge.unbindTransactionFromCurrentThread();
        if (tx == null) {
            clients.remove(clientId);
        } else {
            clients.put(clientId, tx);
        }
    } catch (Exception e) {
        throw wrapException(e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException)

Example 12 with ShellException

use of org.neo4j.shell.ShellException in project neo4j by neo4j.

the class JSONParser method parse.

public static Object parse(String json) throws ShellException {
    try {
        final String input = json.trim();
        if (input.isEmpty()) {
            return null;
        }
        if (input.charAt(0) == '{') {
            return new JSONObject(input).toMap();
        }
        if (input.charAt(0) == '[') {
            return new JSONArray(input).toList();
        }
        final Object value = JSONObject.stringToValue(input);
        if (value.equals(null)) {
            return null;
        }
        return value;
    } catch (JSONException e) {
        throw new ShellException("Could not parse value " + json + " " + e.getMessage());
    }
}
Also used : ShellException(org.neo4j.shell.ShellException)

Example 13 with ShellException

use of org.neo4j.shell.ShellException in project neo4j by neo4j.

the class TransactionGuardIntegrationTest method terminateLongRunningShellPeriodicCommitQuery.

@Test
public void terminateLongRunningShellPeriodicCommitQuery() throws Exception {
    GraphDatabaseAPI database = startDatabaseWithTimeoutCustomGuard();
    GraphDatabaseShellServer shellServer = getGraphDatabaseShellServer(database);
    try {
        SameJvmClient client = getShellClient(shellServer);
        CollectingOutput commandOutput = new CollectingOutput();
        URL url = prepareTestImportFile(8);
        execute(shellServer, commandOutput, client.getId(), "USING PERIODIC COMMIT 5 LOAD CSV FROM '" + url + "' AS line CREATE ();");
        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) URL(java.net.URL) Test(org.junit.Test)

Example 14 with ShellException

use of org.neo4j.shell.ShellException in project neo4j by neo4j.

the class BashVariableInterpreterTest method customInterpreter.

@Test
public void customInterpreter() throws Exception {
    // GIVEN
    interpreter.addReplacer("test", new Replacer() {

        @Override
        public String getReplacement(ShellServer server, Session session) throws ShellException {
            return "Hello";
        }
    });
    // WHEN
    String interpreted = interpreter.interpret("\\test world", server, session);
    // THEN
    assertEquals("Hello world", interpreted);
}
Also used : ShellServer(org.neo4j.shell.ShellServer) Replacer(org.neo4j.shell.impl.BashVariableInterpreter.Replacer) ShellException(org.neo4j.shell.ShellException) Session(org.neo4j.shell.Session) Test(org.junit.Test)

Example 15 with ShellException

use of org.neo4j.shell.ShellException in project neo4j by neo4j.

the class RemoteClient method getServer.

public ShellServer getServer() {
    // Poke the server by calling a method, f.ex. the welcome() method.
    // If the connection is lost then try to reconnect, using the last
    // server lookup address.
    boolean hadServer = this.server != null;
    boolean shouldTryToReconnect = this.server == null;
    try {
        if (!shouldTryToReconnect) {
            server.welcome(initialSession);
        }
    } catch (RemoteException | ShellException ignored) {
        shouldTryToReconnect = true;
    }
    Exception originException = null;
    if (shouldTryToReconnect) {
        this.server = null;
        try {
            this.server = findRemoteServer();
            if (hadServer) {
                getOutput().println("[Reconnected to server]");
            }
        } catch (ShellException | RemoteException ee) {
            // Ok
            originException = ee;
        }
    }
    if (this.server == null) {
        throw new RuntimeException("Server closed or cannot be reached anymore: " + originException.getMessage(), originException);
    }
    return this.server;
}
Also used : RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException) ShellException(org.neo4j.shell.ShellException) RemoteException(java.rmi.RemoteException)

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