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
}
}
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);
}
}
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);
}
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);
}
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()));
}
Aggregations