Search in sources :

Example 1 with JoinResponseMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage 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 2 with JoinResponseMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage in project geode by apache.

the class JGroupsMessengerJUnitTest method testMessageFiltering.

@Test
public void testMessageFiltering() throws Exception {
    initMocks(true);
    InternalDistributedMember mbr = createAddress(8888);
    NetView view = new NetView(mbr);
    // the digest should be set in an outgoing join response
    JoinResponseMessage joinResponse = new JoinResponseMessage(mbr, view, 0);
    messenger.filterOutgoingMessage(joinResponse);
    assertNotNull(joinResponse.getMessengerData());
    // save the view digest for later
    byte[] data = joinResponse.getMessengerData();
    // the digest should be used and the message bytes nulled out in an incoming join response
    messenger.filterIncomingMessage(joinResponse);
    assertNull(joinResponse.getMessengerData());
    // the digest shouldn't be set in an outgoing rejection message
    joinResponse = new JoinResponseMessage("you can't join my distributed system.  nyah nyah nyah!", 0);
    messenger.filterOutgoingMessage(joinResponse);
    assertNull(joinResponse.getMessengerData());
    // the digest shouldn't be installed from an incoming rejection message
    joinResponse.setMessengerData(data);
    messenger.filterIncomingMessage(joinResponse);
    assertNotNull(joinResponse.getMessengerData());
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) NetView(org.apache.geode.distributed.internal.membership.NetView) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with JoinResponseMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage in project geode by apache.

the class GMSJoinLeaveJUnitTest method testCoordinatorFindRequestFailure.

@Test
public void testCoordinatorFindRequestFailure() throws Exception {
    try {
        initMocks(false);
        HashSet<InternalDistributedMember> registrants = new HashSet<>();
        registrants.add(mockMembers[0]);
        FindCoordinatorResponse fcr = new FindCoordinatorResponse(mockMembers[0], mockMembers[0], false, null, registrants, false, true, null);
        NetView view = createView();
        JoinResponseMessage jrm = new JoinResponseMessage(mockMembers[0], view, 0);
        gmsJoinLeave.setJoinResponseMessage(jrm);
        TcpClientWrapper tcpClientWrapper = mock(TcpClientWrapper.class);
        gmsJoinLeave.setTcpClientWrapper(tcpClientWrapper);
        FindCoordinatorRequest fcreq = new FindCoordinatorRequest(gmsJoinLeaveMemberId, new HashSet<>(), -1, null, 0, "");
        int connectTimeout = (int) services.getConfig().getMemberTimeout() * 2;
        // passing wrong port here, so ot will fail
        when(tcpClientWrapper.sendCoordinatorFindRequest(new InetSocketAddress("localhost", 12346), fcreq, connectTimeout)).thenReturn(fcr);
        assertFalse("Should not be able to join ", gmsJoinLeave.join());
    } finally {
    }
}
Also used : TcpClientWrapper(org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave.TcpClientWrapper) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) FindCoordinatorResponse(org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorResponse) FindCoordinatorRequest(org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorRequest) InetSocketAddress(java.net.InetSocketAddress) NetView(org.apache.geode.distributed.internal.membership.NetView) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) HashSet(java.util.HashSet) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with JoinResponseMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage in project geode by apache.

the class GMSJoinLeaveJUnitTest method testProcessJoinResponseIsRecorded.

// This test does not test the actual join process but rather that the join response gets loggedß
@Test
public void testProcessJoinResponseIsRecorded() throws IOException {
    initMocks();
    when(services.getAuthenticator()).thenReturn(authenticator);
    when(authenticator.authenticate(mockMembers[0], null)).thenThrow(new AuthenticationFailedException("we want to fail auth here"));
    when(services.getMessenger()).thenReturn(messenger);
    JoinResponseMessage[] joinResponse = gmsJoinLeave.getJoinResponseMessage();
    JoinResponseMessage jrm = new JoinResponseMessage(mockMembers[0], new byte[9], 233);
    gmsJoinLeave.processMessage(jrm);
    // this should NOT logs, this is just to inform member succesful joining
    Assert.assertEquals(null, joinResponse[0]);
    jrm = new JoinResponseMessage("rejected...", 0);
    gmsJoinLeave.processMessage(jrm);
    // this should log..
    Assert.assertEquals(jrm, joinResponse[0]);
    gmsJoinLeave.setJoinResponseMessage(null);
    jrm = new JoinResponseMessage(mockMembers[0], new NetView(), 0);
    gmsJoinLeave.processMessage(jrm);
    // this should log..
    Assert.assertEquals(jrm, joinResponse[0]);
}
Also used : AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) NetView(org.apache.geode.distributed.internal.membership.NetView) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 5 with JoinResponseMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage in project geode by apache.

the class GMSJoinLeave method waitForJoinResponse.

private JoinResponseMessage waitForJoinResponse() throws InterruptedException {
    JoinResponseMessage response;
    synchronized (joinResponse) {
        if (joinResponse[0] == null && !isJoined) {
            // Note that if we give up waiting but a response is on
            // the way we will get the new view and join that way.
            // See installView()
            long timeout = Math.max(services.getConfig().getMemberTimeout(), services.getConfig().getJoinTimeout() / 5);
            joinResponse.wait(timeout);
        }
        response = joinResponse[0];
        if (response != null && response.getCurrentView() != null && !isJoined) {
            // reset joinResponse[0]
            joinResponse[0] = null;
            // we got view here that means either we have to wait for
            NetView v = response.getCurrentView();
            InternalDistributedMember coord = v.getCoordinator();
            if (searchState.alreadyTried.contains(coord)) {
                searchState.view = response.getCurrentView();
                // we already sent join request to it..so lets wait some more time here
                // assuming we got this response immediately, so wait for same timeout here..
                long timeout = Math.max(services.getConfig().getMemberTimeout(), services.getConfig().getJoinTimeout() / 5);
                joinResponse.wait(timeout);
                response = joinResponse[0];
            } else {
                // try on this coordinator
                searchState.view = response.getCurrentView();
                response = null;
            }
            searchState.view = v;
        }
        if (isJoined) {
            return null;
        }
    }
    return response;
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) NetView(org.apache.geode.distributed.internal.membership.NetView) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage)

Aggregations

JoinResponseMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage)11 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)6 NetView (org.apache.geode.distributed.internal.membership.NetView)6 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)5 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)5 Test (org.junit.Test)5 SystemConnectException (org.apache.geode.SystemConnectException)4 IOException (java.io.IOException)3 GemFireConfigException (org.apache.geode.GemFireConfigException)3 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 InetSocketAddress (java.net.InetSocketAddress)2 UnknownHostException (java.net.UnknownHostException)2 HashSet (java.util.HashSet)2 Properties (java.util.Properties)2 ForcedDisconnectException (org.apache.geode.ForcedDisconnectException)2 GemFireIOException (org.apache.geode.GemFireIOException)2 FindCoordinatorRequest (org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorRequest)2