Search in sources :

Example 36 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project graphdb by neo4j-attic.

the class TestCacheTypes method testNoCache.

@Test
public void testNoCache() {
    GraphDatabaseService db = newDb("none");
    assertEquals(CacheType.none, ((EmbeddedGraphDatabase) db).getConfig().getGraphDbModule().getNodeManager().getCacheType());
    db.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Test(org.junit.Test)

Example 37 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project graphdb by neo4j-attic.

the class TestCacheTypes method testSoftRefCache.

@Test
public void testSoftRefCache() {
    GraphDatabaseService db = newDb("soft");
    assertEquals(CacheType.soft, ((EmbeddedGraphDatabase) db).getConfig().getGraphDbModule().getNodeManager().getCacheType());
    db.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Test(org.junit.Test)

Example 38 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project graphdb by neo4j-attic.

the class TestCacheTypes method testDefaultCache.

@Test
public void testDefaultCache() {
    GraphDatabaseService db = newDb(null);
    assertEquals(CacheType.soft, ((EmbeddedGraphDatabase) db).getConfig().getGraphDbModule().getNodeManager().getCacheType());
    db.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Test(org.junit.Test)

Example 39 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class TestTransactionEventsWithIndexes method nodeCanBeLegacyIndexedInBeforeCommit.

@Test
public void nodeCanBeLegacyIndexedInBeforeCommit() throws Exception {
    // Given we have a legacy index...
    GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    final Index<Node> index;
    try (Transaction tx = db.beginTx()) {
        index = db.index().forNodes("index");
        tx.success();
    }
    // ... and a transaction event handler that likes to add nodes to that index
    db.registerTransactionEventHandler(new TransactionEventHandler<Object>() {

        @Override
        public Object beforeCommit(TransactionData data) throws Exception {
            Iterator<Node> nodes = data.createdNodes().iterator();
            if (nodes.hasNext()) {
                Node node = nodes.next();
                index.add(node, "key", "value");
            }
            return null;
        }

        @Override
        public void afterCommit(TransactionData data, Object state) {
        }

        @Override
        public void afterRollback(TransactionData data, Object state) {
        }
    });
    // When we create a node...
    try (Transaction tx = db.beginTx()) {
        db.schema().awaitIndexesOnline(10, TimeUnit.SECONDS);
        Node node = db.createNode();
        node.setProperty("random", 42);
        tx.success();
    }
    // Then we should be able to look it up through the index.
    try (Transaction ignore = db.beginTx()) {
        Node node = single(index.get("key", "value"));
        assertThat(node.getProperty("random"), is((Object) 42));
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Iterator(java.util.Iterator) TransactionData(org.neo4j.graphdb.event.TransactionData) Test(org.junit.Test)

Example 40 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class TestMigrateToDenseNodeSupport method migrateDbWithDenseNodes.

@Test
public void migrateDbWithDenseNodes() throws Exception {
    // migrate
    new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(dir).setConfig(allow_store_upgrade, "true").newGraphDatabase().shutdown();
    // check consistency
    assertConsistentStore(dir);
    // open again to do extra checks
    GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(dir).newGraphDatabase();
    try (Transaction tx = db.beginTx()) {
        ResourceIterator<Node> allNodesWithLabel = db.findNodes(referenceNode);
        Node refNode = Iterators.single(allNodesWithLabel);
        int sparseCount = 0;
        for (Relationship relationship : refNode.getRelationships(Types.SPARSE, OUTGOING)) {
            verifySparseNode(db, relationship.getEndNode());
            sparseCount++;
        }
        int denseCount = 0;
        for (Relationship relationship : refNode.getRelationships(Types.DENSE, OUTGOING)) {
            verifyDenseNode(db, relationship.getEndNode());
            denseCount++;
        }
        assertEquals(10, sparseCount);
        assertEquals(10, denseCount);
        tx.success();
    }
    db.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Test(org.junit.Test)

Aggregations

GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)322 Test (org.junit.Test)225 Transaction (org.neo4j.graphdb.Transaction)182 Node (org.neo4j.graphdb.Node)142 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)77 File (java.io.File)70 Relationship (org.neo4j.graphdb.Relationship)49 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)32 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)17 Result (org.neo4j.graphdb.Result)14 Label (org.neo4j.graphdb.Label)13 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)12 HashMap (java.util.HashMap)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 PageCache (org.neo4j.io.pagecache.PageCache)10 DbRepresentation (org.neo4j.test.DbRepresentation)10 GraphDatabaseFactory (org.neo4j.graphdb.factory.GraphDatabaseFactory)9 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)8