Search in sources :

Example 21 with Transaction

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

Example 22 with Transaction

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();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Test(org.junit.Test)

Example 23 with Transaction

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();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Test(org.junit.Test)

Example 24 with Transaction

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();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Test(org.junit.Test)

Example 25 with Transaction

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);
}
Also used : PropertyKeyTokenStore(org.neo4j.kernel.impl.store.PropertyKeyTokenStore) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Label(org.neo4j.graphdb.Label) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) NeoStores(org.neo4j.kernel.impl.store.NeoStores) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) BeforeClass(org.junit.BeforeClass)

Aggregations

Transaction (org.neo4j.graphdb.Transaction)2409 Node (org.neo4j.graphdb.Node)1086 Test (org.junit.jupiter.api.Test)751 Test (org.junit.Test)607 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)352 Relationship (org.neo4j.graphdb.Relationship)307 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)302 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)241 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)177 Label (org.neo4j.graphdb.Label)154 Result (org.neo4j.graphdb.Result)142 HashMap (java.util.HashMap)105 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)104 MethodSource (org.junit.jupiter.params.provider.MethodSource)103 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)86 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)77 File (java.io.File)74 ArrayList (java.util.ArrayList)73 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)67 Path (java.nio.file.Path)64