use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class TestTransactionEvents method makeSureHandlersCantBeRegisteredTwice.
@Test
public void makeSureHandlersCantBeRegisteredTwice() {
DummyTransactionEventHandler<Object> handler = new DummyTransactionEventHandler<>(null);
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
db.registerTransactionEventHandler(handler);
db.registerTransactionEventHandler(handler);
try (Transaction tx = db.beginTx()) {
db.createNode().delete();
tx.success();
}
assertEquals(Integer.valueOf(0), handler.beforeCommit);
assertEquals(Integer.valueOf(1), handler.afterCommit);
assertNull(handler.afterRollback);
db.unregisterTransactionEventHandler(handler);
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class TransactionMonitorTest method shouldCountTerminatedTransactions.
@Test
public void shouldCountTerminatedTransactions() throws Exception {
GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
try {
TransactionCounters counts = db.getDependencyResolver().resolveDependency(TransactionCounters.class);
TransactionCountersChecker checker = new TransactionCountersChecker(counts);
try (Transaction tx = db.beginTx()) {
dbConsumer.accept(db);
tx.terminate();
}
checker.verifyTerminated(isWriteTx, counts);
} finally {
db.shutdown();
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class TransactionMonitorTest method shoulCountRolledBackTransactions.
@Test
public void shoulCountRolledBackTransactions() throws Exception {
GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
try {
TransactionCounters counts = db.getDependencyResolver().resolveDependency(TransactionCounters.class);
TransactionCountersChecker checker = new TransactionCountersChecker(counts);
try (Transaction tx = db.beginTx()) {
dbConsumer.accept(db);
tx.failure();
}
checker.verifyRolledBacked(isWriteTx, counts);
} finally {
db.shutdown();
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class TransactionMonitorTest method shouldCountCommittedTransactions.
@Test
public void shouldCountCommittedTransactions() throws Exception {
GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
try {
TransactionCounters counts = db.getDependencyResolver().resolveDependency(TransactionCounters.class);
TransactionCountersChecker checker = new TransactionCountersChecker(counts);
try (Transaction tx = db.beginTx()) {
dbConsumer.accept(db);
tx.success();
}
checker.verifyCommitted(isWriteTx, counts);
} finally {
db.shutdown();
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class DuplicatePropertyRemoverTest method setUp.
@BeforeClass
public static void setUp() {
GraphDatabaseFactory factory = new TestGraphDatabaseFactory();
GraphDatabaseService db = factory.newEmbeddedDatabase(storePath.absolutePath());
api = (GraphDatabaseAPI) db;
Label nodeLabel = Label.label("Label");
propertyNames = new ArrayList<>();
try (Transaction transaction = db.beginTx()) {
node = db.createNode(nodeLabel);
nodeId = node.getId();
for (int i = 0; i < PROPERTY_COUNT; i++) {
String propKey = "key" + i;
propertyNames.add(propKey);
String propValue = "value" + i;
boolean isBigProp = ThreadLocalRandom.current().nextBoolean();
if (isBigProp) {
propValue += propValue;
propValue += propValue;
propValue += propValue;
propValue += propValue;
propValue += propValue;
}
node.setProperty(propKey, propValue);
}
transaction.success();
}
Collections.shuffle(propertyNames);
DependencyResolver resolver = api.getDependencyResolver();
NeoStores neoStores = resolver.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
nodeStore = neoStores.getNodeStore();
PropertyKeyTokenStore propertyKeyTokenStore = neoStores.getPropertyKeyTokenStore();
indexedPropertyKeys = PropertyDeduplicatorTestUtil.indexPropertyKeys(propertyKeyTokenStore);
propertyStore = neoStores.getPropertyStore();
remover = new DuplicatePropertyRemover(nodeStore, propertyStore);
}
Aggregations