Search in sources :

Example 46 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.

the class TestNeo4jCacheAndPersistence method testSameTxWithArray.

@Test
public void testSameTxWithArray() {
    getTransaction().success();
    getTransaction().finish();
    newTransaction();
    Node nodeA = getGraphDb().createNode();
    Node nodeB = getGraphDb().createNode();
    Relationship relA = nodeA.createRelationshipTo(nodeB, MyRelTypes.TEST);
    nodeA.setProperty(arrayKey, array);
    relA.setProperty(arrayKey, array);
    NodeManager nodeManager = ((EmbeddedGraphDatabase) getGraphDb()).getConfig().getGraphDbModule().getNodeManager();
    nodeManager.clearCache();
    assertTrue(nodeA.getProperty(arrayKey) != null);
    assertTrue(relA.getProperty(arrayKey) != null);
    relA.delete();
    nodeA.delete();
    nodeB.delete();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 47 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.

the class TestNeo4jCacheAndPersistence method testAddCacheCleared.

@Test
public void testAddCacheCleared() {
    Node nodeA = getGraphDb().createNode();
    nodeA.setProperty("1", 1);
    Node nodeB = getGraphDb().createNode();
    Relationship rel = nodeA.createRelationshipTo(nodeB, MyRelTypes.TEST);
    rel.setProperty("1", 1);
    getTransaction().success();
    getTransaction().finish();
    newTransaction();
    NodeManager nodeManager = ((EmbeddedGraphDatabase) getGraphDb()).getConfig().getGraphDbModule().getNodeManager();
    nodeManager.clearCache();
    nodeA.createRelationshipTo(nodeB, MyRelTypes.TEST);
    int count = 0;
    for (Relationship relToB : nodeA.getRelationships(MyRelTypes.TEST)) {
        count++;
    }
    assertEquals(2, count);
    nodeA.setProperty("2", 2);
    assertEquals(1, nodeA.getProperty("1"));
    rel.setProperty("2", 2);
    assertEquals(1, rel.getProperty("1"));
    nodeManager.clearCache();
    // trigger empty load
    getGraphDb().getNodeById(nodeA.getId());
    getGraphDb().getRelationshipById(rel.getId());
    // apply COW maps
    getTransaction().success();
    getTransaction().finish();
    newTransaction();
    count = 0;
    for (Relationship relToB : nodeA.getRelationships(MyRelTypes.TEST)) {
        count++;
    }
    assertEquals(2, count);
    assertEquals(1, nodeA.getProperty("1"));
    assertEquals(1, rel.getProperty("1"));
    assertEquals(2, nodeA.getProperty("2"));
    assertEquals(2, rel.getProperty("2"));
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 48 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.

the class TestNeo4jCacheAndPersistence method testLowGrabSize.

@Test
public void testLowGrabSize() {
    Map<String, String> config = new HashMap<String, String>();
    config.put("relationship_grab_size", "1");
    String storePath = getStorePath("neo2");
    deleteFileOrDirectory(storePath);
    EmbeddedGraphDatabase graphDb = new EmbeddedGraphDatabase(storePath, config);
    Transaction tx = graphDb.beginTx();
    Node node1 = graphDb.createNode();
    Node node2 = graphDb.createNode();
    node1.createRelationshipTo(node2, MyRelTypes.TEST);
    node2.createRelationshipTo(node1, MyRelTypes.TEST2);
    node1.createRelationshipTo(node2, MyRelTypes.TEST_TRAVERSAL);
    tx.success();
    tx.finish();
    tx = graphDb.beginTx();
    Set<Relationship> rels = new HashSet<Relationship>();
    RelationshipType[] types = new RelationshipType[] { MyRelTypes.TEST, MyRelTypes.TEST2, MyRelTypes.TEST_TRAVERSAL };
    graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache();
    for (Relationship rel : node1.getRelationships(types)) {
        assertTrue(rels.add(rel));
    }
    assertEquals(3, rels.size());
    rels.clear();
    graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache();
    for (Relationship rel : node1.getRelationships()) {
        assertTrue(rels.add(rel));
    }
    assertEquals(3, rels.size());
    rels.clear();
    graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache();
    for (Relationship rel : node2.getRelationships(types)) {
        assertTrue(rels.add(rel));
    }
    assertEquals(3, rels.size());
    rels.clear();
    graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache();
    for (Relationship rel : node2.getRelationships()) {
        assertTrue(rels.add(rel));
    }
    assertEquals(3, rels.size());
    rels.clear();
    graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache();
    for (Relationship rel : node1.getRelationships(Direction.OUTGOING)) {
        assertTrue(rels.add(rel));
    }
    assertEquals(2, rels.size());
    rels.clear();
    graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache();
    for (Relationship rel : node1.getRelationships(Direction.INCOMING)) {
        assertTrue(rels.add(rel));
    }
    assertEquals(1, rels.size());
    rels.clear();
    graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache();
    for (Relationship rel : node2.getRelationships(Direction.OUTGOING)) {
        assertTrue(rels.add(rel));
    }
    assertEquals(1, rels.size());
    rels.clear();
    graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache();
    for (Relationship rel : node2.getRelationships(Direction.INCOMING)) {
        assertTrue(rels.add(rel));
    }
    assertEquals(2, rels.size());
    tx.success();
    tx.finish();
    graphDb.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) Transaction(org.neo4j.graphdb.Transaction) HashMap(java.util.HashMap) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 49 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.

the class TestCacheTypes method testOldCache.

@Test
public void testOldCache() {
    GraphDatabaseService db = newDb("old");
    assertEquals(CacheType.old, ((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 50 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.

the class TestCacheTypes method testStrongCache.

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

Aggregations

EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)84 Test (org.junit.Test)50 File (java.io.File)35 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)32 Node (org.neo4j.graphdb.Node)26 Transaction (org.neo4j.graphdb.Transaction)17 Relationship (org.neo4j.graphdb.Relationship)14 BeforeClass (org.junit.BeforeClass)13 HashMap (java.util.HashMap)7 BatchInserterImpl (org.neo4j.kernel.impl.batchinsert.BatchInserterImpl)6 RandomAccessFile (java.io.RandomAccessFile)5 BatchInserter (org.neo4j.kernel.impl.batchinsert.BatchInserter)5 BatchInserterIndex (org.neo4j.graphdb.index.BatchInserterIndex)4 TransactionManager (javax.transaction.TransactionManager)3 Before (org.junit.Before)3 DynamicRelationshipType (org.neo4j.graphdb.DynamicRelationshipType)3 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)3 BatchInserterIndexProvider (org.neo4j.graphdb.index.BatchInserterIndexProvider)3 IndexManager (org.neo4j.graphdb.index.IndexManager)3 Transaction (javax.transaction.Transaction)2