Search in sources :

Example 11 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 12 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 13 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 14 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)

Example 15 with HighlyAvailableGraphDatabase

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

the class TerminationOfSlavesDuringPullUpdatesTest method slavesTerminateOrReadConsistentDataWhenApplyingBatchLargerThanSafeZone.

@Test
public void slavesTerminateOrReadConsistentDataWhenApplyingBatchLargerThanSafeZone() throws Throwable {
    long safeZone = TimeUnit.MILLISECONDS.toMillis(0);
    clusterRule.withSharedSetting(HaSettings.id_reuse_safe_zone_time, String.valueOf(safeZone));
    // given
    final ClusterManager.ManagedCluster cluster = clusterRule.startCluster();
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    // when
    // ... slaves and master has node with long string property
    long entityId = action.createInitialEntity(master);
    cluster.sync();
    // ... and property is removed on master
    action.removeProperties(master, entityId);
    Thread.sleep(100);
    // ... and maintenance is called to make sure "safe" ids are freed to be reused
    forceMaintenance(master);
    // ... and a new property is created on master that
    action.setNewProperties(master, entityId);
    final HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
    Race race = new Race();
    final AtomicBoolean end = new AtomicBoolean(false);
    for (int i = 0; i < READER_CONTESTANTS; i++) {
        race.addContestant(readContestant(action, entityId, slave, end));
    }
    race.addContestant(pullUpdatesContestant(slave, end));
    race.go();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) Race(org.neo4j.test.Race) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) 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