Search in sources :

Example 51 with NetView

use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.

the class JGroupsMessengerJUnitTest method testEncryptedJoinResponse.

@Test
public void testEncryptedJoinResponse() throws Exception {
    InternalDistributedMember otherMbr = new InternalDistributedMember("localhost", 8888);
    Properties p = new Properties();
    p.put(ConfigurationProperties.SECURITY_UDP_DHALGO, "AES:128");
    initMocks(false, p);
    NetView v = createView(otherMbr);
    GMSEncrypt otherMbrEncrptor = new GMSEncrypt(services);
    otherMbrEncrptor.setPublicKey(messenger.getPublicKey(messenger.getMemberID()), messenger.getMemberID());
    messenger.setPublicKey(otherMbrEncrptor.getPublicKeyBytes(), otherMbr);
    messenger.initClusterKey();
    JoinResponseMessage gfmsg = new JoinResponseMessage(otherMbr, messenger.getClusterSecretKey(), 1);
    short version = Version.CURRENT_ORDINAL;
    HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
    messenger.writeEncryptedMessage(gfmsg, version, out);
    byte[] requestBytes = out.toByteArray();
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(requestBytes));
    messenger.addRequestId(1, messenger.getMemberID());
    DistributionMessage gfMessageAtOtherMbr = messenger.readEncryptedMessage(dis, version, otherMbrEncrptor);
    assertEquals(gfmsg, gfMessageAtOtherMbr);
    // lets send view as well..
    InstallViewMessage installViewMessage = new InstallViewMessage(v, null, true);
    out = new HeapDataOutputStream(Version.CURRENT);
    messenger.writeEncryptedMessage(installViewMessage, version, out);
    requestBytes = out.toByteArray();
    otherMbrEncrptor.addClusterKey(((JoinResponseMessage) gfMessageAtOtherMbr).getSecretPk());
    dis = new DataInputStream(new ByteArrayInputStream(requestBytes));
    gfMessageAtOtherMbr = messenger.readEncryptedMessage(dis, version, otherMbrEncrptor);
    assertEquals(installViewMessage, gfMessageAtOtherMbr);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ByteArrayInputStream(java.io.ByteArrayInputStream) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) NetView(org.apache.geode.distributed.internal.membership.NetView) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DataInputStream(java.io.DataInputStream) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 52 with NetView

use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.

the class JGroupsMessengerJUnitTest method testEncryptedJoinRequest.

@Test
public void testEncryptedJoinRequest() throws Exception {
    InternalDistributedMember otherMbr = new InternalDistributedMember("localhost", 8888);
    Properties p = new Properties();
    p.put(ConfigurationProperties.SECURITY_UDP_DHALGO, "AES:128");
    initMocks(false, p);
    NetView v = createView(otherMbr);
    GMSEncrypt otherMbrEncrptor = new GMSEncrypt(services);
    messenger.setPublicKey(otherMbrEncrptor.getPublicKeyBytes(), otherMbr);
    messenger.initClusterKey();
    JoinRequestMessage gfmsg = new JoinRequestMessage(otherMbr, messenger.getMemberID(), null, 9789, 1);
    short version = Version.CURRENT_ORDINAL;
    HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
    messenger.writeEncryptedMessage(gfmsg, version, out);
    byte[] requestBytes = out.toByteArray();
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(requestBytes));
    DistributionMessage distributionMessage = messenger.readEncryptedMessage(dis, version, otherMbrEncrptor);
    assertEquals(gfmsg, distributionMessage);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ByteArrayInputStream(java.io.ByteArrayInputStream) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) NetView(org.apache.geode.distributed.internal.membership.NetView) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DataInputStream(java.io.DataInputStream) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 53 with NetView

use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.

the class JGroupsMessengerJUnitTest method testReceiver.

