Search in sources :

Example 16 with MemberIsAvailable

use of org.neo4j.cluster.member.paxos.MemberIsAvailable 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 17 with MemberIsAvailable

use of org.neo4j.cluster.member.paxos.MemberIsAvailable 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 18 with MemberIsAvailable

use of org.neo4j.cluster.member.paxos.MemberIsAvailable 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

MemberIsAvailable (org.neo4j.cluster.member.paxos.MemberIsAvailable)18 Test (org.junit.Test)16 LinkedList (java.util.LinkedList)8 URI (java.net.URI)5 InstanceId (org.neo4j.cluster.InstanceId)5 ClusterMembersSnapshot (org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents.ClusterMembersSnapshot)5 HANewSnapshotFunction (org.neo4j.kernel.ha.cluster.HANewSnapshotFunction)4 IOException (java.io.IOException)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ClusterClient (org.neo4j.cluster.client.ClusterClient)1 PaxosClusterMemberEvents (org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents)1 AtomicBroadcastListener (org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastListener)1 AtomicBroadcastSerializer (org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer)1 ObjectStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory)1 Payload (org.neo4j.cluster.protocol.atomicbroadcast.Payload)1