Search in sources :

Example 6 with MemberIsAvailable

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

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

the class LenientObjectInputStreamTest method shouldStoreTheSerialVersionIdOfAClassTheFirstTimeItsDeserialised.

@Test
public void shouldStoreTheSerialVersionIdOfAClassTheFirstTimeItsDeserialised() throws IOException, ClassNotFoundException {
    // given
    MemberIsAvailable memberIsAvailable = memberIsAvailable();
    Payload payload = payloadFor(memberIsAvailable);
    VersionMapper versionMapper = new VersionMapper();
    // when
    new LenientObjectInputStream(inputStreamFor(payload), versionMapper).readObject();
    // then
    assertTrue(versionMapper.hasMappingFor(memberIsAvailable.getClass().getName()));
    assertEquals(serialVersionUIDFor(memberIsAvailable), versionMapper.mappingFor(memberIsAvailable.getClass().getName()));
}
Also used : MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable) Test(org.junit.Test)

Example 8 with MemberIsAvailable

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

the class LenientObjectOutputStreamTest method shouldUseDefaultSerialVersionUIDWhenSerialisingAnObjectifNoMappingExists.

@Test
public void shouldUseDefaultSerialVersionUIDWhenSerialisingAnObjectifNoMappingExists() throws IOException, ClassNotFoundException {
    // given
    VersionMapper emptyVersionMapper = new VersionMapper();
    MemberIsAvailable memberIsAvailable = memberIsAvailable();
    // when
    Object deserialisedObject = deserialise(serialise(memberIsAvailable, emptyVersionMapper));
    // then
    assertEquals(serialVersionUIDFor(memberIsAvailable), serialVersionUIDFor(deserialisedObject));
}
Also used : MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable) Test(org.junit.Test)

Example 9 with MemberIsAvailable

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

the class HANewSnapshotFunction method apply.

@Override
public Iterable<MemberIsAvailable> apply(Iterable<MemberIsAvailable> previousSnapshot, final MemberIsAvailable newMessage) {
    /*
         * If a master event is received, all events that set to slave that instance should be removed. The same
         * should happen to existing master events and backup events, no matter which instance they are for
         */
    if (newMessage.getRole().equals(MASTER)) {
        List<MemberIsAvailable> result = new LinkedList<>();
        for (MemberIsAvailable existing : previousSnapshot) {
            if ((isSlave(existing) && sameIds(newMessage, existing)) || isMaster(existing)) {
                continue;
            }
            result.add(existing);
        }
        result.add(newMessage);
        return result;
    } else /*
         * If a slave event is received, all existing slave events for that instance should be removed. The same for
         * master and backup, which means remove all events for that instance.
         */
    if (newMessage.getRole().equals(SLAVE)) {
        List<MemberIsAvailable> result = new LinkedList<>();
        for (MemberIsAvailable existing : previousSnapshot) {
            if (sameIds(newMessage, existing)) {
                continue;
            }
            result.add(existing);
        }
        result.add(newMessage);
        return result;
    } else if (newMessage.getRole().equals(OnlineBackupKernelExtension.BACKUP)) {
        List<MemberIsAvailable> result = new LinkedList<>();
        for (MemberIsAvailable existing : previousSnapshot) {
            if (existing.getRole().equals(OnlineBackupKernelExtension.BACKUP)) {
                continue;
            }
            result.add(existing);
        }
        result.add(newMessage);
        return result;
    }
    return Iterables.append(newMessage, previousSnapshot);
}
Also used : MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList)

Example 10 with MemberIsAvailable

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

the class LenientObjectOutputStreamTest method shouldUseStoredSerialVersionUIDWhenSerialisingAnObject.

@Test
public void shouldUseStoredSerialVersionUIDWhenSerialisingAnObject() throws IOException, ClassNotFoundException {
    // given
    MemberIsAvailable memberIsAvailable = memberIsAvailable();
    VersionMapper versionMapper = new VersionMapper();
    versionMapper.addMappingFor(memberIsAvailable.getClass().getName(), 12345L);
    // when
    Object deserialisedObject = deserialise(serialise(memberIsAvailable, versionMapper));
    // then
    assertEquals(12345L, serialVersionUIDFor(deserialisedObject));
}
Also used : MemberIsAvailable(org.neo4j.cluster.member.paxos.MemberIsAvailable) 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