Search in sources :

Example 1 with HighlyAvailableGraphDatabase

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

the class UniquenessConstraintValidationHAIT method shouldPreventConcurrentCreationOfConflictingNonStringPropertyOnMasterAndSlave.

@Test
public void shouldPreventConcurrentCreationOfConflictingNonStringPropertyOnMasterAndSlave() throws Exception {
    // given
    ClusterManager.ManagedCluster cluster = clusterRule.startCluster();
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
    // when
    Future<Boolean> created;
    try (Transaction tx = master.beginTx()) {
        master.createNode(LABEL).setProperty(PROPERTY_KEY, 0x0099CC);
        created = otherThread.execute(createNode(slave, LABEL.name(), PROPERTY_KEY, 0x0099CC));
        assertThat(otherThread, isWaiting());
        tx.success();
    }
    // then
    assertFalse("creating violating data should fail", created.get());
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Test(org.junit.Test)

Example 2 with HighlyAvailableGraphDatabase

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

the class UniquenessConstraintValidationHAIT method shouldPreventConcurrentCreationOfConflictingDataOnSeparateHosts.

@Test
public void shouldPreventConcurrentCreationOfConflictingDataOnSeparateHosts() throws Exception {
    // given
    ClusterManager.ManagedCluster cluster = clusterRule.startCluster();
    HighlyAvailableGraphDatabase slave1 = cluster.getAnySlave();
    HighlyAvailableGraphDatabase slave2 = cluster.getAnySlave(/*except:*/
    slave1);
    // when
    Future<Boolean> created;
    try (Transaction tx = slave1.beginTx()) {
        slave1.createNode(LABEL).setProperty(PROPERTY_KEY, "value3");
        created = otherThread.execute(createNode(slave2, LABEL.name(), PROPERTY_KEY, "value3"));
        assertThat(otherThread, isWaiting());
        tx.success();
    }
    // then
    assertFalse("creating violating data should fail", created.get());
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Test(org.junit.Test)

Example 3 with HighlyAvailableGraphDatabase

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

the class UpdatePullerSwitchIT method createLabeledNodeOnMaster.

private void createLabeledNodeOnMaster(ClusterManager.ManagedCluster cluster, Label label) {
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    try (Transaction transaction = master.beginTx()) {
        Node masterNode = master.createNode();
        masterNode.addLabel(label);
        transaction.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) Node(org.neo4j.graphdb.Node)

Example 4 with HighlyAvailableGraphDatabase

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

the class ConstraintsInHAIT method creatingConstraintOnSlaveIsNotAllowed.

@Test
public void creatingConstraintOnSlaveIsNotAllowed() throws Exception {
    // given
    ClusterManager.ManagedCluster cluster = clusterRule.startCluster();
    HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
    slave.beginTx();
    try {
        ConstraintCreator constraintCreator = slave.schema().constraintFor(Label.label("LabelName")).assertPropertyIsUnique("PropertyName");
        // when
        constraintCreator.create();
        fail("should have thrown exception");
    } catch (InvalidTransactionTypeException e) {
        assertThat(e.getMessage(), equalTo("Modifying the database schema can only be done on the master server, " + "this server is a slave. Please issue schema modification commands directly to the master."));
    }
}
Also used : HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ConstraintCreator(org.neo4j.graphdb.schema.ConstraintCreator) InvalidTransactionTypeException(org.neo4j.graphdb.InvalidTransactionTypeException) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Test(org.junit.Test)

Example 5 with HighlyAvailableGraphDatabase

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

the class TestSlaveOnlyCluster method testMasterElectionAfterMasterRecoversInSlaveOnlyCluster.

@Test
public void testMasterElectionAfterMasterRecoversInSlaveOnlyCluster() throws Throwable {
    ManagedCluster cluster = clusterRule.startCluster();
    assertThat(cluster.getServerId(cluster.getMaster()), equalTo(new InstanceId(3)));
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    CountDownLatch masterFailedLatch = createMasterFailLatch(cluster);
    RepairKit repairKit = cluster.fail(master);
    try {
        assertTrue(masterFailedLatch.await(60, TimeUnit.SECONDS));
    } finally {
        repairKit.repair();
    }
    cluster.await(allSeesAllAsAvailable());
    long nodeId = createNodeWithPropertyOn(cluster.getAnySlave(), PROPERTY, VALUE);
    try (Transaction ignore = master.beginTx()) {
        assertThat(master.getNodeById(nodeId).getProperty(PROPERTY), equalTo(VALUE));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) InstanceId(org.neo4j.cluster.InstanceId) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) RepairKit(org.neo4j.kernel.impl.ha.ClusterManager.RepairKit) CountDownLatch(java.util.concurrent.CountDownLatch) 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