Search in sources :

Example 11 with MemberIsAvailable

use of org.neo4j.cluster.member.paxos.MemberIsAvailable in project neo4j by neo4j.

the class HANewSnapshotFunctionTest method instanceBeingSlaveReappearsAsMasterShouldBeTreatedAsMaster.

@Test
public void instanceBeingSlaveReappearsAsMasterShouldBeTreatedAsMaster() throws Exception {
    // GIVEN these events
    List<MemberIsAvailable> events = new LinkedList<>();
    events.add(roleForId(SLAVE, 2));
    events.add(roleForId(SLAVE, 1));
    events.add(roleForId(MASTER, 1));
    events.add(roleForId(SLAVE, 3));
    // and this expected outcome
    List<MemberIsAvailable> expected = new LinkedList<>();
    expected.add(roleForId(SLAVE, 2));
    expected.add(roleForId(MASTER, 1));
    expected.add(roleForId(SLAVE, 3));
    // WHEN events start getting added
    Iterable<MemberIsAvailable> result = new LinkedList<>();
    for (MemberIsAvailable event : events) {
        result = new HANewSnapshotFunction().apply(result, event);
    }
    // THEN the result should be the expected one
    eventsMatch(result, expected);
}
Also used : MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 12 with MemberIsAvailable

use of org.neo4j.cluster.member.paxos.MemberIsAvailable in project neo4j by neo4j.

the class HANewSnapshotFunctionTest method instanceBeingBackupReplacedByAnotherInstanceShouldNotRemainBackup.

@Test
public void instanceBeingBackupReplacedByAnotherInstanceShouldNotRemainBackup() throws Exception {
    // GIVEN these events
    List<MemberIsAvailable> events = new LinkedList<>();
    events.add(roleForId(OnlineBackupKernelExtension.BACKUP, 1));
    events.add(roleForId(MASTER, 2));
    events.add(roleForId(OnlineBackupKernelExtension.BACKUP, 2));
    events.add(roleForId(SLAVE, 3));
    // and this expected outcome
    List<MemberIsAvailable> expected = new LinkedList<>();
    expected.add(roleForId(MASTER, 2));
    expected.add(roleForId(OnlineBackupKernelExtension.BACKUP, 2));
    expected.add(roleForId(SLAVE, 3));
    // WHEN events start getting added
    Iterable<MemberIsAvailable> result = new LinkedList<>();
    for (MemberIsAvailable event : events) {
        result = new HANewSnapshotFunction().apply(result, event);
    }
    // THEN the result should be the expected one
    eventsMatch(result, expected);
}
Also used : MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 13 with MemberIsAvailable

use of org.neo4j.cluster.member.paxos.MemberIsAvailable in project neo4j by neo4j.

the class HANewSnapshotFunctionTest method duplicateSlaveEventsShouldBeFilteredOut.

@Test
public void duplicateSlaveEventsShouldBeFilteredOut() throws Exception {
    // GIVEN
    // This is the list of events
    List<MemberIsAvailable> events = new LinkedList<>();
    events.add(roleForId(MASTER, 1));
    events.add(roleForId(SLAVE, 2));
    events.add(roleForId(SLAVE, 3));
    events.add(roleForId(SLAVE, 2));
    events.add(roleForId(SLAVE, 3));
    // This is what it should look like
    List<MemberIsAvailable> expected = new LinkedList<>();
    expected.add(roleForId(MASTER, 1));
    expected.add(roleForId(SLAVE, 2));
    expected.add(roleForId(SLAVE, 3));
    // WHEN events start getting added
    Iterable<MemberIsAvailable> result = new LinkedList<>();
    for (MemberIsAvailable event : events) {
        result = new HANewSnapshotFunction().apply(result, event);
    }
    // THEN the result should be the same as the one above
    eventsMatch(result, expected);
}
Also used : MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 14 with MemberIsAvailable

use of org.neo4j.cluster.member.paxos.MemberIsAvailable in project neo4j by neo4j.

the class HANewSnapshotFunctionTest method eventsMatch.

private void eventsMatch(Iterable<MemberIsAvailable> result, List<MemberIsAvailable> expected) {
    Iterator<MemberIsAvailable> iter = result.iterator();
    for (MemberIsAvailable anExpected : expected) {
        assertEquals(anExpected, iter.next());
    }
    assertFalse(iter.hasNext());
}
Also used : MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable)

Example 15 with MemberIsAvailable

use of org.neo4j.cluster.member.paxos.MemberIsAvailable in project neo4j by neo4j.

the class HANewSnapshotFunctionTest method normalClusterCreationShouldBePassedUnchanged.

@Test
public void normalClusterCreationShouldBePassedUnchanged() throws Exception {
    // GIVEN
    // This is what the end result should look like
    List<MemberIsAvailable> events = new LinkedList<>();
    events.add(roleForId(MASTER, 1));
    events.add(roleForId(SLAVE, 2));
    events.add(roleForId(SLAVE, 3));
    // WHEN events start getting added
    Iterable<MemberIsAvailable> result = new LinkedList<>();
    for (MemberIsAvailable event : events) {
        result = new HANewSnapshotFunction().apply(result, event);
    }
    // THEN the result is the expected one
    eventsMatch(result, events);
}
Also used : MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable) LinkedList(java.util.LinkedList) 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