Search in sources :

Example 16 with GraphDatabaseService

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();
        }
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) Label(org.neo4j.graphdb.Label) GraphDatabaseCypherService(org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 17 with GraphDatabaseService

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();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 18 with GraphDatabaseService

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);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) CheckPoint(org.neo4j.kernel.impl.transaction.log.entry.CheckPoint) Test(org.junit.Test)

Example 19 with GraphDatabaseService

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());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) CheckPoint(org.neo4j.kernel.impl.transaction.log.entry.CheckPoint) Test(org.junit.Test)

Example 20 with GraphDatabaseService

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());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) CheckPoint(org.neo4j.kernel.impl.transaction.log.entry.CheckPoint) 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