Search in sources :

Example 1 with BatchTransaction

use of org.neo4j.test.BatchTransaction in project neo4j by neo4j.

the class CreateAndLoadDenseNodeIT method createDbIfNecessary.

private void createDbIfNecessary() {
    if (!new File(dbRule.getStoreDir(), "neostore").exists()) {
        db = dbRule.getGraphDatabaseAPI();
        try (BatchTransaction tx = beginBatchTx(db)) {
            Node node = db.createNode();
            createRelationships(tx, node, MyRelTypes.TEST, INCOMING, 1);
            createRelationships(tx, node, MyRelTypes.TEST, OUTGOING, 3_000_000);
            createRelationships(tx, node, MyRelTypes.TEST2, OUTGOING, 5);
            createRelationships(tx, node, MyRelTypes.TEST2, BOTH, 5);
            createRelationships(tx, node, MyRelTypes.TEST_TRAVERSAL, OUTGOING, 2_000_000);
            createRelationships(tx, node, MyRelTypes.TEST_TRAVERSAL, INCOMING, 2);
        } finally {
            dbRule.shutdownAndKeepStore();
        }
    }
}
Also used : Node(org.neo4j.graphdb.Node) BatchTransaction(org.neo4j.test.BatchTransaction) File(java.io.File)

Example 2 with BatchTransaction

use of org.neo4j.test.BatchTransaction in project neo4j by neo4j.

the class BatchTransactionTest method shouldUseProgressListener.

@Test
public void shouldUseProgressListener() throws Exception {
    // GIVEN
    Transaction transaction = mock(Transaction.class);
    GraphDatabaseService db = mock(GraphDatabaseService.class);
    when(db.beginTx()).thenReturn(transaction);
    ProgressListener progress = mock(ProgressListener.class);
    BatchTransaction tx = beginBatchTx(db).withIntermediarySize(10).withProgress(progress);
    // WHEN
    tx.increment();
    tx.increment(9);
    // THEN
    verify(db, times(2)).beginTx();
    verify(transaction, times(1)).close();
    verify(progress, times(1)).add(1);
    verify(progress, times(1)).add(9);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) BatchTransaction(org.neo4j.test.BatchTransaction) Transaction(org.neo4j.graphdb.Transaction) ProgressListener(org.neo4j.helpers.progress.ProgressListener) BatchTransaction(org.neo4j.test.BatchTransaction) Test(org.junit.Test)

Aggregations

BatchTransaction (org.neo4j.test.BatchTransaction)2 File (java.io.File)1 Test (org.junit.Test)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 Node (org.neo4j.graphdb.Node)1 Transaction (org.neo4j.graphdb.Transaction)1 ProgressListener (org.neo4j.helpers.progress.ProgressListener)1