Search in sources :

Example 16 with GraphDatabaseShellServer

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

Example 17 with GraphDatabaseShellServer

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;
}
Also used : GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer)

Example 18 with GraphDatabaseShellServer

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);
}
Also used : Statement(org.junit.runners.model.Statement) TestRule(org.junit.rules.TestRule) EphemeralFileSystemRule(org.neo4j.test.rule.fs.EphemeralFileSystemRule) Settings(org.neo4j.kernel.configuration.Settings) ShellLobby(org.neo4j.shell.ShellLobby) HashMap(java.util.HashMap) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) DatabaseRule(org.neo4j.test.rule.DatabaseRule) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Assert.assertThat(org.junit.Assert.assertThat) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) After(org.junit.After) SystemOutput(org.neo4j.shell.impl.SystemOutput) QueryLoggerIT.readAllLines(org.neo4j.kernel.impl.query.QueryLoggerIT.readAllLines) Transaction(org.neo4j.graphdb.Transaction) Before(org.junit.Before) PrintWriter(java.io.PrintWriter) ImpermanentDatabaseRule(org.neo4j.test.rule.ImpermanentDatabaseRule) Result(org.neo4j.graphdb.Result) Matchers.allOf(org.hamcrest.Matchers.allOf) StringWriter(java.io.StringWriter) TestDirectory(org.neo4j.test.rule.TestDirectory) IOException(java.io.IOException) Test(org.junit.Test) File(java.io.File) List(java.util.List) Rule(org.junit.Rule) ShellException(org.neo4j.shell.ShellException) Matchers.contains(org.hamcrest.Matchers.contains) ShellClient(org.neo4j.shell.ShellClient) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) RuleChain.outerRule(org.junit.rules.RuleChain.outerRule) Matchers.containsString(org.hamcrest.Matchers.containsString) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) SystemOutput(org.neo4j.shell.impl.SystemOutput) HashMap(java.util.HashMap) PrintWriter(java.io.PrintWriter) Before(org.junit.Before)

Example 19 with GraphDatabaseShellServer

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();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) Transaction(org.neo4j.graphdb.Transaction) Relationship(org.neo4j.graphdb.Relationship) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 20 with GraphDatabaseShellServer

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();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) Transaction(org.neo4j.graphdb.Transaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Test(org.junit.Test)

Aggregations

GraphDatabaseShellServer (org.neo4j.shell.kernel.GraphDatabaseShellServer)20 Test (org.junit.Test)13 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)7 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)6 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 Transaction (org.neo4j.graphdb.Transaction)3 ShellServer (org.neo4j.shell.ShellServer)3 SystemOutput (org.neo4j.shell.impl.SystemOutput)3 PrintWriter (java.io.PrintWriter)2 HashSet (java.util.HashSet)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 GraphDatabaseFactory (org.neo4j.graphdb.factory.GraphDatabaseFactory)2 Output (org.neo4j.shell.Output)2 Response (org.neo4j.shell.Response)2 RmiPublicationIT.createDefaultConfigFile (org.neo4j.shell.RmiPublicationIT.createDefaultConfigFile)2 SameJvmClient (org.neo4j.shell.impl.SameJvmClient)2