Skip to content

Commit

Permalink
Revert "GEODE-8298: Fix multicast version detection (apache#5370)"
Browse files Browse the repository at this point in the history
This reverts commit fd76cc0
  • Loading branch information
Bill committed Jul 22, 2020
1 parent 2a2c2aa commit 78e182e
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ public String getUniqueId() {
return memberIdentifier.getUniqueId();
}

public void setVersionForTest(Version v) {
public void setVersionForTest(KnownVersion v) {
memberIdentifier.setVersionForTest(v);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ public void testReadEssentialData() throws IOException, ClassNotFoundException {
validate(newMember);
}

@Test
public void testSetVersionOrdinal() {
final GMSMemberData memberData = new GMSMemberData();
memberData.setVersionOrdinal(unknownVersionOrdinal);
validate(memberData);
}

private AbstractShortAssert<?> validate(final MemberData memberData) {
return assertThat(memberData.getVersionOrdinal()).isEqualTo(unknownVersionOrdinal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,12 @@
import org.apache.geode.distributed.internal.membership.gms.interfaces.JoinLeave;
import org.apache.geode.distributed.internal.membership.gms.interfaces.Messenger;
import org.apache.geode.internal.serialization.DSFIDSerializer;
import org.apache.geode.internal.serialization.KnownVersion;
import org.apache.geode.internal.serialization.Version;
import org.apache.geode.internal.serialization.Versioning;
import org.apache.geode.internal.serialization.internal.DSFIDSerializerImpl;
import org.apache.geode.test.junit.categories.MembershipTest;

@Category({MembershipTest.class})
public class GMSMembershipJUnitTest {

private static final Version OLDER_THAN_CURRENT_VERSION =
Versioning.getVersion((short) (KnownVersion.CURRENT_ORDINAL - 1));
private static final Version NEWER_THAN_CURRENT_VERSION =
Versioning.getVersion((short) (KnownVersion.CURRENT_ORDINAL + 1));;
private static final int DEFAULT_PORT = 8888;

private Services services;
private MembershipConfig mockConfig;
private Authenticator authenticator;
Expand Down Expand Up @@ -148,7 +139,7 @@ public long getAckSevereAlertThreshold() {
Random r = new Random();
mockMembers = new MemberIdentifier[5];
for (int i = 0; i < mockMembers.length; i++) {
mockMembers[i] = createMemberID(DEFAULT_PORT + i);
mockMembers[i] = createMemberID(8888 + i);
uuid = new UUID(r.nextLong(), r.nextLong());
mockMembers[i].setUUID(uuid);
}
Expand Down Expand Up @@ -184,7 +175,7 @@ public void testSendMessage() throws Exception {
MemberIdentifier myGMSMemberId = myMemberId;
List<MemberIdentifier> gmsMembers =
members.stream().map(x -> ((MemberIdentifier) x)).collect(Collectors.toList());
manager.getGMSManager().installView(new GMSMembershipView<>(myGMSMemberId, 1, gmsMembers));
manager.getGMSManager().installView(new GMSMembershipView(myGMSMemberId, 1, gmsMembers));
MemberIdentifier[] destinations = new MemberIdentifier[] {mockMembers[0]};
Set<MemberIdentifier> failures =
manager.send(destinations, m);
Expand All @@ -208,9 +199,9 @@ public void testStartupEvents() throws Exception {
manager.getGMSManager().started();
manager.isJoining = true;

List<MemberIdentifier> viewMembers =
List<MemberIdentifier> viewmembers =
Arrays.asList(new MemberIdentifier[] {mockMembers[0], myMemberId});
manager.getGMSManager().installView(createView(myMemberId, 2, viewMembers));
manager.getGMSManager().installView(createView(myMemberId, 2, viewmembers));

// add a surprise member that will be shunned due to it's having
// an old view ID
Expand All @@ -228,7 +219,7 @@ public void testStartupEvents() throws Exception {
// suspect a member
MemberIdentifier suspectMember = mockMembers[1];
manager.handleOrDeferSuspect(
new SuspectMember<>(mockMembers[0], suspectMember, "testing"));
new SuspectMember(mockMembers[0], suspectMember, "testing"));
// suspect messages aren't queued - they're ignored before joining the system
assertEquals(2, manager.getStartupEvents().size());
verify(listener, never()).memberSuspect(suspectMember, mockMembers[0], "testing");
Expand All @@ -241,9 +232,9 @@ public void testStartupEvents() throws Exception {
assertEquals(3, manager.getStartupEvents().size());

// this view officially adds surpriseMember2
viewMembers = Arrays
viewmembers = Arrays
.asList(new MemberIdentifier[] {mockMembers[0], myMemberId, surpriseMember2});
manager.handleOrDeferViewEvent(new MembershipView<>(myMemberId, 3, viewMembers));
manager.handleOrDeferViewEvent(new MembershipView(myMemberId, 3, viewmembers));
assertEquals(4, manager.getStartupEvents().size());

// add a surprise member that will be shunned due to it's having
Expand All @@ -256,13 +247,13 @@ public void testStartupEvents() throws Exception {
// process a new view after we finish joining but before event processing has started
manager.isJoining = false;
mockMembers[4].setVmViewId(4);
viewMembers = Arrays.asList(new MemberIdentifier[] {mockMembers[0], myMemberId,
viewmembers = Arrays.asList(new MemberIdentifier[] {mockMembers[0], myMemberId,
surpriseMember2, mockMembers[4]});
manager.handleOrDeferViewEvent(new MembershipView<>(myMemberId, 4, viewMembers));
manager.handleOrDeferViewEvent(new MembershipView(myMemberId, 4, viewmembers));
assertEquals(6, manager.getStartupEvents().size());

// exercise the toString methods for code coverage
for (StartupEvent<MemberIdentifier> ev : manager.getStartupEvents()) {
for (StartupEvent ev : manager.getStartupEvents()) {
ev.toString();
}

Expand All @@ -280,14 +271,14 @@ public void testStartupEvents() throws Exception {
// for code coverage also install a view after we finish joining but before
// event processing has started. This should notify the distribution manager
// with a LocalViewMessage to process the view
manager.handleOrDeferViewEvent(new MembershipView<>(myMemberId, 5, viewMembers));
manager.handleOrDeferViewEvent(new MembershipView(myMemberId, 5, viewmembers));
await().untilAsserted(() -> assertEquals(manager.getView().getViewId(), 5));

// process a suspect now - it will be passed to the listener
reset(listener);
suspectMember = mockMembers[1];
manager.handleOrDeferSuspect(
new SuspectMember<>(mockMembers[0], suspectMember, "testing"));
new SuspectMember(mockMembers[0], suspectMember, "testing"));
verify(listener).memberSuspect(suspectMember, mockMembers[0], "testing");
}

Expand All @@ -301,15 +292,15 @@ public void testAddressesWithoutUUIDs() throws Exception {
manager.getGMSManager().started();
manager.isJoining = true;

List<MemberIdentifier> viewMembers =
List<MemberIdentifier> viewmembers =
Arrays.asList(new MemberIdentifier[] {mockMembers[0], mockMembers[1], myMemberId});
GMSMembershipView view = createView(myMemberId, 2, viewMembers);
GMSMembershipView view = createView(myMemberId, 2, viewmembers);
manager.getGMSManager().installView(view);
when(services.getJoinLeave().getView()).thenReturn(view);

MemberIdentifier[] destinations = new MemberIdentifier[viewMembers.size()];
MemberIdentifier[] destinations = new MemberIdentifier[viewmembers.size()];
for (int i = 0; i < destinations.length; i++) {
MemberIdentifier id = viewMembers.get(i);
MemberIdentifier id = viewmembers.get(i);
destinations[i] = createMemberID(id.getMembershipPort());
}
manager.checkAddressesForUUIDs(destinations);
Expand Down Expand Up @@ -337,83 +328,4 @@ public void noDispatchWhenSick() throws MemberShunnedException, MemberStartupExc
assertThat(spy.getStartupEvents()).isEmpty();
}

@Test
public void testIsMulticastAllowedWithOldVersionSurpriseMember() {
MembershipView<MemberIdentifier> view = createMembershipView();
manager.addSurpriseMember(createSurpriseMember(OLDER_THAN_CURRENT_VERSION));

manager.processView(view);

assertThat(manager.getGMSManager().isMulticastAllowed()).isFalse();
}

@Test
public void testIsMulticastAllowedWithCurrentVersionSurpriseMember() {
MembershipView<MemberIdentifier> view = createMembershipView();
manager.addSurpriseMember(createSurpriseMember(KnownVersion.CURRENT));

manager.processView(view);

assertThat(manager.getGMSManager().isMulticastAllowed()).isTrue();
}

@Test
public void testIsMulticastAllowedWithNewVersionSurpriseMember() {
MembershipView<MemberIdentifier> view = createMembershipView();
manager.addSurpriseMember(createSurpriseMember(NEWER_THAN_CURRENT_VERSION));

manager.processView(view);

assertThat(manager.getGMSManager().isMulticastAllowed()).isTrue();
}

@Test
public void testIsMulticastAllowedWithOldVersionViewMember() {
MembershipView<MemberIdentifier> view = createMembershipView();
view.getMembers().get(0).setVersionForTest(OLDER_THAN_CURRENT_VERSION);

manager.processView(view);

assertThat(manager.getGMSManager().isMulticastAllowed()).isFalse();
}

@Test
public void testMulticastAllowedWithCurrentVersionViewMember() {
MembershipView<MemberIdentifier> view = createMembershipView();

manager.processView(view);

assertThat(manager.getGMSManager().isMulticastAllowed()).isTrue();
}

@Test
public void testMulticastAllowedWithNewVersionViewMember() {
MembershipView<MemberIdentifier> view = createMembershipView();
view.getMembers().get(0).setVersionForTest(NEWER_THAN_CURRENT_VERSION);

manager.processView(view);

assertThat(manager.getGMSManager().isMulticastAllowed()).isTrue();
}

private MemberIdentifier createSurpriseMember(Version version) {
MemberIdentifier surpriseMember = createMemberID(DEFAULT_PORT + 5);
surpriseMember.setVmViewId(3);
surpriseMember.setVersionForTest(version);
return surpriseMember;
}

private MembershipView<MemberIdentifier> createMembershipView() {
List<MemberIdentifier> viewMembers = createMemberIdentifiers();
return new MembershipView<>(myMemberId, 2, viewMembers);
}

private List<MemberIdentifier> createMemberIdentifiers() {
List<MemberIdentifier> viewMembers = new ArrayList<>();
for (int i = 0; i < 2; ++i) {
MemberIdentifier memberIdentifier = createMemberID(DEFAULT_PORT + 6 + i);
viewMembers.add(memberIdentifier);
}
return viewMembers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.jgroups.util.UUID;

import org.apache.geode.internal.serialization.DeserializationContext;
import org.apache.geode.internal.serialization.KnownVersion;
import org.apache.geode.internal.serialization.SerializationContext;
import org.apache.geode.internal.serialization.Version;

Expand Down Expand Up @@ -49,6 +50,8 @@ public interface MemberData {

String getUniqueTag();

void setVersionOrdinal(short versionOrdinal);

void setUUID(UUID u);

UUID getUUID();
Expand Down Expand Up @@ -89,7 +92,7 @@ public interface MemberData {

void setVmKind(int vmKind);

void setVersion(Version v);
void setVersion(KnownVersion v);

void setDirectChannelPort(int directPort);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.apache.geode.internal.serialization.DataSerializableFixedID;
import org.apache.geode.internal.serialization.DeserializationContext;
import org.apache.geode.internal.serialization.KnownVersion;
import org.apache.geode.internal.serialization.SerializationContext;
import org.apache.geode.internal.serialization.Version;

Expand Down Expand Up @@ -190,7 +191,7 @@ void _readEssentialData(DataInput in, Function<InetAddress, String> hostnameReso

String getUniqueId();

void setVersionForTest(Version v);
void setVersionForTest(KnownVersion v);

void setUniqueTag(String tag);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ public String getUniqueTag() {
return uniqueTag;
}

@Override
public void setVersionOrdinal(short versionOrdinal) {
this.version = Versioning.getVersion(versionOrdinal);
}

@Override
public void setUUID(UUID u) {
if (u == null) {
Expand Down Expand Up @@ -502,8 +507,8 @@ public void setVmKind(int vmKind) {


@Override
public void setVersion(Version version) {
this.version = version;
public void setVersion(KnownVersion v) {
setVersionOrdinal(v.ordinal());
}

@Override
Expand Down Expand Up @@ -578,7 +583,7 @@ public void setHostName(String hostName) {
@Override
public void readEssentialData(DataInput in,
DeserializationContext context) throws IOException, ClassNotFoundException {
setVersion(Versioning.getVersion(VersioningIO.readOrdinal(in)));
setVersionOrdinal(VersioningIO.readOrdinal(in));

int flags = in.readShort();
this.networkPartitionDetectionEnabled = (flags & NPD_ENABLED_BIT) != 0;
Expand Down
Loading

0 comments on commit 78e182e

Please sign in to comment.