Search in sources :

Example 31 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class TransactionConstraintsIT method startTxAsSlaveAndFinishItAfterHavingSwitchedToMasterShouldNotSucceed.

@Test
public void startTxAsSlaveAndFinishItAfterHavingSwitchedToMasterShouldNotSucceed() throws Exception {
    // GIVEN
    GraphDatabaseService db = cluster.getAnySlave(getSlaveOnlySlave());
    // WHEN
    Transaction tx = db.beginTx();
    try {
        db.createNode().setProperty("name", "slave");
        tx.success();
    } finally {
        HighlyAvailableGraphDatabase oldMaster = cluster.getMaster();
        cluster.shutdown(oldMaster);
        // Wait for new master
        cluster.await(masterAvailable(oldMaster));
        assertFinishGetsTransactionFailure(tx);
    }
    // THEN
    assertEquals(db, cluster.getMaster());
    // to prevent a deadlock scenario which occurs if this test exists (and @After starts)
    // before the db has recovered from its KERNEL_PANIC
    awaitFullyOperational(db);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) Test(org.junit.Test)

Example 32 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class TransactionConstraintsIT method slaveShouldNotBeAbleToProduceAnInvalidTransaction.

@Test
public void slaveShouldNotBeAbleToProduceAnInvalidTransaction() throws Exception {
    // GIVEN
    HighlyAvailableGraphDatabase aSlave = cluster.getAnySlave();
    Node node = createMiniTree(aSlave);
    Transaction tx = aSlave.beginTx();
    // Deleting this node isn't allowed since it still has relationships
    node.delete();
    tx.success();
    // EXPECT
    exception.expect(ConstraintViolationException.class);
    // WHEN
    tx.close();
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 33 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class TestClusterClientPadding method additionalClusterClientCanHelpBreakTiesWhenMasterFails.

@Test
public void additionalClusterClientCanHelpBreakTiesWhenMasterFails() throws Throwable {
    HighlyAvailableGraphDatabase sittingMaster = cluster.getMaster();
    cluster.fail(sittingMaster);
    cluster.await(masterAvailable(sittingMaster));
}
Also used : HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) Test(org.junit.Test)

Example 34 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class HACountsPropagationTest method shouldPropagateRelationshipCountsInHA.

@Test
public void shouldPropagateRelationshipCountsInHA() throws Throwable {
    ManagedCluster cluster = clusterRule.startCluster();
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    try (Transaction tx = master.beginTx()) {
        Node left = master.createNode();
        Node right = master.createNode(Label.label("A"));
        left.createRelationshipTo(right, RelationshipType.withName("Type"));
        tx.success();
    }
    cluster.sync();
    for (HighlyAvailableGraphDatabase db : cluster.getAllMembers()) {
        CountsTracker counts = counts(db);
        assertEquals(1, counts.relationshipCount(-1, -1, -1, newDoubleLongRegister()).readSecond());
        assertEquals(1, counts.relationshipCount(-1, -1, 0, newDoubleLongRegister()).readSecond());
        assertEquals(1, counts.relationshipCount(-1, 0, -1, newDoubleLongRegister()).readSecond());
        assertEquals(1, counts.relationshipCount(-1, 0, 0, newDoubleLongRegister()).readSecond());
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Node(org.neo4j.graphdb.Node) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) Test(org.junit.Test)

Example 35 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class HACountsPropagationTest method shouldPropagateNodeCountsInHA.

@Test
public void shouldPropagateNodeCountsInHA() throws Throwable {
    ManagedCluster cluster = clusterRule.startCluster();
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    try (Transaction tx = master.beginTx()) {
        master.createNode();
        master.createNode(Label.label("A"));
        tx.success();
    }
    cluster.sync();
    for (HighlyAvailableGraphDatabase db : cluster.getAllMembers()) {
        CountsTracker counts = counts(db);
        assertEquals(2, counts.nodeCount(-1, newDoubleLongRegister()).readSecond());
        assertEquals(1, counts.nodeCount(0, /* A */
        newDoubleLongRegister()).readSecond());
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) Test(org.junit.Test)

Aggregations

HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)80 Test (org.junit.Test)68 Transaction (org.neo4j.graphdb.Transaction)38 ClusterManager (org.neo4j.kernel.impl.ha.ClusterManager)24 Node (org.neo4j.graphdb.Node)22 ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)16 File (java.io.File)12 InstanceId (org.neo4j.cluster.InstanceId)10 Response (javax.ws.rs.core.Response)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 TransientTransactionFailureException (org.neo4j.graphdb.TransientTransactionFailureException)5 TestHighlyAvailableGraphDatabaseFactory (org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory)5 RepairKit (org.neo4j.kernel.impl.ha.ClusterManager.RepairKit)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 ClusterClient (org.neo4j.cluster.client.ClusterClient)4 TransactionTerminatedException (org.neo4j.graphdb.TransactionTerminatedException)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 IOException (java.io.IOException)3 URI (java.net.URI)3 ExecutionException (java.util.concurrent.ExecutionException)3