Search in sources :

Example 61 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class TestBasicHaOperations method testBasicPropagationFromMasterToSlave.

@Test
public void testBasicPropagationFromMasterToSlave() throws Throwable {
    // given
    ManagedCluster cluster = clusterRule.startCluster();
    long nodeId = 4;
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    try (Transaction tx = master.beginTx()) {
        Node node = master.createNode();
        node.setProperty("Hello", "World");
        nodeId = node.getId();
        tx.success();
    }
    cluster.sync();
    // No need to wait, the push factor is 2
    HighlyAvailableGraphDatabase slave1 = cluster.getAnySlave();
    checkNodeOnSlave(nodeId, slave1);
    HighlyAvailableGraphDatabase slave2 = cluster.getAnySlave(slave1);
    checkNodeOnSlave(nodeId, slave2);
}
Also used : Transaction(org.neo4j.graphdb.Transaction) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 62 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class TestBasicHaOperations method checkNodeOnSlave.

private void checkNodeOnSlave(long nodeId, HighlyAvailableGraphDatabase slave2) {
    try (Transaction tx = slave2.beginTx()) {
        String value = slave2.getNodeById(nodeId).getProperty("Hello").toString();
        logger.getLogger().info("Hello=" + value);
        assertEquals("World", value);
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction)

Example 63 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class BiggerThanLogTxIT method nodeCount.

private long nodeCount(GraphDatabaseService db) {
    try (Transaction tx = db.beginTx()) {
        long count = Iterables.count(db.getAllNodes());
        tx.success();
        return count;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction)

Example 64 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class ClusterPartitionIT method ensureInstanceIsReadOnlyInPendingState.

/*
     * This method must be called on an instance that has had addSomeData() called on it.
     */
private void ensureInstanceIsReadOnlyInPendingState(HighlyAvailableGraphDatabase instance) {
    assertEquals(PENDING, instance.getInstanceState());
    tx(instance, retryACoupleOfTimesOn(TRANSIENT_ERRORS), db -> assertEquals(testPropValue, instance.getNodeById(testNodeId).getProperty(testPropKey)));
    try (Transaction ignored = instance.beginTx()) {
        instance.getNodeById(testNodeId).delete();
        fail("Should not be able to do write transactions when detached");
    } catch (TransientDatabaseFailureException | TransactionFailureException expected) {
    // expected
    }
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) Transaction(org.neo4j.graphdb.Transaction) TransientDatabaseFailureException(org.neo4j.graphdb.TransientDatabaseFailureException)

Example 65 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class ClusterTopologyChangesIT method createNodeOn.

private static Node createNodeOn(HighlyAvailableGraphDatabase db) {
    try (Transaction tx = db.beginTx()) {
        Node node = db.createNode();
        node.setProperty("key", String.valueOf(System.currentTimeMillis()));
        tx.success();
        return node;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node)

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