Search in sources :

Example 1 with ClusterMembersSnapshot

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)));
}
Also used : HANewSnapshotFunction(org.neo4j.kernel.ha.cluster.HANewSnapshotFunction) InstanceId(org.neo4j.cluster.InstanceId) MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable) ClusterMembersSnapshot(org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents.ClusterMembersSnapshot) URI(java.net.URI) Test(org.junit.Test)

Example 2 with ClusterMembersSnapshot

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)));
}
Also used : HANewSnapshotFunction(org.neo4j.kernel.ha.cluster.HANewSnapshotFunction) InstanceId(org.neo4j.cluster.InstanceId) MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable) ClusterMembersSnapshot(org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents.ClusterMembersSnapshot) URI(java.net.URI) Test(org.junit.Test)

Example 3 with ClusterMembersSnapshot

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)));
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable) ClusterMembersSnapshot(org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents.ClusterMembersSnapshot) PaxosClusterMemberEvents(org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents) URI(java.net.URI) Test(org.junit.Test)

Example 4 with ClusterMembersSnapshot

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)));
}
Also used : HANewSnapshotFunction(org.neo4j.kernel.ha.cluster.HANewSnapshotFunction) InstanceId(org.neo4j.cluster.InstanceId) MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable) ClusterMembersSnapshot(org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents.ClusterMembersSnapshot) URI(java.net.URI) Test(org.junit.Test)

Example 5 with ClusterMembersSnapshot

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)));
}
Also used : HANewSnapshotFunction(org.neo4j.kernel.ha.cluster.HANewSnapshotFunction) InstanceId(org.neo4j.cluster.InstanceId) MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable) ClusterMembersSnapshot(org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents.ClusterMembersSnapshot) URI(java.net.URI) Test(org.junit.Test)

Aggregations

URI (java.net.URI)5 Test (org.junit.Test)5 InstanceId (org.neo4j.cluster.InstanceId)5 MemberIsAvailable (org.neo4j.cluster.member.paxos.MemberIsAvailable)5 ClusterMembersSnapshot (org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents.ClusterMembersSnapshot)5 HANewSnapshotFunction (org.neo4j.kernel.ha.cluster.HANewSnapshotFunction)4 PaxosClusterMemberEvents (org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents)1