use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class ManyMergesStressTest method shouldWorkFine.
@Test
public void shouldWorkFine() throws Throwable {
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
GraphDatabaseQueryService graph = new GraphDatabaseCypherService(db);
Label person = Label.label("Person");
try (Transaction tx = db.beginTx()) {
// THIS USED TO CAUSE OUT OF FILE HANDLES
// (maybe look at: http://stackoverflow.com/questions/6210348/too-many-open-files-error-on-lucene)
db.schema().indexFor(person).on("id").create();
// THIS SHOULD ALSO WORK
db.schema().constraintFor(person).assertPropertyIsUnique("id").create();
tx.success();
}
try (Transaction tx = db.beginTx()) {
db.schema().indexFor(person).on("name").create();
tx.success();
}
try (Transaction tx = db.beginTx()) {
db.schema().awaitIndexesOnline(1, TimeUnit.MINUTES);
tx.success();
}
for (int count = 0; count < TRIES; count++) {
Pair<String, String> stringPair = getRandomName();
String ident = stringPair.first();
String name = stringPair.other();
String id = Long.toString(Math.abs(random.nextLong()));
String query = format("MERGE (%s:Person {id: %s}) ON CREATE SET %s.name = \"%s\";", ident, id, ident, name);
try (InternalTransaction tx = graph.beginTransaction(KernelTransaction.Type.implicit, SecurityContext.AUTH_DISABLED)) {
Result result = db.execute(query);
result.close();
tx.success();
}
}
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class CypherLoggingTest method shouldNotLogQueries.
@Test
public void shouldNotLogQueries() throws Exception {
// given
AssertableLogProvider logProvider = new AssertableLogProvider();
GraphDatabaseService database = new TestGraphDatabaseFactory().setUserLogProvider(logProvider).newImpermanentDatabase();
// when
database.execute("CREATE (n:Reference) CREATE (foo {test:'me'}) RETURN n");
database.execute("MATCH (n) RETURN n");
// then
inLog(org.neo4j.cypher.internal.ExecutionEngine.class);
logProvider.assertNoLoggingOccurred();
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class CheckPointerIntegrationTest method shouldCheckPointBasedOnTime.
@Test
public void shouldCheckPointBasedOnTime() throws Throwable {
// given
long millis = 200;
GraphDatabaseService db = builder.setConfig(GraphDatabaseSettings.check_point_interval_time, millis + "ms").setConfig(GraphDatabaseSettings.check_point_interval_tx, "10000").setConfig(GraphDatabaseSettings.logical_log_rotation_threshold, "1g").newGraphDatabase();
// when
try (Transaction tx = db.beginTx()) {
db.createNode();
tx.success();
}
// The scheduled job checking whether or not checkpoints are needed runs more frequently
// now that we've set the time interval so low, so we can simply wait for it here
long endTime = currentTimeMillis() + SECONDS.toMillis(30);
while (!checkPointInTxLog(db)) {
Thread.sleep(millis);
assertTrue("Took too long to produce a checkpoint", currentTimeMillis() < endTime);
}
db.shutdown();
// then - 2 check points have been written in the log
List<CheckPoint> checkPoints = new CheckPointCollector(storeDir, fs).find(0);
assertTrue("Expected at least two (at least one for time interval and one for shutdown), was " + checkPoints.toString(), checkPoints.size() >= 2);
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class CheckPointerIntegrationTest method shouldCheckPointBasedOnTxCount.
@Test
public void shouldCheckPointBasedOnTxCount() throws Throwable {
// given
GraphDatabaseService db = builder.setConfig(GraphDatabaseSettings.check_point_interval_time, "300m").setConfig(GraphDatabaseSettings.check_point_interval_tx, "1").setConfig(GraphDatabaseSettings.logical_log_rotation_threshold, "1g").newGraphDatabase();
// when
try (Transaction tx = db.beginTx()) {
db.createNode();
tx.success();
}
// Instead of waiting 10s for the background job to do this check, perform the check right here
triggerCheckPointAttempt(db);
assertTrue(checkPointInTxLog(db));
db.shutdown();
// then - 2 check points have been written in the log
List<CheckPoint> checkPoints = new CheckPointCollector(storeDir, fs).find(0);
assertEquals(2, checkPoints.size());
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class CheckPointerIntegrationTest method shouldNotCheckPointWhenThereAreNoCommits.
@Test
public void shouldNotCheckPointWhenThereAreNoCommits() throws Throwable {
// given
GraphDatabaseService db = builder.setConfig(GraphDatabaseSettings.check_point_interval_time, "1s").setConfig(GraphDatabaseSettings.check_point_interval_tx, "10000").setConfig(GraphDatabaseSettings.logical_log_rotation_threshold, "1g").newGraphDatabase();
// when
// nothing happens
triggerCheckPointAttempt(db);
assertFalse(checkPointInTxLog(db));
db.shutdown();
// then - 1 check point has been written in the log
List<CheckPoint> checkPoints = new CheckPointCollector(storeDir, fs).find(0);
assertEquals(1, checkPoints.size());
}
Aggregations