Search in sources :

Example 21 with InternalDistributedMember

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

the class GMSMembershipManagerJUnitTest method testDirectChannelSendFailureDueToForcedDisconnect.

@Test
public void testDirectChannelSendFailureDueToForcedDisconnect() throws Exception {
    setUpDirectChannelMock();
    HighPriorityAckedMessage m = new HighPriorityAckedMessage();
    InternalDistributedMember[] recipients = new InternalDistributedMember[] { mockMembers[2], mockMembers[3] };
    m.setRecipients(Arrays.asList(recipients));
    Set<InternalDistributedMember> failures = manager.directChannelSend(recipients, m, null);
    manager.setShutdown();
    ConnectExceptions exception = new ConnectExceptions();
    exception.addFailure(recipients[0], new Exception("testing"));
    when(dc.send(any(GMSMembershipManager.class), any(mockMembers.getClass()), any(DistributionMessage.class), anyInt(), anyInt())).thenThrow(exception);
    Assertions.assertThatThrownBy(() -> {
        manager.directChannelSend(recipients, m, null);
    }).isInstanceOf(DistributedSystemDisconnectedException.class);
}
Also used : HighPriorityAckedMessage(org.apache.geode.distributed.internal.HighPriorityAckedMessage) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ConnectExceptions(org.apache.geode.internal.tcp.ConnectExceptions) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 22 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember 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 23 with InternalDistributedMember

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

the class JGroupsMessengerJUnitTest method testSendUnreliably.

@Test
public void testSendUnreliably() throws Exception {
    for (int i = 0; i < 2; i++) {
        boolean enableMcast = (i == 1);
        initMocks(enableMcast);
        InternalDistributedMember mbr = createAddress(8888);
        DistributedCacheOperation.CacheOperationMessage msg = mock(DistributedCacheOperation.CacheOperationMessage.class);
        when(msg.getRecipients()).thenReturn(new InternalDistributedMember[] { mbr });
        when(msg.getMulticast()).thenReturn(enableMcast);
        if (!enableMcast) {
            // for non-mcast we send a message with a reply-processor
            when(msg.getProcessorId()).thenReturn(1234);
        } else {
            // for mcast we send a direct-ack message and expect the messenger
            // to register it
            stub(msg.isDirectAck()).toReturn(true);
        }
        when(msg.getDSFID()).thenReturn((int) DataSerializableFixedID.PUT_ALL_MESSAGE);
        interceptor.collectMessages = true;
        try {
            messenger.sendUnreliably(msg);
        } catch (GemFireIOException e) {
            fail("expected success");
        }
        if (enableMcast) {
            verify(msg, atLeastOnce()).registerProcessor();
        }
        verify(msg).toData(isA(DataOutput.class));
        assertTrue("expected 1 message but found " + interceptor.collectedMessages, interceptor.collectedMessages.size() == 1);
        assertTrue(interceptor.collectedMessages.get(0).isFlagSet(Message.Flag.NO_RELIABILITY));
    }
}
Also used : DataOutput(java.io.DataOutput) DistributedCacheOperation(org.apache.geode.internal.cache.DistributedCacheOperation) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) GemFireIOException(org.apache.geode.GemFireIOException) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 24 with InternalDistributedMember

use of org.apache.geode.distributed.internal.membership.InternalDistributedMember 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 25 with InternalDistributedMember

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

the class JGroupsMessengerJUnitTest method createAddress.

/**
   * creates an InternalDistributedMember address that can be used with the doctored JGroups
   * channel. This includes a logical (UUID) address and a physical (IpAddress) address.
   * 
   * @param port the UDP port to use for the new address
   */
private InternalDistributedMember createAddress(int port) {
    GMSMember gms = new GMSMember("localhost", port);
    gms.setUUID(UUID.randomUUID());
    gms.setVmKind(DistributionManager.NORMAL_DM_TYPE);
    gms.setVersionOrdinal(Version.CURRENT_ORDINAL);
    return new InternalDistributedMember(gms);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember)

Aggregations

InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)516 Test (org.junit.Test)162 HashSet (java.util.HashSet)124 Set (java.util.Set)77 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)63 NetView (org.apache.geode.distributed.internal.membership.NetView)60 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)56 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)55 ArrayList (java.util.ArrayList)54 DistributedMember (org.apache.geode.distributed.DistributedMember)49 UnitTest (org.apache.geode.test.junit.categories.UnitTest)49 HashMap (java.util.HashMap)46 IOException (java.io.IOException)36 Iterator (java.util.Iterator)34 PartitionedRegionLoadModel (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel)34 CompositeDirector (org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector)33 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)32 Map (java.util.Map)29 CancelException (org.apache.geode.CancelException)29 DM (org.apache.geode.distributed.internal.DM)29