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