@Test
public void testReceiver() throws Exception {
    try {
        DistributionStats.enableClockStats = true;
        initMocks(false);
        JGroupsReceiver receiver = (JGroupsReceiver) messenger.myChannel.getReceiver();
        // a zero-length message is ignored
        Message msg = new Message(new JGAddress(messenger.getMemberID()));
        Object result = messenger.readJGMessage(msg);
        assertNull(result);
        // for code coverage we need to pump this message through the receiver
        receiver.receive(msg);
        // for more code coverage we need to actually set a buffer in the message
        msg.setBuffer(new byte[0]);
        result = messenger.readJGMessage(msg);
        assertNull(result);
        receiver.receive(msg);
        // now create a view and a real distribution-message
        InternalDistributedMember myAddress = messenger.getMemberID();
        InternalDistributedMember other = createAddress(8888);
        NetView v = new NetView(myAddress);
        v.add(other);
        when(joinLeave.getView()).thenReturn(v);
        messenger.installView(v);
        List<InternalDistributedMember> recipients = v.getMembers();
        SerialAckedMessage dmsg = new SerialAckedMessage();
        dmsg.setRecipients(recipients);
        // a message is ignored during manager shutdown
        msg = messenger.createJGMessage(dmsg, new JGAddress(other), Version.CURRENT_ORDINAL);
        when(manager.shutdownInProgress()).thenReturn(Boolean.TRUE);
        receiver.receive(msg);
        verify(manager, never()).processMessage(isA(DistributionMessage.class));
        assertTrue("There should be UDPDispatchRequestTime stats", services.getStatistics().getUDPDispatchRequestTime() > 0);
    } finally {
        DistributionStats.enableClockStats = false;
    }
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) SerialAckedMessage(org.apache.geode.distributed.internal.SerialAckedMessage) Message(org.jgroups.Message) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) JGroupsReceiver(org.apache.geode.distributed.internal.membership.gms.messenger.JGroupsMessenger.JGroupsReceiver) NetView(org.apache.geode.distributed.internal.membership.NetView) SerialAckedMessage(org.apache.geode.distributed.internal.SerialAckedMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 54 with NetView

use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.

the class GMSMembershipManagerJUnitTest method testReplyProcessorInitiatesSuspicion.

@Test
public void testReplyProcessorInitiatesSuspicion() throws Exception {
    DM dm = mock(DM.class);
    DMStats stats = mock(DMStats.class);
    InternalDistributedSystem system = InternalDistributedSystem.newInstanceForTesting(dm, distProperties);
    when(dm.getStats()).thenReturn(stats);
    when(dm.getSystem()).thenReturn(system);
    when(dm.getCancelCriterion()).thenReturn(stopper);
    when(dm.getMembershipManager()).thenReturn(manager);
    when(dm.getViewMembers()).thenReturn(members);
    when(dm.getDistributionManagerIds()).thenReturn(new HashSet(members));
    when(dm.addMembershipListenerAndGetDistributionManagerIds(any(MembershipListener.class))).thenReturn(new HashSet(members));
    manager.start();
    manager.started();
    manager.isJoining = true;
    List<InternalDistributedMember> viewmembers = Arrays.asList(new InternalDistributedMember[] { mockMembers[0], mockMembers[1], myMemberId });
    manager.installView(new NetView(myMemberId, 2, viewmembers));
    List<InternalDistributedMember> mbrs = new ArrayList<>(1);
    mbrs.add(mockMembers[0]);
    ReplyProcessor21 rp = new ReplyProcessor21(dm, mbrs);
    rp.enableSevereAlertProcessing();
    boolean result = rp.waitForReplies(WAIT_FOR_REPLIES_MILLIS);
    // the wait should have timed out
    assertFalse(result);
    verify(healthMonitor, atLeastOnce()).checkIfAvailable(isA(InternalDistributedMember.class), isA(String.class), isA(Boolean.class));
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) NetView(org.apache.geode.distributed.internal.membership.NetView) ArrayList(java.util.ArrayList) DM(org.apache.geode.distributed.internal.DM) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributedMembershipListener(org.apache.geode.distributed.internal.membership.DistributedMembershipListener) MembershipListener(org.apache.geode.distributed.internal.MembershipListener) HashSet(java.util.HashSet) ReplyProcessor21(org.apache.geode.distributed.internal.ReplyProcessor21) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 55 with NetView

use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.

the class GMSMembershipManagerJUnitTest method testStartupEvents.

@Test
public void testStartupEvents() throws Exception {
    manager.start();
    manager.started();
    manager.isJoining = true;
    List<InternalDistributedMember> viewmembers = Arrays.asList(new InternalDistributedMember[] { mockMembers[0], myMemberId });
    manager.installView(new NetView(myMemberId, 2, viewmembers));
    // add a surprise member that will be shunned due to it's having
    // an old view ID
    InternalDistributedMember surpriseMember = mockMembers[2];
    surpriseMember.setVmViewId(1);
    manager.handleOrDeferSurpriseConnect(surpriseMember);
    assertEquals(1, manager.getStartupEvents().size());
    // add a surprise member that will be accepted
    InternalDistributedMember surpriseMember2 = mockMembers[3];
    surpriseMember2.setVmViewId(3);
    manager.handleOrDeferSurpriseConnect(surpriseMember2);
    assertEquals(2, manager.getStartupEvents().size());
    // suspect a member
    InternalDistributedMember suspectMember = mockMembers[1];
    manager.handleOrDeferSuspect(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");
    HighPriorityAckedMessage m = new HighPriorityAckedMessage();
    mockMembers[0].setVmViewId(1);
    m.setRecipient(mockMembers[0]);
    m.setSender(mockMembers[1]);
    manager.handleOrDeferMessage(m);
    assertEquals(3, manager.getStartupEvents().size());
    // this view officially adds surpriseMember2
    viewmembers = Arrays.asList(new InternalDistributedMember[] { mockMembers[0], myMemberId, surpriseMember2 });
    manager.handleOrDeferViewEvent(new NetView(myMemberId, 3, viewmembers));
    assertEquals(4, manager.getStartupEvents().size());
    // add a surprise member that will be shunned due to it's having
    // an old view ID
    InternalDistributedMember surpriseMember3 = mockMembers[4];
    surpriseMember.setVmViewId(1);
    manager.handleOrDeferSurpriseConnect(surpriseMember);
    assertEquals(5, manager.getStartupEvents().size());
    // 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 InternalDistributedMember[] { mockMembers[0], myMemberId, surpriseMember2, mockMembers[4] });
    manager.handleOrDeferViewEvent(new NetView(myMemberId, 4, viewmembers));
    assertEquals(6, manager.getStartupEvents().size());
    // exercise the toString methods for code coverage
    for (StartupEvent ev : manager.getStartupEvents()) {
        ev.toString();
    }
    manager.startEventProcessing();
    // all startup events should have been processed
    assertEquals(0, manager.getStartupEvents().size());
    // the new view should have been installed
    assertEquals(4, manager.getView().getViewId());
    // supriseMember2 should have been announced
    verify(listener).newMemberConnected(surpriseMember2);
    // supriseMember should have been rejected (old view ID)
    verify(listener, never()).newMemberConnected(surpriseMember);
    // 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
    reset(listener);
    manager.handleOrDeferViewEvent(new NetView(myMemberId, 5, viewmembers));
    assertEquals(0, manager.getStartupEvents().size());
    verify(listener).messageReceived(isA(LocalViewMessage.class));
    // process a suspect now - it will be passed to the listener
    reset(listener);
    suspectMember = mockMembers[1];
    manager.handleOrDeferSuspect(new SuspectMember(mockMembers[0], suspectMember, "testing"));
    verify(listener).memberSuspect(suspectMember, mockMembers[0], "testing");
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) HighPriorityAckedMessage(org.apache.geode.distributed.internal.HighPriorityAckedMessage) SuspectMember(org.apache.geode.distributed.internal.membership.gms.SuspectMember) StartupEvent(org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager.StartupEvent) NetView(org.apache.geode.distributed.internal.membership.NetView) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

NetView (org.apache.geode.distributed.internal.membership.NetView)101 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)65 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)59 Test (org.junit.Test)59 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)57 HashSet (java.util.HashSet)25 InstallViewMessage (org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage)18 Message (org.jgroups.Message)14 ArrayList (java.util.ArrayList)12 JoinResponseMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage)10 UnitTest (org.apache.geode.test.junit.categories.UnitTest)10 LinkedList (java.util.LinkedList)9 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)9 IOException (java.io.IOException)8 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)8 Properties (java.util.Properties)7 FindCoordinatorResponse (org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorResponse)7 CancelException (org.apache.geode.CancelException)6 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)6 JoinRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)6