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);
}
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;
}
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);
}
use of org.neo4j.shell.kernel.GraphDatabaseShellServer in project neo4j-documentation by neo4j.
the class ShellDocTest method testMatrix.
@Test
public void testMatrix() throws Exception {
GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().loadPropertiesFromURL(getClass().getResource("/autoindex.properties")).setConfig(record_id_batch_size, "1").newGraphDatabase();
final GraphDatabaseShellServer server = new GraphDatabaseShellServer(db, false);
Documenter doc = new Documenter("a matrix example", server);
doc.add("mknode --cd", "", "Create a reference node");
doc.add("mkrel -t ROOT -c -v", "created", "create the Thomas Andersson node");
doc.add("cd 1", "", "go to the new node");
doc.add("set name \"Thomas Andersson\"", "", "set the name property");
doc.add("mkrel -t KNOWS -cv", "", "create Thomas direct friends");
doc.add("cd 2", "", "go to the new node");
doc.add("set name \"Trinity\"", "", "set the name property");
doc.add("cd ..", "", "go back in the history stack");
doc.add("mkrel -t KNOWS -cv", "", "create Thomas direct friends");
doc.add("cd 3", "", "go to the new node");
doc.add("set name \"Morpheus\"", "", "set the name property");
doc.add("mkrel -t KNOWS 2", "", "create relationship to Trinity");
doc.add("ls -rv", "", "list the relationships of node 3");
doc.add("cd -r 2", "", "change the current position to relationship #2");
doc.add("set -t int age 3", "", "set the age property on the relationship");
doc.add("cd ..", "", "back to Morpheus");
doc.add("cd -r 3", "", "next relationship");
doc.add("set -t int age 90", "", "set the age property on the relationship");
doc.add("cd start", "", "position to the start node of the current relationship");
doc.add("", "", "We're now standing on Morpheus node, so let's create the rest of the friends.");
doc.add("mkrel -t KNOWS -c", "", "new node");
doc.add("ls -r", "", "list relationships on the current node");
doc.add("cd 4", "", "go to Cypher");
doc.add("set name Cypher", "", "set the name");
doc.add("mkrel -ct KNOWS", "", "create new node from Cypher");
// TODO: how to list outgoing relationships?
// doc.add( "ls -rd out", "", "list relationships" );
doc.add("ls -r", "", "list relationships");
doc.add("cd 5", "", "go to the Agent Smith node");
doc.add("set name \"Agent Smith\"", "", "set the name");
doc.add("mkrel -cvt CODED_BY", "", "outgoing relationship and new node");
doc.add("cd 6", "", "go there");
doc.add("set name \"The Architect\"", "", "set the name");
doc.add("cd", "", "go to the first node in the history stack");
doc.add("", "", "");
doc.add("start morpheus = node:node_auto_index(name='Morpheus') " + "match (morpheus)-[:KNOWS]-(zionist) " + "return zionist.name;", "Trinity", "Morpheus' friends, looking up Morpheus by name in the Neo4j autoindex");
// wrapping this in a tx will cause problems, so we don't
doc.run();
server.shutdown();
try (Transaction tx = db.beginTx()) {
assertEquals(7, Iterables.count(db.getAllRelationships()));
assertEquals(7, Iterables.count(db.getAllNodes()));
boolean foundRootAndNeoRelationship = false;
for (Relationship relationship : db.getAllRelationships()) {
if (relationship.getType().name().equals("ROOT")) {
foundRootAndNeoRelationship = true;
assertFalse("The root node should not have a name property.", relationship.getStartNode().hasProperty("name"));
assertEquals("Thomas Andersson", relationship.getEndNode().getProperty("name", null));
}
}
assertTrue("Could not find the node connecting the root and Neo nodes.", foundRootAndNeoRelationship);
tx.success();
}
try (PrintWriter writer = doc.getWriter("shell-matrix-example-graph");
Transaction tx = db.beginTx()) {
writer.println(createGraphViz("Shell Matrix Example", db, "graph"));
writer.flush();
tx.success();
}
db.shutdown();
}
use of org.neo4j.shell.kernel.GraphDatabaseShellServer in project neo4j-documentation by neo4j.
the class ShellDocTest method testDumpCypherResultSimple.
@Test
public void testDumpCypherResultSimple() throws Exception {
GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
final GraphDatabaseShellServer server = new GraphDatabaseShellServer(db, false);
try (Transaction tx = db.beginTx()) {
Documenter doc = new Documenter("simple cypher result dump", server);
doc.add("mknode --cd --np \"{'name':'Neo'}\"", "", "create a new node and go to it");
doc.add("mkrel -c -d i -t LIKES --np \"{'app':'foobar'}\"", "", "create a relationship");
doc.add("dump MATCH (n)-[r]-(m) WHERE n = {self} return n,r,m;", "create (_0 {`name`:\"Neo\"})", "Export the cypher statement results");
doc.run();
}
server.shutdown();
db.shutdown();
}
Aggregations