Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 0F704200B8B for ; Tue, 30 Aug 2016 04:57:57 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 0DD03160AC8; Tue, 30 Aug 2016 02:57:57 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 89D1C160ACB for ; Tue, 30 Aug 2016 04:57:55 +0200 (CEST) Received: (qmail 7281 invoked by uid 500); 30 Aug 2016 02:57:54 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 7272 invoked by uid 99); 30 Aug 2016 02:57:54 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Aug 2016 02:57:54 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 51826C094E for ; Tue, 30 Aug 2016 02:57:54 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -3.739 X-Spam-Level: X-Spam-Status: No, score=-3.739 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.519] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id QUe3AjU3qLmO for ; Tue, 30 Aug 2016 02:57:51 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 4822E60D24 for ; Tue, 30 Aug 2016 02:57:47 +0000 (UTC) Received: (qmail 5792 invoked by uid 99); 30 Aug 2016 02:57:46 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Aug 2016 02:57:46 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 30074E69B0; Tue, 30 Aug 2016 02:57:46 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: udo@apache.org To: commits@geode.incubator.apache.org Date: Tue, 30 Aug 2016 02:58:01 -0000 Message-Id: In-Reply-To: <53ee65c8432a423ab4220ab81c3028fd@git.apache.org> References: <53ee65c8432a423ab4220ab81c3028fd@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [17/27] incubator-geode git commit: GEODE-1372 added unit test and some more fixes. archived-at: Tue, 30 Aug 2016 02:57:57 -0000 http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5247cce/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorDUnitTest.java index 954846f..2a35ba7 100755 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorDUnitTest.java @@ -132,6 +132,11 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { system = null; } } + + //for child classes + protected void addDSProps(Properties p) { + + } //////// Test Methods @@ -163,6 +168,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { properties.put(SECURITY_PEER_AUTHENTICATOR, "com.gemstone.gemfire.distributed.MyAuthenticator.create"); properties.put(ENABLE_CLUSTER_CONFIGURATION, "false"); properties.put(USE_CLUSTER_CONFIGURATION, "false"); + addDSProps(properties); system = (InternalDistributedSystem) DistributedSystem.connect(properties); InternalDistributedMember mbr = system.getDistributedMember(); assertEquals("expected the VM to have NORMAL vmKind", @@ -299,6 +305,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { properties.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel()); properties.put(ENABLE_CLUSTER_CONFIGURATION, "false"); + addDSProps(properties); SerializableCallable startLocator1 = new SerializableCallable("start locator1") { @Override public Object call() throws Exception { @@ -404,6 +411,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "true"); properties.put(DISABLE_AUTO_RECONNECT, "true"); + addDSProps(properties); File logFile = new File(""); if (logFile.exists()) { logFile.delete(); @@ -525,6 +533,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { // properties.put("log-level", "fine"); properties.put(ENABLE_CLUSTER_CONFIGURATION, "false"); + addDSProps(properties); try { final String uname = getUniqueName(); File logFile = new File(""); @@ -657,6 +666,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { properties.put(MEMBER_TIMEOUT, "2000"); properties.put(ENABLE_CLUSTER_CONFIGURATION, "false"); + addDSProps(properties); SerializableRunnable stopLocator = getStopLocatorRunnable(); try { @@ -804,6 +814,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { properties.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel()); properties.put(ENABLE_CLUSTER_CONFIGURATION, "false"); + addDSProps(properties); SerializableRunnable stopLocator = getStopLocatorRunnable(); try { @@ -941,6 +952,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { properties.put(MEMBER_TIMEOUT, "2000"); properties.put(ENABLE_CLUSTER_CONFIGURATION, "false"); + addDSProps(properties); SerializableRunnable disconnect = new SerializableRunnable("Disconnect from " + locators) { public void run() { @@ -1054,6 +1066,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { props.setProperty(MCAST_PORT, "0"); props.setProperty(LOCATORS, locators); + addDSProps(props); final String expected = "java.net.ConnectException"; final String addExpected = "" + expected + ""; @@ -1126,6 +1139,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { locProps.setProperty(MEMBER_TIMEOUT, "1000"); locProps.put(ENABLE_CLUSTER_CONFIGURATION, "false"); + addDSProps(locProps); Locator.startLocatorAndDS(port, logFile, locProps); } catch (IOException ex) { com.gemstone.gemfire.test.dunit.Assert.fail("While starting locator on port " + port, ex); @@ -1142,6 +1156,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { props.setProperty(MCAST_PORT, "0"); props.setProperty(LOCATORS, locators); props.setProperty(MEMBER_TIMEOUT, "1000"); + addDSProps(props); DistributedSystem.connect(props); } }; @@ -1153,6 +1168,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { props.setProperty(LOCATORS, locators); props.setProperty(MEMBER_TIMEOUT, "1000"); + addDSProps(props); system = (InternalDistributedSystem) DistributedSystem.connect(props); final DistributedMember coord = MembershipManagerHelper.getCoordinator(system); @@ -1223,6 +1239,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { props.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "true"); props.put(ENABLE_CLUSTER_CONFIGURATION, "false"); + addDSProps(props); SerializableRunnable connect = new SerializableRunnable("Connect to " + locators) { public void run() { @@ -1357,7 +1374,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { dsProps.setProperty(LOCATORS, locators); dsProps.setProperty(MCAST_PORT, "0"); dsProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false"); - + addDSProps(dsProps); vm0.invoke(new SerializableRunnable("Start locator on " + port1) { public void run() { File logFile = new File(""); @@ -1391,6 +1408,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { Properties props = new Properties(); props.setProperty(MCAST_PORT, "0"); props.setProperty(LOCATORS, locators); + addDSProps(props); DistributedSystem.connect(props); } }; @@ -1401,6 +1419,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { props.setProperty(MCAST_PORT, "0"); props.setProperty(LOCATORS, locators); + addDSProps(props); system = (InternalDistributedSystem) DistributedSystem.connect(props); WaitCriterion ev = new WaitCriterion() { @@ -1478,6 +1497,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { dsProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false"); dsProps.setProperty(MCAST_PORT, "0"); + addDSProps(dsProps); startLocatorSync(vm0, new Object[] { port1, dsProps }); startLocatorSync(vm1, new Object[] { port2, dsProps }); startLocatorSync(vm2, new Object[] { port3, dsProps }); @@ -1690,6 +1710,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { props.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "true"); props.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false"); + addDSProps(props); Locator.startLocatorAndDS(port1, logFile, null, props); } catch (IOException ex) { com.gemstone.gemfire.test.dunit.Assert.fail("While starting locator on port " + port1, ex); @@ -1707,6 +1728,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { props.setProperty(MCAST_TTL, "0"); props.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "true"); props.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false"); + addDSProps(props); Locator.startLocatorAndDS(port2, logFile, null, props); } catch (IOException ex) { com.gemstone.gemfire.test.dunit.Assert.fail("While starting locator on port " + port2, ex); @@ -1723,6 +1745,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { props.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel()); props.setProperty(MCAST_TTL, "0"); props.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "true"); + addDSProps(props); DistributedSystem.connect(props); } }; @@ -1737,6 +1760,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { props.setProperty(MCAST_TTL, "0"); props.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "true"); + addDSProps(props); system = (InternalDistributedSystem) DistributedSystem.connect(props); WaitCriterion ev = new WaitCriterion() { public boolean done() { @@ -1789,6 +1813,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { props.setProperty(MCAST_PORT, "0"); props.setProperty(LOCATORS, locators); props.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false"); + addDSProps(props); system = (InternalDistributedSystem) DistributedSystem.connect(props); system.disconnect(); } finally { @@ -1835,6 +1860,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { props.setProperty(MCAST_PORT, "0"); props.setProperty(LOCATORS, locators); props.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel()); + addDSProps(props); DistributedSystem.connect(props); } }; @@ -1870,6 +1896,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { p.setProperty(LOCATORS, Host.getHost(0).getHostName() + "[" + port1 + "]"); p.setProperty(MCAST_PORT, "0"); p.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false"); + addDSProps(p); if (stateFile.exists()) { stateFile.delete(); } @@ -1955,6 +1982,7 @@ public class LocatorDUnitTest extends JUnit4DistributedTestCase { Properties locProps = new Properties(); locProps.put(MCAST_PORT, "0"); locProps.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel()); + addDSProps(locProps); Locator.startLocatorAndDS(port, logFile, locProps); } catch (IOException ex) { com.gemstone.gemfire.test.dunit.Assert.fail("While starting locator on port " + port, ex); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5247cce/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorUDPSecurityDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorUDPSecurityDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorUDPSecurityDUnitTest.java new file mode 100755 index 0000000..37f14c3 --- /dev/null +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorUDPSecurityDUnitTest.java @@ -0,0 +1,28 @@ +package com.gemstone.gemfire.distributed; + +import java.util.Properties; + +import org.junit.Test; + +import com.gemstone.gemfire.distributed.internal.DistributionConfig; + +public class LocatorUDPSecurityDUnitTest extends LocatorDUnitTest{ + + public LocatorUDPSecurityDUnitTest(String name) { + super(name); + } + + @Test + public void testLoop() throws Exception { + for(int i=0; i < 2; i++) { + testMultipleLocatorsRestartingAtSameTime(); + tearDown(); + setUp(); + } + } + + @Override + protected void addDSProps(Properties p) { + p.setProperty(DistributionConfig.SECURITY_CLIENT_DHALGO_NAME, "AES:128"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5247cce/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeaveJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeaveJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeaveJUnitTest.java index ec639aa..d652915 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeaveJUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeaveJUnitTest.java @@ -176,7 +176,7 @@ public class GMSJoinLeaveJUnitTest { // simulate a response being received InternalDistributedMember sender = mockMembers[2]; - FindCoordinatorResponse resp = new FindCoordinatorResponse(coordinator, sender); + FindCoordinatorResponse resp = new FindCoordinatorResponse(coordinator, sender, null, 0); gmsJoinLeave.processMessage(resp); // tell GMSJoinLeave that a unit test is running so it won't clear the // responses collection @@ -193,7 +193,7 @@ public class GMSJoinLeaveJUnitTest { public void testProcessJoinMessageRejectOldMemberVersion() throws IOException { initMocks(); - gmsJoinLeave.processMessage(new JoinRequestMessage(mockOldMember, mockOldMember, null, -1)); + gmsJoinLeave.processMessage(new JoinRequestMessage(mockOldMember, mockOldMember, null, -1, 0)); assertTrue("JoinRequest should not have been added to view request", gmsJoinLeave.getViewRequests().size() == 0); verify(messenger).send(any(JoinResponseMessage.class)); } @@ -216,7 +216,7 @@ public class GMSJoinLeaveJUnitTest { when(authenticator.authenticate(mockMembers[0], credentials)).thenThrow(new AuthenticationFailedException("we want to fail auth here")); when(services.getMessenger()).thenReturn(messenger); - gmsJoinLeave.processMessage(new JoinRequestMessage(mockMembers[0], mockMembers[0], credentials, -1)); + gmsJoinLeave.processMessage(new JoinRequestMessage(mockMembers[0], mockMembers[0], credentials, -1, 0)); assertTrue("JoinRequest should not have been added to view request", gmsJoinLeave.getViewRequests().size() == 0); verify(messenger).send(any(JoinResponseMessage.class)); } @@ -228,7 +228,7 @@ public class GMSJoinLeaveJUnitTest { when(authenticator.authenticate(mockMembers[0], null)).thenThrow(new AuthenticationFailedException("we want to fail auth here")); when(services.getMessenger()).thenReturn(messenger); - gmsJoinLeave.processMessage(new JoinRequestMessage(mockMembers[0], mockMembers[0], null, -1)); + gmsJoinLeave.processMessage(new JoinRequestMessage(mockMembers[0], mockMembers[0], null, -1, 0)); assertTrue("JoinRequest should not have been added to view request", gmsJoinLeave.getViewRequests().size() == 0); verify(messenger).send(any(JoinResponseMessage.class)); } @@ -243,9 +243,22 @@ public class GMSJoinLeaveJUnitTest { JoinResponseMessage[] joinResponse = gmsJoinLeave.getJoinResponseMessage(); - JoinResponseMessage jrm = new JoinResponseMessage(); + 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]); } /** @@ -461,10 +474,10 @@ public class GMSJoinLeaveJUnitTest { prepareAndInstallView(gmsJoinLeaveMemberId, createMemberList(gmsJoinLeaveMemberId,mockMembers[0])); gmsJoinLeave.getView().add(mockMembers[1]); GMSJoinLeaveTestHelper.becomeCoordinatorForTest(gmsJoinLeave); - JoinRequestMessage msg = new JoinRequestMessage(gmsJoinLeaveMemberId, mockMembers[2], null, -1); + JoinRequestMessage msg = new JoinRequestMessage(gmsJoinLeaveMemberId, mockMembers[2], null, -1, 0); msg.setSender(mockMembers[2]); gmsJoinLeave.processMessage(msg); - msg = new JoinRequestMessage(gmsJoinLeaveMemberId, mockMembers[2], null, -1); + msg = new JoinRequestMessage(gmsJoinLeaveMemberId, mockMembers[2], null, -1, 0); msg.setSender(mockMembers[2]); gmsJoinLeave.processMessage(msg); @@ -856,7 +869,7 @@ public class GMSJoinLeaveJUnitTest { initMocks(false); System.setProperty(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY, "true"); gmsJoinLeave.join(); - gmsJoinLeave.processMessage(new JoinRequestMessage(mockMembers[0], mockMembers[0], credentials, -1)); + gmsJoinLeave.processMessage(new JoinRequestMessage(mockMembers[0], mockMembers[0], credentials, -1, 0)); int viewRequests = gmsJoinLeave.getViewRequests().size(); assertTrue( "There should be 1 viewRequest but found " + viewRequests, viewRequests == 1); @@ -1056,13 +1069,13 @@ public class GMSJoinLeaveJUnitTest { initMocks(false); HashSet registrants = new HashSet<>(); registrants.add(mockMembers[0]); - FindCoordinatorResponse fcr = new FindCoordinatorResponse(mockMembers[0], mockMembers[0], false, null, registrants, false, true); + FindCoordinatorResponse fcr = new FindCoordinatorResponse(mockMembers[0], mockMembers[0], false, null, registrants, false, true, null); NetView view = createView(); - JoinResponseMessage jrm = new JoinResponseMessage(mockMembers[0], view); + JoinResponseMessage jrm = new JoinResponseMessage(mockMembers[0], view, 0); TcpClientWrapper tcpClientWrapper = mock(TcpClientWrapper.class); gmsJoinLeave.setTcpClientWrapper(tcpClientWrapper); - FindCoordinatorRequest fcreq = new FindCoordinatorRequest(gmsJoinLeaveMemberId, new HashSet<>(), -1); + FindCoordinatorRequest fcreq = new FindCoordinatorRequest(gmsJoinLeaveMemberId, new HashSet<>(), -1, null, 0); int connectTimeout = (int)services.getConfig().getMemberTimeout() * 2; when(tcpClientWrapper.sendCoordinatorFindRequest(new InetSocketAddress("localhost", 12345), fcreq, connectTimeout)).thenReturn(fcr); callAsnyc(()->{gmsJoinLeave.installView(view);}); @@ -1083,14 +1096,14 @@ public class GMSJoinLeaveJUnitTest { initMocks(false); HashSet registrants = new HashSet<>(); registrants.add(mockMembers[0]); - FindCoordinatorResponse fcr = new FindCoordinatorResponse(mockMembers[0], mockMembers[0], false, null, registrants, false, true); + FindCoordinatorResponse fcr = new FindCoordinatorResponse(mockMembers[0], mockMembers[0], false, null, registrants, false, true, null); NetView view = createView(); - JoinResponseMessage jrm = new JoinResponseMessage(mockMembers[0], view); + 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); + 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); @@ -1208,7 +1221,7 @@ public class GMSJoinLeaveJUnitTest { } private void processJoinMessage(InternalDistributedMember coordinator, InternalDistributedMember newMember, int port) { - JoinRequestMessage reqMsg = new JoinRequestMessage(coordinator, newMember, null, port); + JoinRequestMessage reqMsg = new JoinRequestMessage(coordinator, newMember, null, port, 0); gmsJoinLeave.processMessage(reqMsg); } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5247cce/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/GMSEncryptJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/GMSEncryptJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/GMSEncryptJUnitTest.java index b9e2202..e8f99d9 100755 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/GMSEncryptJUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/GMSEncryptJUnitTest.java @@ -159,7 +159,7 @@ public class GMSEncryptJUnitTest { initMocks(); GMSEncrypt gmsEncrypt1 = new GMSEncrypt(services, mockMembers[1]); // this will be the sender - gmsEncrypt1.addClusterKey(); + gmsEncrypt1.initClusterSecretKey(); // establish the public keys for the sender and receiver netView.setPublicKey(mockMembers[1], gmsEncrypt1.getPublicKeyBytes()); @@ -183,7 +183,7 @@ public class GMSEncryptJUnitTest { initMocks(); GMSEncrypt gmsEncrypt1 = new GMSEncrypt(services, mockMembers[1]); // this will be the sender - gmsEncrypt1.addClusterKey(); + gmsEncrypt1.initClusterSecretKey(); GMSEncrypt gmsEncrypt2 = new GMSEncrypt(services, mockMembers[2]); // this will be the sender // establish the public keys for the sender and receiver @@ -192,7 +192,7 @@ public class GMSEncryptJUnitTest { gmsEncrypt1.installView(netView, mockMembers[1]); - byte[] secretBytes = gmsEncrypt1.getSecretBytes(); + byte[] secretBytes = gmsEncrypt1.getClusterSecretKey(); gmsEncrypt2.addClusterKey(secretBytes); gmsEncrypt2.installView(netView, mockMembers[1]); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5247cce/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java index e79e8a7..5c672e3 100755 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java @@ -27,9 +27,11 @@ import java.io.DataOutput; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Set; import org.apache.commons.lang.SerializationException; import org.jgroups.Address; @@ -49,6 +51,7 @@ import com.gemstone.gemfire.ForcedDisconnectException; import com.gemstone.gemfire.GemFireIOException; import com.gemstone.gemfire.distributed.DistributedSystemDisconnectedException; import com.gemstone.gemfire.distributed.internal.DM; +import com.gemstone.gemfire.distributed.internal.DistributionConfig; import com.gemstone.gemfire.distributed.internal.DistributionConfigImpl; import com.gemstone.gemfire.distributed.internal.DistributionManager; import com.gemstone.gemfire.distributed.internal.DistributionMessage; @@ -65,6 +68,9 @@ import com.gemstone.gemfire.distributed.internal.membership.gms.interfaces.Healt import com.gemstone.gemfire.distributed.internal.membership.gms.interfaces.JoinLeave; import com.gemstone.gemfire.distributed.internal.membership.gms.interfaces.Manager; import com.gemstone.gemfire.distributed.internal.membership.gms.interfaces.MessageHandler; +import com.gemstone.gemfire.distributed.internal.membership.gms.locator.FindCoordinatorRequest; +import com.gemstone.gemfire.distributed.internal.membership.gms.locator.FindCoordinatorResponse; +import com.gemstone.gemfire.distributed.internal.membership.gms.messages.InstallViewMessage; import com.gemstone.gemfire.distributed.internal.membership.gms.messages.JoinRequestMessage; import com.gemstone.gemfire.distributed.internal.membership.gms.messages.JoinResponseMessage; import com.gemstone.gemfire.distributed.internal.membership.gms.messages.LeaveRequestMessage; @@ -91,10 +97,14 @@ public class JGroupsMessengerJUnitTest { private InterceptUDP interceptor; private long statsId = 123; + private void initMocks(boolean enableMcast) throws Exception { + initMocks(enableMcast, new Properties()); + } + /** * Create stub and mock objects */ - private void initMocks(boolean enableMcast) throws Exception { + private void initMocks(boolean enableMcast, Properties addProp) throws Exception { if (messenger != null) { messenger.stop(); messenger = null; @@ -107,6 +117,7 @@ public class JGroupsMessengerJUnitTest { nonDefault.put(LOG_LEVEL, "fine"); nonDefault.put(LOCATORS, "localhost[10344]"); nonDefault.put(ACK_WAIT_THRESHOLD, "1"); + nonDefault.putAll(addProp); DistributionConfigImpl config = new DistributionConfigImpl(nonDefault); RemoteTransportConfig tconfig = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE); @@ -129,6 +140,7 @@ public class JGroupsMessengerJUnitTest { when(services.getHealthMonitor()).thenReturn(healthMonitor); when(services.getManager()).thenReturn(manager); when(services.getJoinLeave()).thenReturn(joinLeave); + DM dm = mock(DM.class); InternalDistributedSystem system = InternalDistributedSystem.newInstanceForTesting(dm, nonDefault); when(services.getStatistics()).thenReturn(new DistributionStats(system, statsId)); @@ -136,6 +148,9 @@ public class JGroupsMessengerJUnitTest { messenger = new JGroupsMessenger(); messenger.init(services); + //if I do this earlier then test this return messenger as null + when(services.getMessenger()).thenReturn(messenger); + String jgroupsConfig = messenger.getJGroupsStackConfig(); int startIdx = jgroupsConfig.indexOf("', startIdx+4) + 1; @@ -424,15 +439,15 @@ public class JGroupsMessengerJUnitTest { when(joinLeave.getView()).thenReturn(v); InternalDistributedMember sender = createAddress(8888); - JoinRequestMessage msg = new JoinRequestMessage(messenger.localAddress, sender, null, -1); + JoinRequestMessage msg = new JoinRequestMessage(messenger.localAddress, sender, null, -1, 0); - Message jmsg = messenger.createJGMessage(msg, messenger.jgAddress, null, Version.CURRENT_ORDINAL); + Message jmsg = messenger.createJGMessage(msg, messenger.jgAddress, Version.CURRENT_ORDINAL); interceptor.up(new Event(Event.MSG, jmsg)); verify(mh, times(1)).processMessage(any(JoinRequestMessage.class)); LeaveRequestMessage lmsg = new LeaveRequestMessage(messenger.localAddress, sender, "testing"); - jmsg = messenger.createJGMessage(lmsg, messenger.jgAddress, null, Version.CURRENT_ORDINAL); + jmsg = messenger.createJGMessage(lmsg, messenger.jgAddress, Version.CURRENT_ORDINAL); interceptor.up(new Event(Event.MSG, jmsg)); verify(manager).processMessage(any(LeaveRequestMessage.class)); @@ -464,7 +479,7 @@ public class JGroupsMessengerJUnitTest { NetView v = new NetView(sender); when(joinLeave.getView()).thenReturn(v); messenger.installView(v); - JoinRequestMessage msg = new JoinRequestMessage(messenger.localAddress, sender, null, -1); + JoinRequestMessage msg = new JoinRequestMessage(messenger.localAddress, sender, null, -1, 0); if (mcastMsg) { msg.setMulticast(true); } @@ -476,7 +491,7 @@ public class JGroupsMessengerJUnitTest { sentMessages == 1); // send a big message and expect fragmentation - msg = new JoinRequestMessage(messenger.localAddress, sender, new byte[(int)(services.getConfig().getDistributionConfig().getUdpFragmentSize()*(1.5))], -1); + msg = new JoinRequestMessage(messenger.localAddress, sender, new byte[(int)(services.getConfig().getDistributionConfig().getUdpFragmentSize()*(1.5))], -1, 0); // configure an incoming message handler for JoinRequestMessage final DistributionMessage[] messageReceived = new DistributionMessage[1]; @@ -692,7 +707,7 @@ public class JGroupsMessengerJUnitTest { NetView view = new NetView(mbr); // the digest should be set in an outgoing join response - JoinResponseMessage joinResponse = new JoinResponseMessage(mbr, view); + JoinResponseMessage joinResponse = new JoinResponseMessage(mbr, view, 0); messenger.filterOutgoingMessage(joinResponse); assertNotNull(joinResponse.getMessengerData()); @@ -704,7 +719,7 @@ public class JGroupsMessengerJUnitTest { 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!"); + joinResponse = new JoinResponseMessage("you can't join my distributed system. nyah nyah nyah!", 0); messenger.filterOutgoingMessage(joinResponse); assertNull(joinResponse.getMessengerData()); @@ -800,7 +815,7 @@ public class JGroupsMessengerJUnitTest { dmsg.setRecipients(recipients); // a message is ignored during manager shutdown - msg = messenger.createJGMessage(dmsg, new JGAddress(other), null, Version.CURRENT_ORDINAL); + 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)); @@ -891,6 +906,174 @@ public class JGroupsMessengerJUnitTest { assertFalse(AvailablePort.isPortAvailable(services.getConfig().getDistributionConfig().getMcastPort(), AvailablePort.MULTICAST)); } + private NetView createView(InternalDistributedMember otherMbr) { + InternalDistributedMember sender = messenger.getMemberID(); + List mbrs = new ArrayList<>(); + mbrs.add(sender); + mbrs.add(otherMbr); + NetView v = new NetView(sender, 1, mbrs); + return v; + } + + @Test + public void testEncryptedFindCoordinatorRequest() throws Exception{ + InternalDistributedMember otherMbr = new InternalDistributedMember("localhost", 8888); + + Properties p = new Properties(); + p.put(DistributionConfig.SECURITY_CLIENT_DHALGO_NAME, "AES:128"); + initMocks(false, p); + + NetView v = createView(otherMbr); + + GMSEncrypt otherMbrEncrptor = new GMSEncrypt(services); + + messenger.setPublicKey(otherMbrEncrptor.getPublicKeyBytes(), otherMbr); + messenger.initClusterKey(); + + FindCoordinatorRequest gfmsg = new FindCoordinatorRequest(messenger.getMemberID(), new ArrayList(2), 1, messenger.getPublickey(messenger.getMemberID()), 1); + Set recipients = new HashSet<>(); + recipients.add(otherMbr); + gfmsg.setRecipients(recipients); + + 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); + } + + @Test + public void testEncryptedFindCoordinatorResponse() throws Exception{ + InternalDistributedMember otherMbr = new InternalDistributedMember("localhost", 8888); + + Properties p = new Properties(); + p.put(DistributionConfig.SECURITY_CLIENT_DHALGO_NAME, "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(); + + FindCoordinatorResponse gfmsg = new FindCoordinatorResponse(messenger.getMemberID(), messenger.getMemberID(), messenger.getClusterSecretKey(), 1); + Set recipients = new HashSet<>(); + recipients.add(otherMbr); + gfmsg.setRecipients(recipients); + + 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 distributionMessage = messenger.readEncryptedMessage(dis, version, otherMbrEncrptor); + + assertEquals(gfmsg, distributionMessage); + } + + @Test + public void testEncryptedJoinRequest() throws Exception{ + InternalDistributedMember otherMbr = new InternalDistributedMember("localhost", 8888); + + Properties p = new Properties(); + p.put(DistributionConfig.SECURITY_CLIENT_DHALGO_NAME, "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); + } + + @Test + public void testEncryptedJoinResponse() throws Exception{ + InternalDistributedMember otherMbr = new InternalDistributedMember("localhost", 8888); + + Properties p = new Properties(); + p.put(DistributionConfig.SECURITY_CLIENT_DHALGO_NAME, "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); + + } + /** * creates an InternalDistributedMember address that can be used * with the doctored JGroups channel. This includes a logical