use of org.neo4j.kernel.ha.cluster.HANewSnapshotFunction 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.kernel.ha.cluster.HANewSnapshotFunction 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.kernel.ha.cluster.HANewSnapshotFunction 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.kernel.ha.cluster.HANewSnapshotFunction 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