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());
}
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;
}
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)));
}
}
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)));
}
}
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());
}
}
Aggregations