Search in sources :

Example 71 with GraphDatabaseService

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

the class NodeCountsTest method shouldIncludeNumberOfNodesAddedInTransaction.

@Test
public void shouldIncludeNumberOfNodesAddedInTransaction() throws Exception {
    // given
    GraphDatabaseService graphDb = db.getGraphDatabaseAPI();
    try (Transaction tx = graphDb.beginTx()) {
        graphDb.createNode();
        graphDb.createNode();
        tx.success();
    }
    long before = numberOfNodes();
    try (Transaction tx = graphDb.beginTx()) {
        // when
        graphDb.createNode();
        long nodeCount = countsForNode();
        // then
        assertEquals(before + 1, nodeCount);
        tx.success();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.Test)

Example 72 with GraphDatabaseService

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

the class IdGeneratorRebuildFailureEmulationTest method verifyAndDispose.

@After
public void verifyAndDispose() throws Exception {
    GraphDatabaseService graphdb = null;
    try {
        graphdb = new Database(storeDir);
        verifyData(graphdb);
    } finally {
        if (graphdb != null) {
            graphdb.shutdown();
        }
        if (fs != null) {
            fs.disposeAndAssertNoOpenFiles();
        }
        fs = null;
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) ImpermanentGraphDatabase(org.neo4j.test.ImpermanentGraphDatabase) After(org.junit.After)

Example 73 with GraphDatabaseService

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

the class IdGeneratorRebuildFailureEmulationTest method initialize.

@Before
public void initialize() {
    fs = new FileSystem();
    GraphDatabaseService graphdb = new Database(storeDir);
    createInitialData(graphdb);
    graphdb.shutdown();
    Map<String, String> params = new HashMap<>();
    params.put(GraphDatabaseSettings.rebuild_idgenerators_fast.name(), Settings.FALSE);
    Config config = Config.embeddedDefaults(params);
    factory = new StoreFactory(storeDir, config, new DefaultIdGeneratorFactory(fs), pageCacheRule.getPageCache(fs), fs, NullLogProvider.getInstance());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) HashMap(java.util.HashMap) Config(org.neo4j.kernel.configuration.Config) ImpermanentGraphDatabase(org.neo4j.test.ImpermanentGraphDatabase) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) Before(org.junit.Before)

Example 74 with GraphDatabaseService

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

the class RelationshipCountsTest method shouldNotCountRelationshipsDeletedInOtherTransaction.

@Test
public void shouldNotCountRelationshipsDeletedInOtherTransaction() throws Exception {
    // given
    GraphDatabaseService graphDb = db.getGraphDatabaseAPI();
    final Relationship rel;
    try (Transaction tx = graphDb.beginTx()) {
        Node node = graphDb.createNode();
        node.createRelationshipTo(graphDb.createNode(), withName("KNOWS"));
        rel = node.createRelationshipTo(graphDb.createNode(), withName("KNOWS"));
        node.createRelationshipTo(graphDb.createNode(), withName("KNOWS"));
        tx.success();
    }
    final Barrier.Control barrier = new Barrier.Control();
    long before = numberOfRelationships();
    Future<Long> tx = threading.execute(new NamedFunction<GraphDatabaseService, Long>("create-relationships") {

        @Override
        public Long apply(GraphDatabaseService graphDb) {
            try (Transaction tx = graphDb.beginTx()) {
                rel.delete();
                long whatThisThreadSees = countsForRelationship(null, null, null);
                barrier.reached();
                tx.success();
                return whatThisThreadSees;
            }
        }
    }, graphDb);
    barrier.await();
    // when
    long during = numberOfRelationships();
    barrier.release();
    long whatOtherThreadSees = tx.get();
    long after = numberOfRelationships();
    // then
    assertEquals(3, before);
    assertEquals(3, during);
    assertEquals(2, after);
    assertEquals(after, whatOtherThreadSees);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Relationship(org.neo4j.graphdb.Relationship) Node(org.neo4j.graphdb.Node) Barrier(org.neo4j.test.Barrier) Test(org.junit.Test)

Example 75 with GraphDatabaseService

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

the class RelationshipCountsTest method shouldCountRelationshipsByType.

@Test
public void shouldCountRelationshipsByType() throws Exception {
    // given
    final GraphDatabaseService graphDb = db.getGraphDatabaseAPI();
    try (Transaction tx = graphDb.beginTx()) {
        graphDb.createNode().createRelationshipTo(graphDb.createNode(), withName("FOO"));
        graphDb.createNode().createRelationshipTo(graphDb.createNode(), withName("FOO"));
        graphDb.createNode().createRelationshipTo(graphDb.createNode(), withName("BAR"));
        graphDb.createNode().createRelationshipTo(graphDb.createNode(), withName("BAR"));
        graphDb.createNode().createRelationshipTo(graphDb.createNode(), withName("BAR"));
        graphDb.createNode().createRelationshipTo(graphDb.createNode(), withName("BAZ"));
        tx.success();
    }
    // when
    long total = numberOfRelationships();
    long foo = numberOfRelationships(withName("FOO"));
    long bar = numberOfRelationships(withName("BAR"));
    long baz = numberOfRelationships(withName("BAZ"));
    long qux = numberOfRelationships(withName("QUX"));
    // then
    assertEquals(2, foo);
    assertEquals(3, bar);
    assertEquals(1, baz);
    assertEquals(0, qux);
    assertEquals(6, total);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) 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