Search in sources :

Example 21 with HighlyAvailableGraphDatabase

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

the class SchemaIndexHaIT method creatingIndexOnSlaveIsNotAllowed.

@Test
public void creatingIndexOnSlaveIsNotAllowed() throws Throwable {
    // GIVEN
    ManagedCluster cluster = clusterRule.startCluster();
    HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
    // WHEN
    try {
        createIndex(slave);
        fail("should have thrown exception");
    } catch (ConstraintViolationException e) {
    // expected
    }
}
Also used : HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) Test(org.junit.Test)

Example 22 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase 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)

Example 23 with HighlyAvailableGraphDatabase

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

the class TransactionTerminationIT method terminateMasterTransactionThatWaitsForLockAcquiredBySlave.

@Test
public void terminateMasterTransactionThatWaitsForLockAcquiredBySlave() throws Exception {
    ClusterManager.ManagedCluster cluster = startCluster();
    String masterValue = "master";
    String slaveValue = "slave";
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
    createNode(cluster);
    CountDownLatch slaveTxStarted = new CountDownLatch(1);
    CountDownLatch slaveTxCommit = new CountDownLatch(1);
    Future<?> slaveTx = setPropertyInSeparateThreadAndWaitBeforeCommit("slaveTx", slave, slaveValue, slaveTxStarted, slaveTxCommit);
    await(slaveTxStarted);
    AtomicReference<Transaction> masterTxReference = new AtomicReference<>();
    CountDownLatch masterTxStarted = new CountDownLatch(1);
    Future<?> masterTx = setPropertyInSeparateThreadAndAttemptToCommit("masterTx", master, masterValue, masterTxStarted, masterTxReference);
    masterTxStarted.await();
    sleepForAWhile();
    terminate(masterTxReference);
    assertTxWasTerminated(masterTx);
    slaveTxCommit.countDown();
    assertNull(slaveTx.get());
    assertNodeExists(cluster, slaveValue);
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) AtomicReference(java.util.concurrent.atomic.AtomicReference) Matchers.containsString(org.hamcrest.Matchers.containsString) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Test(org.junit.Test)

Example 24 with HighlyAvailableGraphDatabase

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

the class TransactionTerminationIT method terminateSlaveTransactionThatWaitsForLockOnMaster.

@Test
public void terminateSlaveTransactionThatWaitsForLockOnMaster() throws Exception {
    ClusterManager.ManagedCluster cluster = startCluster();
    String masterValue = "master";
    String slaveValue = "slave";
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
    createNode(cluster);
    CountDownLatch masterTxStarted = new CountDownLatch(1);
    CountDownLatch masterTxCommit = new CountDownLatch(1);
    Future<?> masterTx = setPropertyInSeparateThreadAndWaitBeforeCommit("masterTx", master, masterValue, masterTxStarted, masterTxCommit);
    await(masterTxStarted);
    AtomicReference<Transaction> slaveTxReference = new AtomicReference<>();
    CountDownLatch slaveTxStarted = new CountDownLatch(1);
    Future<?> slaveTx = setPropertyInSeparateThreadAndAttemptToCommit("slaveTx", slave, slaveValue, slaveTxStarted, slaveTxReference);
    slaveTxStarted.await();
    sleepForAWhile();
    terminate(slaveTxReference);
    assertTxWasTerminated(slaveTx);
    masterTxCommit.countDown();
    assertNull(masterTx.get());
    assertNodeExists(cluster, masterValue);
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) AtomicReference(java.util.concurrent.atomic.AtomicReference) Matchers.containsString(org.hamcrest.Matchers.containsString) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Test(org.junit.Test)

Example 25 with HighlyAvailableGraphDatabase

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

the class MasterInfoServiceTest method masterShouldRespond404AndUNKNOWNWhenUnknown.

@Test
public void masterShouldRespond404AndUNKNOWNWhenUnknown() throws Exception {
    // given
    HighlyAvailableGraphDatabase database = mock(HighlyAvailableGraphDatabase.class);
    when(database.role()).thenReturn("unknown");
    MasterInfoService service = new MasterInfoService(null, database);
    // when
    Response response = service.isMaster();
    // then
    assertEquals(404, response.getStatus());
    assertEquals("UNKNOWN", String.valueOf(response.getEntity()));
}
Also used : Response(javax.ws.rs.core.Response) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) 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