use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class BiggerThanLogTxIT method shouldHandleSlaveCommittingLargeTx.
@Test
public void shouldHandleSlaveCommittingLargeTx() throws Exception {
// GIVEN
GraphDatabaseService slave = cluster.getAnySlave();
long initialNodeCount = nodeCount(slave);
// WHEN
cluster.info("Before commit large");
int nodeCount = commitLargeTx(slave);
cluster.info("Before sync");
cluster.sync();
cluster.info("After sync");
// THEN all should have that tx
assertAllMembersHasNodeCount(initialNodeCount + nodeCount);
// and if then master commits something, they should all get that too
cluster.info("Before commit small");
commitSmallTx(cluster.getMaster());
cluster.info("Before sync small");
cluster.sync();
cluster.info("After sync small");
assertAllMembersHasNodeCount(initialNodeCount + nodeCount + 1);
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class UdcExtensionImplTest method shouldLoadForEachCreatedGraphdb.
/**
* Expect separate counts for each graphdb.
*/
@Test
public void shouldLoadForEachCreatedGraphdb() throws IOException {
GraphDatabaseService graphdb1 = createDatabase(null);
GraphDatabaseService graphdb2 = createDatabase(null);
Set<String> successCountValues = UdcTimerTask.successCounts.keySet();
assertThat(successCountValues.size(), equalTo(2));
assertThat("this", is(not("that")));
cleanup(graphdb1);
cleanup(graphdb2);
}
use of org.neo4j.graphdb.GraphDatabaseService in project graphdb by neo4j-attic.
the class TestKernelEvents method testShutdownEvents.
@Test
public void testShutdownEvents() {
GraphDatabaseService graphDb = new EmbeddedGraphDatabase("target/var/neodb");
DummyKernelEventHandler handler1 = new DummyKernelEventHandler(RESOURCE1) {
public ExecutionOrder orderComparedTo(KernelEventHandler other) {
if (((DummyKernelEventHandler) other).resource == RESOURCE2) {
return ExecutionOrder.AFTER;
}
return ExecutionOrder.DOESNT_MATTER;
}
};
DummyKernelEventHandler handler2 = new DummyKernelEventHandler(RESOURCE1) {
public ExecutionOrder orderComparedTo(KernelEventHandler other) {
if (((DummyKernelEventHandler) other).resource == RESOURCE1) {
return ExecutionOrder.BEFORE;
}
return ExecutionOrder.DOESNT_MATTER;
}
};
graphDb.registerKernelEventHandler(handler1);
graphDb.registerKernelEventHandler(handler2);
graphDb.shutdown();
assertEquals(Integer.valueOf(0), handler2.beforeShutdown);
assertEquals(Integer.valueOf(1), handler1.beforeShutdown);
}
use of org.neo4j.graphdb.GraphDatabaseService in project graphdb by neo4j-attic.
the class TestReadOnlyNeo4j method testReadOnlyOperationsAndNoTransaction.
@Test
public void testReadOnlyOperationsAndNoTransaction() {
GraphDatabaseService db = new EmbeddedGraphDatabase(PATH);
Transaction tx = db.beginTx();
Node node1 = db.createNode();
Node node2 = db.createNode();
Relationship rel = node1.createRelationshipTo(node2, withName("TEST"));
node1.setProperty("key1", "value1");
rel.setProperty("key1", "value1");
tx.success();
tx.finish();
// make sure write operations still throw exception
try {
db.createNode();
fail("Write operation and no transaction should throw exception");
} catch (NotInTransactionException e) {
// good
}
try {
node1.createRelationshipTo(node2, withName("TEST2"));
fail("Write operation and no transaction should throw exception");
} catch (NotInTransactionException e) {
// good
}
try {
node1.setProperty("key1", "value2");
fail("Write operation and no transaction should throw exception");
} catch (NotInTransactionException e) {
// good
}
try {
rel.removeProperty("key1");
fail("Write operation and no transaction should throw exception");
} catch (NotInTransactionException e) {
// good
}
// clear caches and try reads
((AbstractGraphDatabase) db).getConfig().getGraphDbModule().getNodeManager().clearCache();
assertEquals(node1, db.getNodeById(node1.getId()));
assertEquals(node2, db.getNodeById(node2.getId()));
assertEquals(rel, db.getRelationshipById(rel.getId()));
((AbstractGraphDatabase) db).getConfig().getGraphDbModule().getNodeManager().clearCache();
assertEquals("value1", node1.getProperty("key1"));
Relationship loadedRel = node1.getSingleRelationship(DynamicRelationshipType.withName("TEST"), Direction.OUTGOING);
assertEquals(rel, loadedRel);
assertEquals("value1", loadedRel.getProperty("key1"));
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class BatchInsertionIT method shouldIndexNodesWithMultipleLabels.
@Test
public void shouldIndexNodesWithMultipleLabels() throws Exception {
// Given
File path = new File(dbRule.getStoreDirAbsolutePath());
BatchInserter inserter = BatchInserters.inserter(path, fileSystemRule.get());
inserter.createNode(map("name", "Bob"), label("User"), label("Admin"));
inserter.createDeferredSchemaIndex(label("User")).on("name").create();
inserter.createDeferredSchemaIndex(label("Admin")).on("name").create();
// When
inserter.shutdown();
// Then
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
try (Transaction tx = db.beginTx()) {
assertThat(count(db.findNodes(label("User"), "name", "Bob")), equalTo(1L));
assertThat(count(db.findNodes(label("Admin"), "name", "Bob")), equalTo(1L));
} finally {
db.shutdown();
}
}
Aggregations