use of org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents.ClusterMembersSnapshot 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)));
}
use of org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents.ClusterMembersSnapshot in project neo4j by neo4j.
the class ClusterMembersSnapshotTest method snapshotListShouldContainOnlyOneEventForARoleWithTheSameIdWhenSwitchingFromMasterToSlave.
@Test
public void snapshotListShouldContainOnlyOneEventForARoleWithTheSameIdWhenSwitchingFromMasterToSlave() 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(MASTER, 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(SLAVE, 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)));
}
use of org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents.ClusterMembersSnapshot in project neo4j by neo4j.
the class ClusterMembersSnapshotTest method snapshotListPrunesSameMemberOnIdenticalAvailabilityEvents.
@Test
public void snapshotListPrunesSameMemberOnIdenticalAvailabilityEvents() throws Exception {
// GIVEN
// -- a snapshot containing one member with a role
ClusterMembersSnapshot snapshot = new ClusterMembersSnapshot(new PaxosClusterMemberEvents.UniqueRoleFilter());
URI clusterUri = new URI(URI);
InstanceId instanceId = new InstanceId(1);
MemberIsAvailable memberIsAvailable = new MemberIsAvailable(MASTER, instanceId, clusterUri, new URI(URI + "?something"), DEFAULT);
snapshot.availableMember(memberIsAvailable);
// WHEN
// -- the same member and role gets added to the snapshot
snapshot.availableMember(memberIsAvailable);
// THEN
// -- getting the snapshot list should only reveal the last one
assertEquals(1, Iterables.count(snapshot.getCurrentAvailable(instanceId)));
assertThat(snapshot.getCurrentAvailable(instanceId), hasItem(memberIsAvailable(memberIsAvailable)));
assertEquals(1, Iterables.count(snapshot.getCurrentAvailableMembers()));
assertThat(snapshot.getCurrentAvailableMembers(), hasItems(memberIsAvailable(memberIsAvailable)));
}
use of org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents.ClusterMembersSnapshot in project neo4j by neo4j.
the class ClusterMembersSnapshotTest method snapshotListPrunesOtherMemberWithSameMasterRole.
@Test
public void snapshotListPrunesOtherMemberWithSameMasterRole() 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 event = new MemberIsAvailable(MASTER, instanceId, clusterUri, new URI(URI + "?something1"), DEFAULT);
snapshot.availableMember(event);
// WHEN
// -- another member, but with same role, gets added to the snapshot
URI otherClusterUri = new URI(URI);
InstanceId otherInstanceId = new InstanceId(2);
MemberIsAvailable otherEvent = new MemberIsAvailable(MASTER, otherInstanceId, otherClusterUri, new URI(URI + "?something2"), DEFAULT);
snapshot.availableMember(otherEvent);
// THEN
// -- getting the snapshot list should only reveal the last member added, as it had the same role
assertEquals(1, Iterables.count(snapshot.getCurrentAvailable(otherInstanceId)));
assertThat(snapshot.getCurrentAvailable(otherInstanceId), hasItems(memberIsAvailable(otherEvent)));
assertEquals(1, Iterables.count(snapshot.getCurrentAvailableMembers()));
assertThat(snapshot.getCurrentAvailableMembers(), hasItems(memberIsAvailable(otherEvent)));
}
use of org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents.ClusterMembersSnapshot in project neo4j by neo4j.
the class ClusterMembersSnapshotTest method snapshotListDoesNotPruneOtherMemberWithSlaveRole.
@Test
public void snapshotListDoesNotPruneOtherMemberWithSlaveRole() 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 event = new MemberIsAvailable(SLAVE, instanceId, clusterUri, new URI(URI + "?something1"), DEFAULT);
snapshot.availableMember(event);
// WHEN
// -- another member, but with same role, gets added to the snapshot
URI otherClusterUri = new URI(URI);
InstanceId otherInstanceId = new InstanceId(2);
MemberIsAvailable otherEvent = new MemberIsAvailable(SLAVE, otherInstanceId, otherClusterUri, new URI(URI + "?something2"), DEFAULT);
snapshot.availableMember(otherEvent);
// THEN
assertEquals(2, Iterables.count(snapshot.getCurrentAvailableMembers()));
assertThat(snapshot.getCurrentAvailableMembers(), hasItems(memberIsAvailable(event), memberIsAvailable(otherEvent)));
}
Aggregations