Search in sources :

Example 66 with GraphDatabaseService

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

the class SchemaIndexProviderApprovalTest method init.

@BeforeClass
public static void init() {
    GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase();
    for (TestValue value : TestValue.values()) {
        createNode(db, PROPERTY_KEY, value.value);
    }
    noIndexRun = runFindByLabelAndProperty(db);
    createIndex(db, label(LABEL), PROPERTY_KEY);
    indexRun = runFindByLabelAndProperty(db);
    db.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) BeforeClass(org.junit.BeforeClass)

Example 67 with GraphDatabaseService

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

the class SchemaConstraintProviderApprovalTest method init.

@BeforeClass
public static void init() {
    GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase();
    for (TestValue value : TestValue.values()) {
        createNode(db, PROPERTY_KEY, value.value);
    }
    noIndexRun = runFindByLabelAndProperty(db);
    createConstraint(db, label(LABEL), PROPERTY_KEY);
    constraintRun = runFindByLabelAndProperty(db);
    db.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) BeforeClass(org.junit.BeforeClass)

Example 68 with GraphDatabaseService

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

the class NodeCountsTest method shouldNotSeeNodeCountsOfOtherTransaction.

@Test
public void shouldNotSeeNodeCountsOfOtherTransaction() throws Exception {
    // given
    GraphDatabaseService graphDb = db.getGraphDatabaseAPI();
    final Barrier.Control barrier = new Barrier.Control();
    long before = numberOfNodes();
    Future<Long> done = threading.execute(new NamedFunction<GraphDatabaseService, Long>("create-nodes") {

        @Override
        public Long apply(GraphDatabaseService graphDb) {
            try (Transaction tx = graphDb.beginTx()) {
                graphDb.createNode();
                graphDb.createNode();
                barrier.reached();
                long whatThisThreadSees = countsForNode();
                tx.success();
                return whatThisThreadSees;
            }
        }
    }, graphDb);
    barrier.await();
    // when
    long during = numberOfNodes();
    barrier.release();
    long whatOtherThreadSees = done.get();
    long after = numberOfNodes();
    // then
    assertEquals(0, before);
    assertEquals(0, during);
    assertEquals(after, whatOtherThreadSees);
    assertEquals(2, after);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Barrier(org.neo4j.test.Barrier) Test(org.junit.Test)

Example 69 with GraphDatabaseService

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

the class NodeCountsTest method shouldReportNumberOfNodes.

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

Example 70 with GraphDatabaseService

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

the class NodeCountsTest method shouldReportAccurateNumberOfNodesAfterDeletion.

@Test
public void shouldReportAccurateNumberOfNodesAfterDeletion() throws Exception {
    // given
    GraphDatabaseService graphDb = db.getGraphDatabaseAPI();
    Node one;
    try (Transaction tx = graphDb.beginTx()) {
        one = graphDb.createNode();
        graphDb.createNode();
        tx.success();
    }
    try (Transaction tx = graphDb.beginTx()) {
        one.delete();
        tx.success();
    }
    // when
    long nodeCount = numberOfNodes();
    // then
    assertEquals(1, nodeCount);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) 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