Search in sources :

Example 11 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class NoChangeWriteTransactionTest method shouldIdentifyTransactionWithNetZeroChangesAsReadOnly.

@Test
public void shouldIdentifyTransactionWithNetZeroChangesAsReadOnly() throws Exception {
    // GIVEN a transaction that has seen some changes, where all those changes result in a net 0 change set
    // a good way of producing such state is to add a label to an existing node, and then remove it.
    GraphDatabaseAPI db = dbr.getGraphDatabaseAPI();
    TransactionIdStore txIdStore = db.getDependencyResolver().resolveDependency(TransactionIdStore.class);
    long startTxId = txIdStore.getLastCommittedTransactionId();
    Node node = createEmptyNode(db);
    try (Transaction tx = db.beginTx()) {
        node.addLabel(TestLabels.LABEL_ONE);
        node.removeLabel(TestLabels.LABEL_ONE);
        tx.success();
    }
    // WHEN closing that transaction
    // THEN it should not have been committed
    assertEquals("Expected last txId to be what it started at + 2 (1 for the empty node, and one for the label)", startTxId + 2, txIdStore.getLastCommittedTransactionId());
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 12 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class GuardIT method startDataBase.

private GraphDatabaseAPI startDataBase() {
    GraphDatabaseAPI database = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
    cleanupRule.add(database);
    return database;
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory)

Example 13 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class CountsComputerTest method shouldCreateACountsStoreWhenThereAreNodesInTheDB.

@Test
public void shouldCreateACountsStoreWhenThereAreNodesInTheDB() throws IOException {
    @SuppressWarnings("deprecation") final GraphDatabaseAPI db = (GraphDatabaseAPI) dbBuilder.newGraphDatabase();
    try (Transaction tx = db.beginTx()) {
        db.createNode(Label.label("A"));
        db.createNode(Label.label("C"));
        db.createNode(Label.label("D"));
        db.createNode();
        tx.success();
    }
    long lastCommittedTransactionId = getLastTxId(db);
    db.shutdown();
    rebuildCounts(lastCommittedTransactionId);
    try (Lifespan life = new Lifespan()) {
        CountsTracker store = life.add(createCountsTracker());
        assertEquals(BASE_TX_ID + 1 + 1 + 1 + 1, store.txId());
        assertEquals(4, store.totalEntriesStored());
        assertEquals(4, get(store, nodeKey(-1)));
        assertEquals(1, get(store, nodeKey(0)));
        assertEquals(1, get(store, nodeKey(1)));
        assertEquals(1, get(store, nodeKey(2)));
        assertEquals(0, get(store, nodeKey(3)));
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) Test(org.junit.Test)

Example 14 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class CountsComputerTest method shouldCreateACountsStoreWhenThereAreUnusedNodeRecordsInTheDB.

@Test
public void shouldCreateACountsStoreWhenThereAreUnusedNodeRecordsInTheDB() throws IOException {
    @SuppressWarnings("deprecation") final GraphDatabaseAPI db = (GraphDatabaseAPI) dbBuilder.newGraphDatabase();
    try (Transaction tx = db.beginTx()) {
        db.createNode(Label.label("A"));
        db.createNode(Label.label("C"));
        Node node = db.createNode(Label.label("D"));
        db.createNode();
        node.delete();
        tx.success();
    }
    long lastCommittedTransactionId = getLastTxId(db);
    db.shutdown();
    rebuildCounts(lastCommittedTransactionId);
    try (Lifespan life = new Lifespan()) {
        CountsTracker store = life.add(createCountsTracker());
        assertEquals(BASE_TX_ID + 1 + 1 + 1 + 1, store.txId());
        assertEquals(3, store.totalEntriesStored());
        assertEquals(3, get(store, nodeKey(-1)));
        assertEquals(1, get(store, nodeKey(0)));
        assertEquals(1, get(store, nodeKey(1)));
        assertEquals(0, get(store, nodeKey(2)));
        assertEquals(0, get(store, nodeKey(3)));
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) Test(org.junit.Test)

Example 15 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class CountsComputerTest method shouldCreateAnEmptyCountsStoreFromAnEmptyDatabase.

@Test
public void shouldCreateAnEmptyCountsStoreFromAnEmptyDatabase() throws IOException {
    @SuppressWarnings("deprecation") final GraphDatabaseAPI db = (GraphDatabaseAPI) dbBuilder.newGraphDatabase();
    long lastCommittedTransactionId = getLastTxId(db);
    db.shutdown();
    rebuildCounts(lastCommittedTransactionId);
    try (Lifespan life = new Lifespan()) {
        CountsTracker store = life.add(createCountsTracker());
        // a transaction for creating the label and a transaction for the node
        assertEquals(BASE_TX_ID, store.txId());
        assertEquals(0, store.totalEntriesStored());
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) Test(org.junit.Test)

Aggregations

GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)133 Test (org.junit.Test)96 Transaction (org.neo4j.graphdb.Transaction)50 File (java.io.File)25 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)25 Node (org.neo4j.graphdb.Node)20 DependencyResolver (org.neo4j.graphdb.DependencyResolver)19 Config (org.neo4j.kernel.configuration.Config)15 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)12 IOException (java.io.IOException)8 PageCache (org.neo4j.io.pagecache.PageCache)8 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)8 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)8 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)6 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)6 Before (org.junit.Before)5 Label (org.neo4j.graphdb.Label)5 GraphDatabaseBuilder (org.neo4j.graphdb.factory.GraphDatabaseBuilder)5 GuardTimeoutException (org.neo4j.kernel.guard.GuardTimeoutException)5