use of org.neo4j.cluster.member.paxos.MemberIsAvailable in project neo4j by neo4j.
the class HANewSnapshotFunctionTest method instanceBeingSlaveReappearsAsMasterShouldBeTreatedAsMaster.
@Test
public void instanceBeingSlaveReappearsAsMasterShouldBeTreatedAsMaster() throws Exception {
// GIVEN these events
List<MemberIsAvailable> events = new LinkedList<>();
events.add(roleForId(SLAVE, 2));
events.add(roleForId(SLAVE, 1));
events.add(roleForId(MASTER, 1));
events.add(roleForId(SLAVE, 3));
// and this expected outcome
List<MemberIsAvailable> expected = new LinkedList<>();
expected.add(roleForId(SLAVE, 2));
expected.add(roleForId(MASTER, 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 instanceBeingBackupReplacedByAnotherInstanceShouldNotRemainBackup.
@Test
public void instanceBeingBackupReplacedByAnotherInstanceShouldNotRemainBackup() throws Exception {
// GIVEN these events
List<MemberIsAvailable> events = new LinkedList<>();
events.add(roleForId(OnlineBackupKernelExtension.BACKUP, 1));
events.add(roleForId(MASTER, 2));
events.add(roleForId(OnlineBackupKernelExtension.BACKUP, 2));
events.add(roleForId(SLAVE, 3));
// and this expected outcome
List<MemberIsAvailable> expected = new LinkedList<>();
expected.add(roleForId(MASTER, 2));
expected.add(roleForId(OnlineBackupKernelExtension.BACKUP, 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 HANewSnapshotFunctionTest method duplicateSlaveEventsShouldBeFilteredOut.
@Test
public void duplicateSlaveEventsShouldBeFilteredOut() throws Exception {
// GIVEN
// This is the list of events
List<MemberIsAvailable> events = new LinkedList<>();
events.add(roleForId(MASTER, 1));
events.add(roleForId(SLAVE, 2));
events.add(roleForId(SLAVE, 3));
events.add(roleForId(SLAVE, 2));
events.add(roleForId(SLAVE, 3));
// This is what it should look like
List<MemberIsAvailable> expected = new LinkedList<>();
expected.add(roleForId(MASTER, 1));
expected.add(roleForId(SLAVE, 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 same as the one above
eventsMatch(result, expected);
}
use of org.neo4j.cluster.member.paxos.MemberIsAvailable in project neo4j by neo4j.
the class HANewSnapshotFunctionTest method eventsMatch.
private void eventsMatch(Iterable<MemberIsAvailable> result, List<MemberIsAvailable> expected) {
Iterator<MemberIsAvailable> iter = result.iterator();
for (MemberIsAvailable anExpected : expected) {
assertEquals(anExpected, iter.next());
}
assertFalse(iter.hasNext());
}
use of org.neo4j.cluster.member.paxos.MemberIsAvailable in project neo4j by neo4j.
the class HANewSnapshotFunctionTest method normalClusterCreationShouldBePassedUnchanged.
@Test
public void normalClusterCreationShouldBePassedUnchanged() throws Exception {
// GIVEN
// This is what the end result should look like
List<MemberIsAvailable> events = new LinkedList<>();
events.add(roleForId(MASTER, 1));
events.add(roleForId(SLAVE, 2));
events.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 is the expected one
eventsMatch(result, events);
}
Aggregations