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);
}
}
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());
}
}
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);
}
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);
}
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;
}
Aggregations