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