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)));
}
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()));
}
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));
}
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);
}
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));
}
Aggregations