use of org.neo4j.cluster.member.paxos.MemberIsAvailable in project neo4j by neo4j.
the class HardKillIT method testMasterSwitchHappensOnKillMinus9.
@Test
public void testMasterSwitchHappensOnKillMinus9() throws Exception {
Process proc = null;
HighlyAvailableGraphDatabase dbWithId2 = null, dbWithId3 = null, oldMaster = null;
try {
proc = run(1);
dbWithId2 = startDb(2, path(2));
dbWithId3 = startDb(3, path(3));
waitUntilAllProperlyAvailable(dbWithId2, 1, MASTER, 2, SLAVE, 3, SLAVE);
waitUntilAllProperlyAvailable(dbWithId3, 1, MASTER, 2, SLAVE, 3, SLAVE);
final CountDownLatch newMasterAvailableLatch = new CountDownLatch(1);
dbWithId2.getDependencyResolver().resolveDependency(ClusterClient.class).addAtomicBroadcastListener(new AtomicBroadcastListener() {
@Override
public void receive(Payload value) {
try {
Object event = new AtomicBroadcastSerializer(new ObjectStreamFactory(), new ObjectStreamFactory()).receive(value);
if (event instanceof MemberIsAvailable) {
if (HighAvailabilityModeSwitcher.MASTER.equals(((MemberIsAvailable) event).getRole())) {
newMasterAvailableLatch.countDown();
}
}
} catch (Exception e) {
fail(e.toString());
}
}
});
proc.destroy();
proc = null;
assertTrue(newMasterAvailableLatch.await(60, SECONDS));
assertTrue(dbWithId2.isMaster());
assertTrue(!dbWithId3.isMaster());
// Ensure that everyone has marked the killed instance as failed, otherwise it cannot rejoin
waitUntilAllProperlyAvailable(dbWithId2, 1, UNKNOWN, 2, MASTER, 3, SLAVE);
waitUntilAllProperlyAvailable(dbWithId3, 1, UNKNOWN, 2, MASTER, 3, SLAVE);
oldMaster = startDb(1, path(1));
long oldMasterNode = createNamedNode(oldMaster, "Old master");
assertEquals(oldMasterNode, getNamedNode(dbWithId2, "Old master"));
} finally {
if (proc != null) {
proc.destroy();
}
if (oldMaster != null) {
oldMaster.shutdown();
}
if (dbWithId2 != null) {
dbWithId2.shutdown();
}
if (dbWithId3 != null) {
dbWithId3.shutdown();
}
}
}
use of org.neo4j.cluster.member.paxos.MemberIsAvailable in project neo4j by neo4j.
the class HANewSnapshotFunctionTest method instanceBeingMasterReappearsAsSlaveShouldBeTreatedAsSlave.
@Test
public void instanceBeingMasterReappearsAsSlaveShouldBeTreatedAsSlave() throws Exception {
// GIVEN these events
List<MemberIsAvailable> events = new LinkedList<>();
events.add(roleForId(MASTER, 1));
events.add(roleForId(SLAVE, 2));
events.add(roleForId(SLAVE, 1));
events.add(roleForId(SLAVE, 3));
// and this expected outcome
List<MemberIsAvailable> expected = new LinkedList<>();
expected.add(roleForId(SLAVE, 2));
expected.add(roleForId(SLAVE, 1));
expected.add(roleForId(SLAVE, 3));
// WHEN events start getting added
Iterable<MemberIsAvailable> result = new LinkedList<>();
for (MemberIsAvailable event : events) {
result = new HANewSnapshotFunction().apply(result, event);
}
// THEN the result should be the expected one
eventsMatch(result, expected);
}
use of org.neo4j.cluster.member.paxos.MemberIsAvailable in project neo4j by neo4j.
the class HANewSnapshotFunctionTest method instanceBeingBackupRepeatedlyShouldRemainBackupOnceOnly.
@Test
public void instanceBeingBackupRepeatedlyShouldRemainBackupOnceOnly() throws Exception {
// GIVEN these events
List<MemberIsAvailable> events = new LinkedList<>();
events.add(roleForId(OnlineBackupKernelExtension.BACKUP, 1));
events.add(roleForId(OnlineBackupKernelExtension.BACKUP, 1));
events.add(roleForId(OnlineBackupKernelExtension.BACKUP, 1));
events.add(roleForId(OnlineBackupKernelExtension.BACKUP, 1));
// and this expected outcome
List<MemberIsAvailable> expected = new LinkedList<>();
expected.add(roleForId(OnlineBackupKernelExtension.BACKUP, 1));
// WHEN events start getting added
Iterable<MemberIsAvailable> result = new LinkedList<>();
for (MemberIsAvailable event : events) {
result = new HANewSnapshotFunction().apply(result, event);
}
// THEN the result should be the expected one
eventsMatch(result, expected);
}
use of org.neo4j.cluster.member.paxos.MemberIsAvailable in project neo4j by neo4j.
the class HANewSnapshotFunctionTest method instanceBeingMasterReplacedByAnotherInstanceShouldNotRemainMaster.
@Test
public void instanceBeingMasterReplacedByAnotherInstanceShouldNotRemainMaster() throws Exception {
// GIVEN these events
List<MemberIsAvailable> events = new LinkedList<>();
events.add(roleForId(MASTER, 1));
events.add(roleForId(MASTER, 2));
events.add(roleForId(SLAVE, 3));
// and this expected outcome
List<MemberIsAvailable> expected = new LinkedList<>();
expected.add(roleForId(MASTER, 2));
expected.add(roleForId(SLAVE, 3));
// WHEN events start getting added
Iterable<MemberIsAvailable> result = new LinkedList<>();
for (MemberIsAvailable event : events) {
result = new HANewSnapshotFunction().apply(result, event);
}
// THEN the result should be the expected one
eventsMatch(result, expected);
}
use of org.neo4j.cluster.member.paxos.MemberIsAvailable in project neo4j by neo4j.
the class ClusterMembersSnapshotTest method snapshotListShouldContainOnlyOneEventForARoleWithTheSameIdWhenSwitchingFromSlaveToMaster.
@Test
public void snapshotListShouldContainOnlyOneEventForARoleWithTheSameIdWhenSwitchingFromSlaveToMaster() throws Exception {
// GIVEN
// -- a snapshot containing one member with a role
ClusterMembersSnapshot snapshot = new ClusterMembersSnapshot(new HANewSnapshotFunction());
URI clusterUri = new URI(URI);
InstanceId instanceId = new InstanceId(1);
MemberIsAvailable event1 = new MemberIsAvailable(SLAVE, instanceId, clusterUri, new URI(URI + "?something"), DEFAULT);
snapshot.availableMember(event1);
// WHEN
// -- the same member, although different role, gets added to the snapshot
MemberIsAvailable event2 = new MemberIsAvailable(MASTER, instanceId, clusterUri, new URI(URI + "?something"), DEFAULT);
snapshot.availableMember(event2);
// THEN
// -- getting the snapshot list should reveal both
assertEquals(1, Iterables.count(snapshot.getCurrentAvailable(instanceId)));
assertThat(snapshot.getCurrentAvailable(instanceId), hasItems(memberIsAvailable(event2)));
assertEquals(1, Iterables.count(snapshot.getCurrentAvailableMembers()));
assertThat(snapshot.getCurrentAvailableMembers(), hasItems(memberIsAvailable(event2)));
}
Aggregations