use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster 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.impl.ha.ClusterManager.ManagedCluster 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.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.
the class TxPushStrategyConfigIT method shouldPushToOneLessSlaveOnSlaveCommit.
@Test
public void shouldPushToOneLessSlaveOnSlaveCommit() throws Exception {
ManagedCluster cluster = startCluster(4, 2, HaSettings.TxPushStrategy.fixed_descending);
int missed = 0;
missed += createTransactionOn(cluster, new InstanceId(FIRST_SLAVE));
assertLastTransactions(cluster, lastTx(MASTER, BASE_TX_ID + 1, missed), lastTx(FIRST_SLAVE, BASE_TX_ID + 1, missed), lastTx(SECOND_SLAVE, BASE_TX_ID, missed), lastTx(THIRD_SLAVE, BASE_TX_ID + 1, missed));
missed += createTransactionOn(cluster, new InstanceId(SECOND_SLAVE));
assertLastTransactions(cluster, lastTx(MASTER, BASE_TX_ID + 2, missed), lastTx(FIRST_SLAVE, BASE_TX_ID + 1, missed), lastTx(SECOND_SLAVE, BASE_TX_ID + 2, missed), lastTx(THIRD_SLAVE, BASE_TX_ID + 2, missed));
missed += createTransactionOn(cluster, new InstanceId(THIRD_SLAVE));
assertLastTransactions(cluster, lastTx(MASTER, BASE_TX_ID + 3, missed), lastTx(FIRST_SLAVE, BASE_TX_ID + 1, missed), lastTx(SECOND_SLAVE, BASE_TX_ID + 3, missed), lastTx(THIRD_SLAVE, BASE_TX_ID + 3, missed));
}
use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.
the class TxPushStrategyConfigIT method shouldPushToSlavesInAscendingOrder.
@Test
public void shouldPushToSlavesInAscendingOrder() throws Exception {
ManagedCluster cluster = startCluster(4, 2, HaSettings.TxPushStrategy.fixed_ascending);
for (int i = 0; i < 5; i++) {
int missed = createTransactionOnMaster(cluster);
assertLastTransactions(cluster, lastTx(FIRST_SLAVE, BASE_TX_ID + 1 + i, missed));
assertLastTransactions(cluster, lastTx(SECOND_SLAVE, BASE_TX_ID + 1 + i, missed));
assertLastTransactions(cluster, lastTx(THIRD_SLAVE, BASE_TX_ID, missed));
}
}
use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.
the class ReadOnlySlaveTest method givenClusterWithReadOnlySlaveWhenAddNewLabelOnSlaveThenThrowException.
@Test
public void givenClusterWithReadOnlySlaveWhenAddNewLabelOnSlaveThenThrowException() throws Throwable {
// Given
ManagedCluster cluster = clusterRule.startCluster();
Node node;
HighlyAvailableGraphDatabase master = cluster.getMaster();
try (Transaction tx = master.beginTx()) {
node = master.createNode();
tx.success();
}
// When
HighlyAvailableGraphDatabase readOnlySlave = cluster.getMemberByServerId(new InstanceId(2));
try (Transaction tx = readOnlySlave.beginTx()) {
Node slaveNode = readOnlySlave.getNodeById(node.getId());
// Then
slaveNode.addLabel(Label.label("FOO"));
tx.success();
fail("Should have thrown exception");
} catch (WriteOperationsNotAllowedException ex) {
// Ok!
}
}
Aggregations