Search in sources :

Example 66 with Transaction

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

the class IdBufferingRoleSwitchIT method createNodeWithProperties.

private Node createNodeWithProperties(GraphDatabaseService db, int numberOfProperties) {
    try (Transaction tx = db.beginTx()) {
        Node node = db.createNode();
        for (int i = 0; i < numberOfProperties; i++) {
            node.setProperty("key" + i, "value" + i);
        }
        tx.success();
        return node;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node)

Example 67 with Transaction

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

the class IdBufferingRoleSwitchIT method deleteNode.

private void deleteNode(Node node, GraphDatabaseService db) {
    try (Transaction tx = db.beginTx()) {
        node.delete();
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction)

Example 68 with Transaction

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

the class MeasureUpdatePullingRecordAndIndexGap method awaitIndexes.

private void awaitIndexes(ManagedCluster cluster) {
    for (GraphDatabaseService db : cluster.getAllMembers()) {
        try (Transaction tx = db.beginTx()) {
            db.schema().awaitIndexesOnline(1, MINUTES);
            tx.success();
        }
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction)

Example 69 with Transaction

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

the class SchemaIndexHaIT method createIndex.

private IndexDefinition createIndex(GraphDatabaseService db) {
    try (Transaction tx = db.beginTx()) {
        IndexDefinition index = db.schema().indexFor(label).on(key).create();
        tx.success();
        return index;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition)

Example 70 with Transaction

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

the class SchemaIndexHaIT method indexPopulationJobsShouldContinueThroughRoleSwitch.

@Test
public void indexPopulationJobsShouldContinueThroughRoleSwitch() throws Throwable {
    // GIVEN a cluster of 3
    ControlledGraphDatabaseFactory dbFactory = new ControlledGraphDatabaseFactory();
    ManagedCluster cluster = clusterRule.withDbFactory(dbFactory).startCluster();
    HighlyAvailableGraphDatabase firstMaster = cluster.getMaster();
    // where the master gets some data created as well as an index
    Map<Object, Node> data = createSomeData(firstMaster);
    createIndex(firstMaster);
    //dbFactory.awaitPopulationStarted( firstMaster );
    dbFactory.triggerFinish(firstMaster);
    // Pick a slave, pull the data and the index
    HighlyAvailableGraphDatabase aSlave = cluster.getAnySlave();
    aSlave.getDependencyResolver().resolveDependency(UpdatePuller.class).pullUpdates();
    // and await the index population to start. It will actually block as long as we want it to
    dbFactory.awaitPopulationStarted(aSlave);
    // WHEN we shut down the master
    cluster.shutdown(firstMaster);
    dbFactory.triggerFinish(aSlave);
    cluster.await(masterAvailable(firstMaster));
    // get the new master, which should be the slave we pulled from above
    HighlyAvailableGraphDatabase newMaster = cluster.getMaster();
    // THEN
    assertEquals("Unexpected new master", aSlave, newMaster);
    try (Transaction tx = newMaster.beginTx()) {
        IndexDefinition index = Iterables.single(newMaster.schema().getIndexes());
        awaitIndexOnline(index, newMaster, data);
        tx.success();
    }
    // FINALLY: let all db's finish
    for (HighlyAvailableGraphDatabase db : cluster.getAllMembers()) {
        dbFactory.triggerFinish(db);
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) UpdatePuller(org.neo4j.kernel.ha.UpdatePuller) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

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