Search in sources :

Example 1 with HANewSnapshotFunction

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)));
}
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 HANewSnapshotFunction

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)));
}
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 HANewSnapshotFunction

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)));
}
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 4 with HANewSnapshotFunction

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)));
}
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)4 Test (org.junit.Test)4 InstanceId (org.neo4j.cluster.InstanceId)4 MemberIsAvailable (org.neo4j.cluster.member.paxos.MemberIsAvailable)4 ClusterMembersSnapshot (org.neo4j.cluster.member.paxos.PaxosClusterMemberEvents.ClusterMembersSnapshot)4 HANewSnapshotFunction (org.neo4j.kernel.ha.cluster.HANewSnapshotFunction)4