http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6df75241/gemfire-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/misc/WANConfigurationJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/misc/WANConfigurationJUnitTest.java b/gemfire-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/misc/WANConfigurationJUnitTest.java new file mode 100644 index 0000000..6566152 --- /dev/null +++ b/gemfire-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/misc/WANConfigurationJUnitTest.java @@ -0,0 +1,608 @@ +/*========================================================================= + * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * one or more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ +package com.gemstone.gemfire.internal.cache.wan.misc; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + +import org.junit.After; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import com.gemstone.gemfire.cache.AttributesFactory; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheFactory; +import com.gemstone.gemfire.cache.DataPolicy; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.RegionAttributes; +import com.gemstone.gemfire.cache.RegionFactory; +import com.gemstone.gemfire.cache.Scope; +import com.gemstone.gemfire.cache.asyncqueue.AsyncEventListener; +import com.gemstone.gemfire.cache.wan.GatewayEventFilter; +import com.gemstone.gemfire.cache.wan.GatewayReceiver; +import com.gemstone.gemfire.cache.wan.GatewayReceiverFactory; +import com.gemstone.gemfire.cache.wan.GatewaySender; +import com.gemstone.gemfire.cache.wan.GatewaySenderFactory; +import com.gemstone.gemfire.cache.wan.GatewayTransportFilter; +import com.gemstone.gemfire.cache30.MyGatewayEventFilter1; +import com.gemstone.gemfire.cache30.MyGatewayTransportFilter1; +import com.gemstone.gemfire.cache30.MyGatewayTransportFilter2; +import com.gemstone.gemfire.internal.AvailablePort; +import com.gemstone.gemfire.internal.cache.LocalRegion; +import com.gemstone.gemfire.internal.cache.wan.GatewayReceiverException; +import com.gemstone.gemfire.internal.cache.wan.GatewaySenderException; +import com.gemstone.gemfire.internal.cache.wan.InternalGatewaySenderFactory; +import com.gemstone.gemfire.internal.cache.wan.MyGatewaySenderEventListener; +import com.gemstone.gemfire.internal.i18n.LocalizedStrings; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; + +@Category(IntegrationTest.class) +public class WANConfigurationJUnitTest { + + private Cache cache; + + /** + * Test to validate that the sender can not be started without configuring + * locator + * @throws IOException + * + * @throws IOException + */ + @Test + public void test_GatewaySender_without_Locator() throws IOException { + try { + cache = new CacheFactory().set("mcast-port", "0").create(); + GatewaySenderFactory fact = cache.createGatewaySenderFactory(); + fact.setParallel(true); + GatewaySender sender1 = fact.create("NYSender", 2); + sender1.start(); + fail("Expectd IllegalStateException but not thrown"); + } + catch (Exception e) { + if ((e instanceof IllegalStateException && e + .getMessage() + .startsWith( + LocalizedStrings.AbstractGatewaySender_LOCATOR_SHOULD_BE_CONFIGURED_BEFORE_STARTING_GATEWAY_SENDER + .toLocalizedString()))) { + } + else { + fail("Expectd IllegalStateException but received :" + e); + } + } + } + + /** + * Test to validate that sender with same Id can not be added to cache. + */ + @Test + public void test_SameGatewaySenderCreatedTwice() { + cache = new CacheFactory().set("mcast-port", "0").create(); + try { + GatewaySenderFactory fact = cache.createGatewaySenderFactory(); + fact.setParallel(true); + fact.setManualStart(true); + fact.create("NYSender", 2); + fact.create("NYSender", 2); + fail("Expectd IllegalStateException but not thrown"); + } + catch (Exception e) { + if (e instanceof IllegalStateException + && e.getMessage().contains("A GatewaySender with id")) { + + } + else { + fail("Expectd IllegalStateException but received :" + e); + } + } + } + + /** + * Test to validate that same gatewaySender Id can not be added to the region attributes. + */ + @Test + public void test_SameGatewaySenderIdAddedTwice() { + try { + cache = new CacheFactory().set("mcast-port", "0").create(); + GatewaySenderFactory fact = cache.createGatewaySenderFactory(); + fact.setParallel(true); + fact.setManualStart(true); + GatewaySender sender1 = fact.create("NYSender", 2); + AttributesFactory factory = new AttributesFactory(); + factory.addGatewaySenderId(sender1.getId()); + factory.addGatewaySenderId(sender1.getId()); + fail("Expectd IllegalArgumentException but not thrown"); + } + catch (Exception e) { + if (e instanceof IllegalArgumentException + && e.getMessage().contains("is already added")) { + + } + else { + fail("Expectd IllegalStateException but received :" + e); + } + } + } + + @Test + public void test_GatewaySenderIdAndAsyncEventId() { + cache = new CacheFactory().set("mcast-port", "0").create(); + AttributesFactory factory = new AttributesFactory(); + factory.addGatewaySenderId("ln"); + factory.addGatewaySenderId("ny"); + factory.addAsyncEventQueueId("Async_LN"); + RegionAttributes attrs = factory.create(); + + Set<String> senderIds = new HashSet<String>(); + senderIds.add("ln"); + senderIds.add("ny"); + Set<String> attrsSenderIds = attrs.getGatewaySenderIds(); + assertEquals(senderIds, attrsSenderIds); + Region r = cache.createRegion("Customer", attrs); + assertEquals(senderIds, ((LocalRegion)r).getGatewaySenderIds()); + } + + /** + * Test to validate that distributed region can not have the gateway sender + * with parallel distribution policy + * + */ + public void DIABLEB_DUE_TO_BUG51491_test_GatewaySender_Parallel_DistributedRegion() { + cache = new CacheFactory().set("mcast-port", "0").create(); + GatewaySenderFactory fact = cache.createGatewaySenderFactory(); + fact.setParallel(true); + fact.setManualStart(true); + GatewaySender sender1 = fact.create("NYSender", 2); + AttributesFactory factory = new AttributesFactory(); + factory.addGatewaySenderId(sender1.getId()); + factory.setScope(Scope.DISTRIBUTED_ACK); + factory.setDataPolicy(DataPolicy.REPLICATE); + try { + RegionFactory regionFactory = cache.createRegionFactory(factory.create()); + Region region = regionFactory + .create("test_GatewaySender_Parallel_DistributedRegion"); + } + catch (Exception e) { + fail("Unexpectd Exception :" + e); + } + } + + @Test + public void test_GatewaySender_Parallel_MultipleDispatherThread() { + cache = new CacheFactory().set("mcast-port", "0").create(); + GatewaySenderFactory fact = cache.createGatewaySenderFactory(); + fact.setParallel(true); + fact.setManualStart(true); + fact.setDispatcherThreads(4); + try { + GatewaySender sender1 = fact.create("NYSender", 2); + } + catch (GatewaySenderException e) { + fail("UnExpectd Exception " + e); + } + } + + @Test + public void test_GatewaySender_Serial_ZERO_DispatherThread() { + cache = new CacheFactory().set("mcast-port", "0").create(); + GatewaySenderFactory fact = cache.createGatewaySenderFactory(); + fact.setManualStart(true); + fact.setDispatcherThreads(0); + try { + GatewaySender sender1 = fact.create("NYSender", 2); + fail("Expectd GatewaySenderException but not thrown"); + } + catch (GatewaySenderException e) { + if (e.getMessage().contains("can not be created with dispatcher threads less than 1")) { + } + else { + fail("Expectd IllegalStateException but received :" + e); + } + } + } + + /** + * Test to validate the gateway receiver attributes are correctly set + */ + @Test + public void test_ValidateGatewayReceiverAttributes() { + cache = new CacheFactory().set("mcast-port", "0").create(); + int port1 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + int port2 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + + GatewayReceiverFactory fact = cache.createGatewayReceiverFactory(); + if(port1 < port2){ + fact.setStartPort(port1); + fact.setEndPort(port2); + }else{ + fact.setStartPort(port2); + fact.setEndPort(port1); + } + + fact.setMaximumTimeBetweenPings(2000); + fact.setSocketBufferSize(200); + GatewayTransportFilter myStreamfilter1 = new MyGatewayTransportFilter1(); + GatewayTransportFilter myStreamfilter2 = new MyGatewayTransportFilter2(); + fact.addGatewayTransportFilter(myStreamfilter2); + fact.addGatewayTransportFilter(myStreamfilter1); + GatewayReceiver receiver1 = fact.create(); + + + Region region = cache.createRegionFactory().create( + "test_ValidateGatewayReceiverAttributes"); + Set<GatewayReceiver> receivers = cache.getGatewayReceivers(); + GatewayReceiver rec = receivers.iterator().next(); + assertEquals(receiver1.getHost(), rec.getHost()); + assertEquals(receiver1.getStartPort(), rec.getStartPort()); + assertEquals(receiver1.getEndPort(), rec.getEndPort()); + assertEquals(receiver1.getBindAddress(), rec.getBindAddress()); + assertEquals(receiver1.getMaximumTimeBetweenPings(), rec + .getMaximumTimeBetweenPings()); + assertEquals(receiver1.getSocketBufferSize(), rec + .getSocketBufferSize()); + assertEquals(receiver1.getGatewayTransportFilters().size(), rec + .getGatewayTransportFilters().size()); + + } + + @Test + public void test_ValidateGatewayReceiverStatus() { + cache = new CacheFactory().set("mcast-port", "0").create(); + int port1 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + int port2 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + + GatewayReceiverFactory fact = cache.createGatewayReceiverFactory(); + if(port1 < port2){ + fact.setStartPort(port1); + fact.setEndPort(port2); + }else{ + fact.setStartPort(port2); + fact.setEndPort(port1); + } + + fact.setMaximumTimeBetweenPings(2000); + fact.setSocketBufferSize(200); + GatewayTransportFilter myStreamfilter1 = new MyGatewayTransportFilter1(); + GatewayTransportFilter myStreamfilter2 = new MyGatewayTransportFilter2(); + fact.addGatewayTransportFilter(myStreamfilter2); + fact.addGatewayTransportFilter(myStreamfilter1); + GatewayReceiver receiver1 = fact.create(); + assertTrue(receiver1.isRunning()); + } + + /** + * Test to validate that serial gateway sender attributes are correctly set + * + * @throws IOException + */ + @Test + public void test_ValidateSerialGatewaySenderAttributes() { + cache = new CacheFactory().set("mcast-port", "0").create(); + GatewaySenderFactory fact = cache.createGatewaySenderFactory(); + fact.setManualStart(true); + fact.setBatchConflationEnabled(true); + fact.setBatchSize(200); + fact.setBatchTimeInterval(300); + fact.setPersistenceEnabled(false); + fact.setDiskStoreName("FORNY"); + fact.setMaximumQueueMemory(200); + fact.setAlertThreshold(1200); + GatewayEventFilter myeventfilter1 = new MyGatewayEventFilter1(); + fact.addGatewayEventFilter(myeventfilter1); + GatewayTransportFilter myStreamfilter1 = new MyGatewayTransportFilter1(); + fact.addGatewayTransportFilter(myStreamfilter1); + GatewayTransportFilter myStreamfilter2 = new MyGatewayTransportFilter2(); + fact.addGatewayTransportFilter(myStreamfilter2); + GatewaySender sender1 = fact.create("TKSender", 2); + + + AttributesFactory factory = new AttributesFactory(); + factory.addGatewaySenderId(sender1.getId()); + factory.setDataPolicy(DataPolicy.PARTITION); + Region region = cache.createRegionFactory(factory.create()).create( + "test_ValidateGatewaySenderAttributes"); + Set<GatewaySender> senders = cache.getGatewaySenders(); + assertEquals(senders.size(), 1); + GatewaySender gatewaySender = senders.iterator().next(); + assertEquals(sender1.getRemoteDSId(), gatewaySender + .getRemoteDSId()); + assertEquals(sender1.isManualStart(), gatewaySender.isManualStart()); + assertEquals(sender1.isBatchConflationEnabled(), gatewaySender + .isBatchConflationEnabled()); + assertEquals(sender1.getBatchSize(), gatewaySender.getBatchSize()); + assertEquals(sender1.getBatchTimeInterval(), gatewaySender + .getBatchTimeInterval()); + assertEquals(sender1.isPersistenceEnabled(), gatewaySender + .isPersistenceEnabled()); + assertEquals(sender1.getDiskStoreName(), gatewaySender.getDiskStoreName()); + assertEquals(sender1.getMaximumQueueMemory(), gatewaySender + .getMaximumQueueMemory()); + assertEquals(sender1.getAlertThreshold(), gatewaySender + .getAlertThreshold()); + assertEquals(sender1.getGatewayEventFilters().size(), gatewaySender + .getGatewayEventFilters().size()); + assertEquals(sender1.getGatewayTransportFilters().size(), gatewaySender + .getGatewayTransportFilters().size()); + + } + + /** + * Test to validate that parallel gateway sender attributes are correctly set + * + * @throws IOException + */ + @Test + public void test_ValidateParallelGatewaySenderAttributes() { + cache = new CacheFactory().set("mcast-port", "0").create(); + GatewaySenderFactory fact = cache.createGatewaySenderFactory(); + fact.setParallel(true); + fact.setManualStart(true); + fact.setBatchConflationEnabled(true); + fact.setBatchSize(200); + fact.setBatchTimeInterval(300); + fact.setPersistenceEnabled(false); + fact.setDiskStoreName("FORNY"); + fact.setMaximumQueueMemory(200); + fact.setAlertThreshold(1200); + GatewayEventFilter myeventfilter1 = new MyGatewayEventFilter1(); + fact.addGatewayEventFilter(myeventfilter1); + GatewayTransportFilter myStreamfilter1 = new MyGatewayTransportFilter1(); + fact.addGatewayTransportFilter(myStreamfilter1); + GatewayTransportFilter myStreamfilter2 = new MyGatewayTransportFilter2(); + fact.addGatewayTransportFilter(myStreamfilter2); + GatewaySender sender1 = fact.create("TKSender", 2); + + + AttributesFactory factory = new AttributesFactory(); + factory.addGatewaySenderId(sender1.getId()); + factory.setDataPolicy(DataPolicy.PARTITION); + Region region = cache.createRegionFactory(factory.create()).create( + "test_ValidateGatewaySenderAttributes"); + Set<GatewaySender> senders = cache.getGatewaySenders(); + assertEquals(1, senders.size()); + GatewaySender gatewaySender = senders.iterator().next(); + assertEquals(sender1.getRemoteDSId(), gatewaySender + .getRemoteDSId()); + assertEquals(sender1.isManualStart(), gatewaySender.isManualStart()); + assertEquals(sender1.isBatchConflationEnabled(), gatewaySender + .isBatchConflationEnabled()); + assertEquals(sender1.getBatchSize(), gatewaySender.getBatchSize()); + assertEquals(sender1.getBatchTimeInterval(), gatewaySender + .getBatchTimeInterval()); + assertEquals(sender1.isPersistenceEnabled(), gatewaySender + .isPersistenceEnabled()); + assertEquals(sender1.getDiskStoreName(), gatewaySender.getDiskStoreName()); + assertEquals(sender1.getMaximumQueueMemory(), gatewaySender + .getMaximumQueueMemory()); + assertEquals(sender1.getAlertThreshold(), gatewaySender + .getAlertThreshold()); + assertEquals(sender1.getGatewayEventFilters().size(), gatewaySender + .getGatewayEventFilters().size()); + assertEquals(sender1.getGatewayTransportFilters().size(), gatewaySender + .getGatewayTransportFilters().size()); + + } + + @Test + public void test_GatewaySenderWithGatewaySenderEventListener1() { + cache = new CacheFactory().set("mcast-port", "0").create(); + InternalGatewaySenderFactory fact = (InternalGatewaySenderFactory)cache.createGatewaySenderFactory(); + AsyncEventListener listener = new MyGatewaySenderEventListener(); + ((InternalGatewaySenderFactory)fact).addAsyncEventListener(listener); + try { + fact.create("ln", 2); + fail("Expected GatewaySenderException. When a sender is added , remoteDSId should not be provided."); + } catch (Exception e) { + if (e instanceof GatewaySenderException + && e.getMessage() + .contains( + "cannot define a remote site because at least AsyncEventListener is already added.")) { + + } else { + fail("Expected GatewaySenderException but received :" + e); + } + } + } + + @Test + public void test_GatewaySenderWithGatewaySenderEventListener2() { + cache = new CacheFactory().set("mcast-port", "0").create(); + GatewaySenderFactory fact = cache.createGatewaySenderFactory(); + AsyncEventListener listener = new MyGatewaySenderEventListener(); + ((InternalGatewaySenderFactory)fact).addAsyncEventListener(listener); + try { + ((InternalGatewaySenderFactory)fact).create("ln"); + } catch (Exception e) { + fail("Received Exception :" + e); + } + } + + @Test + public void test_ValidateGatwayReceiverAttributes() { + cache = new CacheFactory().set("mcast-port", "0").create(); + GatewayReceiverFactory fact = cache.createGatewayReceiverFactory(); + fact.setStartPort(50504); + fact.setMaximumTimeBetweenPings(1000); + fact.setSocketBufferSize(4000); + fact.setEndPort(70707); + fact.setManualStart(true); + GatewayTransportFilter myStreamfilter1 = new MyGatewayTransportFilter1(); + fact.addGatewayTransportFilter(myStreamfilter1); + + GatewayReceiver receiver = fact.create(); + try { + receiver.start(); + } + catch (IOException e) { + fail("The test failed with IOException"); + } + + assertEquals(50504, receiver.getStartPort()); + assertEquals(1000, receiver.getMaximumTimeBetweenPings()); + assertEquals(4000,receiver.getSocketBufferSize()); + assertEquals(70707, receiver.getEndPort()); + } + + /** + * This test takes a minimum of 120s to execute. It is known to hang on Mac OS + * X Yosemite do to changes in the the message string checked in + * GatewayRecieverImpl around line 167. Expects + * "Cannot assign requested address" but gets + * "Can't assign requested address". Timout after 150s to safeguard against + * hanging on other platforms that may differ. + * + * @see <a + * href="https://svn.gemstone.com/trac/gemfire/ticket/51536">https://svn + * .gemstone.com/trac/gemfire/ticket/51536<a> + */ + @Test(timeout = 150000) + public void test_ValidateGatwayReceiverAttributes_WrongBindAddress() { + if (System.getProperty("os.name").equals("Mac OS X")) { + fail("Failing to avoid known hang on Mac OS X."); + } + cache = new CacheFactory().set("mcast-port", "0").create(); + GatewayReceiverFactory fact = cache.createGatewayReceiverFactory(); + fact.setStartPort(50504); + fact.setMaximumTimeBetweenPings(1000); + fact.setSocketBufferSize(4000); + fact.setEndPort(70707); + fact.setManualStart(true); + fact.setBindAddress("200.112.204.10"); + GatewayTransportFilter myStreamfilter1 = new MyGatewayTransportFilter1(); + fact.addGatewayTransportFilter(myStreamfilter1); + + GatewayReceiver receiver = fact.create(); + try { + receiver.start(); + fail("Expected GAtewayReceiverException"); + } + catch (GatewayReceiverException gRE){ + assertTrue(gRE.getMessage().contains("Failed to create server socket on")); + } + catch (IOException e) { + e.printStackTrace(); + fail("The test failed with IOException"); + } + } + + @Test + public void test_ValidateGatwayReceiverDefaultStartPortAndDefaultEndPort() { + cache = new CacheFactory().set("mcast-port", "0").create(); + GatewayReceiverFactory fact = cache.createGatewayReceiverFactory(); + fact.setMaximumTimeBetweenPings(1000); + fact.setSocketBufferSize(4000); + fact.setManualStart(true); + GatewayTransportFilter myStreamfilter1 = new MyGatewayTransportFilter1(); + fact.addGatewayTransportFilter(myStreamfilter1); + + GatewayReceiver receiver = fact.create(); + try { + receiver.start(); + } + catch (IOException e) { + fail("The test failed with IOException"); + } + int port = receiver.getPort(); + System.out.println("SKSKSK The port of receiver is " + port); + if((port < 5000) || (port > 5500)) { + fail("GatewayReceiver started on out of range port"); + } + } + + @Test + public void test_ValidateGatwayReceiverDefaultStartPortAndEndPortProvided() { + cache = new CacheFactory().set("mcast-port", "0").create(); + GatewayReceiverFactory fact = cache.createGatewayReceiverFactory(); + fact.setMaximumTimeBetweenPings(1000); + fact.setSocketBufferSize(4000); + fact.setEndPort(50707); + fact.setManualStart(true); + GatewayTransportFilter myStreamfilter1 = new MyGatewayTransportFilter1(); + fact.addGatewayTransportFilter(myStreamfilter1); + + GatewayReceiver receiver = fact.create(); + try { + receiver.start(); + } + catch (IOException e) { + fail("The test failed with IOException"); + } + int port = receiver.getPort(); + if((port < GatewayReceiver.DEFAULT_START_PORT) || (port > 50707)) { + fail("GatewayReceiver started on out of range port"); + } + } + + @Test + public void test_ValidateGatwayReceiverWithManualStartFALSE() { + cache = new CacheFactory().set("mcast-port", "0").create(); + GatewayReceiverFactory fact = cache.createGatewayReceiverFactory(); + fact.setMaximumTimeBetweenPings(1000); + fact.setSocketBufferSize(4000); + fact.setStartPort(5303); + fact.setManualStart(false); + GatewayTransportFilter myStreamfilter1 = new MyGatewayTransportFilter1(); + fact.addGatewayTransportFilter(myStreamfilter1); + GatewayReceiver receiver = fact.create(); + int port = receiver.getPort(); + if ((port < 5303) || (port > GatewayReceiver.DEFAULT_END_PORT)) { + fail("GatewayReceiver started on out of range port"); + } + } + + @Test + public void test_ValidateGatwayReceiverWithStartPortAndDefaultEndPort() { + cache = new CacheFactory().set("mcast-port", "0").create(); + GatewayReceiverFactory fact = cache.createGatewayReceiverFactory(); + fact.setMaximumTimeBetweenPings(1000); + fact.setSocketBufferSize(4000); + fact.setStartPort(5303); + fact.setManualStart(true); + GatewayTransportFilter myStreamfilter1 = new MyGatewayTransportFilter1(); + fact.addGatewayTransportFilter(myStreamfilter1); + + GatewayReceiver receiver = fact.create(); + try { + receiver.start(); + } + catch (IOException e) { + fail("The test failed with IOException"); + } + int port = receiver.getPort(); + if ((port < 5303) || (port > GatewayReceiver.DEFAULT_END_PORT)) { + fail("GatewayReceiver started on out of range port"); + } + } + + @Test + public void test_ValidateGatwayReceiverWithWrongEndPortProvided() { + cache = new CacheFactory().set("mcast-port", "0").create(); + try { + GatewayReceiverFactory fact = cache.createGatewayReceiverFactory(); + fact.setMaximumTimeBetweenPings(1000); + fact.setSocketBufferSize(4000); + fact.setEndPort(4999); + GatewayReceiver receiver = fact.create(); + fail("wrong end port set in the GatewayReceiver"); + } catch (IllegalStateException expected) { + if(!expected.getMessage().contains("Please specify either start port a value which is less than end port.")){ + fail("Caught IllegalStateException"); + expected.printStackTrace(); + } + } + } + + @After + public void tearDown() throws Exception { + if (this.cache != null) { + this.cache.close(); + } + } +}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6df75241/gemfire-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/misc/WANLocatorServerDUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/misc/WANLocatorServerDUnitTest.java b/gemfire-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/misc/WANLocatorServerDUnitTest.java new file mode 100644 index 0000000..365559f --- /dev/null +++ b/gemfire-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/misc/WANLocatorServerDUnitTest.java @@ -0,0 +1,185 @@ +/*========================================================================= + * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * one or more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ +package com.gemstone.gemfire.internal.cache.wan.misc; + +import java.io.IOException; +import java.util.Properties; + +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheFactory; +import com.gemstone.gemfire.cache.client.ClientCache; +import com.gemstone.gemfire.cache.client.ClientCacheFactory; +import com.gemstone.gemfire.cache.client.PoolManager; +import com.gemstone.gemfire.cache.client.internal.Connection; +import com.gemstone.gemfire.cache.client.internal.PoolImpl; +import com.gemstone.gemfire.cache.server.CacheServer; +import com.gemstone.gemfire.cache.wan.GatewayReceiver; +import com.gemstone.gemfire.cache.wan.GatewayReceiverFactory; +import com.gemstone.gemfire.cache.wan.GatewaySender; +import com.gemstone.gemfire.distributed.internal.DistributionConfig; +import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem; +import com.gemstone.gemfire.internal.AvailablePortHelper; +import com.gemstone.gemfire.internal.cache.PoolFactoryImpl; +import com.gemstone.gemfire.internal.cache.wan.WANTestBase; + +import dunit.Host; + +public class WANLocatorServerDUnitTest extends WANTestBase { + + static PoolImpl proxy; + + public WANLocatorServerDUnitTest(String name) { + super(name); + } + + public void setUp() throws Exception { + super.setUp(); + final Host host = Host.getHost(0); + + } + + public void test_3Locators_2Servers() { + + int port1 = AvailablePortHelper.getRandomAvailablePortForDUnitSite(); + + int port2 = AvailablePortHelper.getRandomAvailablePortForDUnitSite(); + + int port3 = AvailablePortHelper.getRandomAvailablePortForDUnitSite(); + + vm0.invoke(WANLocatorServerDUnitTest.class, "createLocator", new Object[] { + port1, port2, port3, port1 }); + + vm1.invoke(WANLocatorServerDUnitTest.class, "createLocator", new Object[] { + port1, port2, port3, port2 }); + + vm2.invoke(WANLocatorServerDUnitTest.class, "createLocator", new Object[] { + port1, port2, port3, port3 }); + + vm3.invoke(WANLocatorServerDUnitTest.class, "createReceiver", new Object[] { + port1, port2, port3 }); + vm5.invoke(WANLocatorServerDUnitTest.class, "createClient", new Object[] { + port1, port2, port3 }); + + vm0.invoke(WANLocatorServerDUnitTest.class, "disconnect"); + vm1.invoke(WANLocatorServerDUnitTest.class, "disconnect"); + vm2.invoke(WANLocatorServerDUnitTest.class, "disconnect"); + + vm0.invoke(WANLocatorServerDUnitTest.class, "createLocator", new Object[] { + port1, port2, port3, port1 }); + + vm1.invoke(WANLocatorServerDUnitTest.class, "createLocator", new Object[] { + port1, port2, port3, port2 }); + + vm2.invoke(WANLocatorServerDUnitTest.class, "createLocator", new Object[] { + port1, port2, port3, port3 }); + + vm5.invoke(WANLocatorServerDUnitTest.class, "tryNewConnection"); + + } + + public static void createLocator(Integer port1, Integer port2, Integer port3, + Integer startingPort) { + WANTestBase test = new WANTestBase(testName); + Properties props = new Properties(); + props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0"); + props.setProperty(DistributionConfig.DISTRIBUTED_SYSTEM_ID_NAME, "" + 1); + props.setProperty(DistributionConfig.LOCATORS_NAME, "localhost[" + port1 + + "],localhost[" + port2 + "],localhost[" + port3 + "]"); + props.setProperty(DistributionConfig.START_LOCATOR_NAME, "localhost[" + + startingPort + + "],server=true,peer=true,hostname-for-clients=localhost"); + test.getSystem(props); + } + + public static void createReceiver(Integer port1, Integer port2, Integer port3) { + WANTestBase test = new WANTestBase(testName); + Properties props = new Properties(); + props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0"); + props.setProperty(DistributionConfig.LOCATORS_NAME, "localhost[" + port1 + + "],localhost[" + port2 + "],localhost[" + port3 + "]"); + + InternalDistributedSystem ds = test.getSystem(props); + cache = CacheFactory.create(ds); + GatewayReceiverFactory fact = cache.createGatewayReceiverFactory(); + int port = AvailablePortHelper.getRandomAvailablePortForDUnitSite(); + fact.setStartPort(port); + fact.setEndPort(port); + fact.setManualStart(true); + GatewayReceiver receiver = fact.create(); + try { + receiver.start(); + } + catch (IOException e) { + e.printStackTrace(); + fail("Test " + test.getName() + + " failed to start GatewayRecevier on port " + port); + } + } + + public static void createServer(Integer port1, Integer port2, Integer port3) { + WANTestBase test = new WANTestBase(testName); + Properties props = new Properties(); + props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0"); + props.setProperty(DistributionConfig.LOCATORS_NAME, "localhost[" + port1 + + "],localhost[" + port2 + "],localhost[" + port3 + "]"); + + InternalDistributedSystem ds = test.getSystem(props); + cache = CacheFactory.create(ds); + CacheServer server = cache.addCacheServer(); + int port = AvailablePortHelper.getRandomAvailablePortForDUnitSite(); + server.setPort(port); + try { + server.start(); + } + catch (IOException e) { + e.printStackTrace(); + fail("Test " + test.getName() + " failed to start CacheServer on port " + + port); + } + getLogWriter().info( + "Server Started on port : " + port + " : server : " + server); + } + + public static void disconnect() { + WANTestBase test = new WANTestBase(testName); + test.getSystem().disconnect(); + } + + public static void createClient(Integer port1, Integer port2, Integer port3) { + ClientCacheFactory cf = new ClientCacheFactory(); + cache = (Cache)cf.create(); + PoolFactoryImpl pf = (PoolFactoryImpl)PoolManager.createFactory(); + pf.setReadTimeout(0); + pf.setIdleTimeout(-1); + pf.setMinConnections(4); + pf.setServerGroup(GatewayReceiver.RECEIVER_GROUP); + pf.addLocator("localhost", port1); + pf.addLocator("localhost", port2); + pf.addLocator("localhost", port3); + pf.init((GatewaySender)null); + proxy = ((PoolImpl)pf.create("KISHOR_POOL")); + Connection con1 = proxy.acquireConnection(); + try { + con1.close(true); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + public static void tryNewConnection() { + Connection con1 = null; + try { + con1 = proxy.acquireConnection(); + } + catch (Exception e) { + fail("No Exception expected", e); + } + + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6df75241/gemfire-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/misc/WANSSLDUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/misc/WANSSLDUnitTest.java b/gemfire-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/misc/WANSSLDUnitTest.java new file mode 100644 index 0000000..d242ab9 --- /dev/null +++ b/gemfire-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/misc/WANSSLDUnitTest.java @@ -0,0 +1,136 @@ +package com.gemstone.gemfire.internal.cache.wan.misc; + +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.internal.cache.wan.WANTestBase; + +import dunit.DistributedTestCase; + +public class WANSSLDUnitTest extends WANTestBase{ + + public WANSSLDUnitTest(String name) { + super(name); + } + + public void setUp() throws Exception { + super.setUp(); + } + + public void testSenderSSLReceiverSSL(){ + Integer lnPort = (Integer)vm0.invoke(WANTestBase.class, + "createFirstLocatorWithDSId", new Object[] { 1 }); + Integer nyPort = (Integer)vm1.invoke(WANTestBase.class, + "createFirstRemoteLocator", new Object[] { 2, lnPort }); + + vm2.invoke(WANTestBase.class, "createReceiverWithSSL", new Object[] { nyPort }); + + vm4.invoke(WANTestBase.class, "createCacheWithSSL", new Object[] { lnPort }); + + vm4.invoke(WANTestBase.class, "createSender", new Object[] { "ln", 2, + false, 100, 10, false, false, null, true }); + + vm2.invoke(WANTestBase.class, "createReplicatedRegion", new Object[] { + testName + "_RR", null, isOffHeap() }); + + vm4.invoke(WANTestBase.class, "startSender", new Object[] { "ln" }); + + vm4.invoke(WANTestBase.class, "createReplicatedRegion", new Object[] { + testName + "_RR", "ln", isOffHeap() }); + + vm4.invoke(WANTestBase.class, "doPuts", new Object[] { testName + "_RR", + 1000 }); + + vm2.invoke(WANTestBase.class, "validateRegionSize", new Object[] { + testName + "_RR", 1000 }); + } + + public void testSenderNoSSLReceiverSSL() { + addExpectedException("Unexpected IOException"); + addExpectedException("SSL Error"); + addExpectedException("Unrecognized SSL message"); + try { + Integer lnPort = (Integer)vm0.invoke(WANTestBase.class, + "createFirstLocatorWithDSId", new Object[] { 1 }); + Integer nyPort = (Integer)vm1.invoke(WANTestBase.class, + "createFirstRemoteLocator", new Object[] { 2, lnPort }); + + vm2.invoke(WANTestBase.class, "createReceiverWithSSL", + new Object[] { nyPort }); + + vm4.invoke(WANTestBase.class, "createCache", new Object[] { lnPort }); + + vm4.invoke(WANTestBase.class, "createSender", new Object[] { "ln", 2, + false, 100, 10, false, false, null, true }); + + vm2.invoke(WANTestBase.class, "createReplicatedRegion", new Object[] { + testName + "_RR", null, isOffHeap() }); + + vm4.invoke(WANTestBase.class, "startSender", new Object[] { "ln" }); + + vm4.invoke(WANTestBase.class, "createReplicatedRegion", new Object[] { + testName + "_RR", "ln", isOffHeap() }); + + vm4.invoke(WANTestBase.class, "doPuts", new Object[] { testName + "_RR", + 1000 }); + + vm2.invoke(WANTestBase.class, "validateRegionSize", new Object[] { + testName + "_RR", 1000 }); + fail("Expected exception as only Receiver is SSL enabled. Not Sender"); + } + catch (Exception e) { + assertTrue(e.getCause().getMessage().contains("Server expecting SSL connection")); + } + } + + public void testSenderSSLReceiverNoSSL(){ + addExpectedException("Acceptor received unknown"); + addExpectedException("failed accepting client"); + Integer lnPort = (Integer)vm0.invoke(WANTestBase.class, + "createFirstLocatorWithDSId", new Object[] { 1 }); + Integer nyPort = (Integer)vm1.invoke(WANTestBase.class, + "createFirstRemoteLocator", new Object[] { 2, lnPort }); + + vm2.invoke(WANTestBase.class, "createReceiver", new Object[] { nyPort }); + + vm4.invoke(WANTestBase.class, "createCacheWithSSL", + new Object[] { lnPort }); + + vm4.invoke(WANTestBase.class, "createSender", new Object[] { "ln", 2, + false, 100, 10, false, false, null, true }); + + vm2.invoke(WANTestBase.class, "createReplicatedRegion", new Object[] { + testName + "_RR", null, isOffHeap() }); + + vm4.invoke(WANTestBase.class, "startSender", new Object[] { "ln" }); + + vm4.invoke(WANTestBase.class, "createReplicatedRegion", new Object[] { + testName + "_RR", "ln", isOffHeap() }); + + vm4.invoke(WANTestBase.class, "doPuts", new Object[] { testName + "_RR", + 1 }); + + Boolean doesSizeMatch = (Boolean)vm2.invoke(WANSSLDUnitTest.class, "ValidateSSLRegionSize", new Object[] { + testName + "_RR", 1 }); + + assertFalse(doesSizeMatch); + } + + public static boolean ValidateSSLRegionSize (String regionName, final int regionSize) { + final Region r = cache.getRegion(Region.SEPARATOR + regionName); + assertNotNull(r); + WaitCriterion wc = new WaitCriterion() { + public boolean done() { + return false; + } + + public String description() { + return null; + } + }; + DistributedTestCase.waitForCriterion(wc, 2000, 500, false); + + if(r.size() == regionSize){ + return true; + } + return false; + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6df75241/gemfire-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/misc/WanAutoDiscoveryDUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/misc/WanAutoDiscoveryDUnitTest.java b/gemfire-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/misc/WanAutoDiscoveryDUnitTest.java new file mode 100644 index 0000000..82cfd62 --- /dev/null +++ b/gemfire-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/misc/WanAutoDiscoveryDUnitTest.java @@ -0,0 +1,549 @@ +/*========================================================================= + * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * one or more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ +package com.gemstone.gemfire.internal.cache.wan.misc; + +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import com.gemstone.gemfire.GemFireConfigException; +import com.gemstone.gemfire.IncompatibleSystemException; +import com.gemstone.gemfire.internal.AvailablePortHelper; +import com.gemstone.gemfire.internal.cache.wan.WANTestBase; + +import dunit.AsyncInvocation; +import dunit.Host; + +public class WanAutoDiscoveryDUnitTest extends WANTestBase { + + + public WanAutoDiscoveryDUnitTest(String name) { + super(name); + } + + public void setUp() throws Exception { + super.setUp(); + final Host host = Host.getHost(0); + + } + + /** + * Test to validate that sender can not be started without locator started. + * else GemFireConfigException will be thrown. + */ + public void test_GatewaySender_Started_Before_Locator() { + try { + int port = AvailablePortHelper.getRandomAvailablePortForDUnitSite(); + vm0.invoke(WANTestBase.class, "createCache", new Object[]{port}); + vm0.invoke(WANTestBase.class, "createSender", new Object[]{"ln",2,false,100,10,false,false, null, false}); + fail("Expected GemFireConfigException but not thrown"); + } + catch (Exception e) { + if (!(e.getCause() instanceof GemFireConfigException)) { + fail("Expected GemFireConfigException but received :", e); + } + } + } + + /** + * Test to validate that all locators in one DS should have same name. Though + * this test passes, it causes other below tests to fail. In this test, VM1 is + * throwing IncompatibleSystemException after startInitLocator. I think, after + * throwing this exception, locator is not stopped properly and hence other + * tests are failing. + * + * @throws Exception + */ + public void __test_AllLocatorsinDSShouldHaveDistributedSystemId() throws Exception { + try { + Integer lnLocPort1 = (Integer)vm0.invoke( + WANTestBase.class, "createFirstLocatorWithDSId", + new Object[] {1}); + + Integer lnLocPort2 = (Integer)vm1.invoke( + WANTestBase.class, "createSecondLocator", new Object[] { 2, + lnLocPort1 }); + fail("Expected IncompatibleSystemException but not thrown"); + } + catch (Exception e) { + if (!(e.getCause()instanceof IncompatibleSystemException)) { + fail("Expected IncompatibleSystemException but received :", e); + } + } + } + + /** + * Test to validate that multiple locators added on LN site and multiple + * locators on Ny site recognizes each other + * @throws Exception + */ + public void test_NY_Recognises_ALL_LN_Locators() throws Exception { + ArrayList<Integer> locatorPorts = new ArrayList<Integer>(); + Map<Integer, ArrayList<Integer>> dsVsPort = new HashMap<Integer, ArrayList<Integer>>(); + dsVsPort.put(1, locatorPorts); + + Integer lnLocPort1 = (Integer)vm0.invoke( + WANTestBase.class, "createFirstLocatorWithDSId", + new Object[] {1}); + locatorPorts.add(lnLocPort1); + + Integer lnLocPort2 = (Integer)vm1.invoke(WANTestBase.class, + "createSecondLocator", new Object[] { 1, lnLocPort1 }); + locatorPorts.add(lnLocPort2); + + locatorPorts = new ArrayList<Integer>(); + dsVsPort.put(2, locatorPorts); + Integer nyLocPort1 = (Integer)vm2.invoke(WANTestBase.class, + "createFirstRemoteLocator", new Object[] { 2, lnLocPort1 }); + locatorPorts.add(nyLocPort1); + + Integer nyLocPort2 = (Integer)vm3.invoke( + WANTestBase.class, "createSecondRemoteLocator", new Object[] { + 2, nyLocPort1, lnLocPort1}); + locatorPorts.add(nyLocPort2); + + vm0.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + vm1.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + vm2.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + vm3.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + } + + /** + * Test to validate that TK site's locator is recognized by LN and NY. Test to + * validate that HK site's locator is recognized by LN , NY, TK. + */ + public void test_NY_Recognises_TK_AND_HK_Through_LN_Locator() { + + Map<Integer, ArrayList<Integer>> dsVsPort = new HashMap<Integer, ArrayList<Integer>>(); + + ArrayList<Integer> locatorPorts = new ArrayList<Integer>(); + dsVsPort.put(1, locatorPorts); + + Integer lnLocPort1 = (Integer)vm0.invoke(WANTestBase.class, + "createFirstLocatorWithDSId", new Object[] { 1 }); + locatorPorts.add(lnLocPort1); + + locatorPorts = new ArrayList<Integer>(); + dsVsPort.put(2, locatorPorts); + Integer nyLocPort1 = (Integer)vm1.invoke(WANTestBase.class, + "createFirstRemoteLocator", new Object[] { 2, lnLocPort1 }); + locatorPorts.add(nyLocPort1); + + locatorPorts = new ArrayList<Integer>(); + dsVsPort.put(3, locatorPorts); + Integer tkLocPort = (Integer)vm2.invoke(WANTestBase.class, + "createFirstRemoteLocator", new Object[] { 3, lnLocPort1 }); + locatorPorts.add(tkLocPort); + + locatorPorts = new ArrayList<Integer>(); + dsVsPort.put(4, locatorPorts); + Integer hkLocPort = (Integer)vm3.invoke(WANTestBase.class, + "createFirstRemoteLocator", new Object[] { 4, lnLocPort1 }); + locatorPorts.add(hkLocPort); + + vm0.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + vm1.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + vm2.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + vm3.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + } + + public void test_TK_Recognises_LN_AND_NY() { + + Map<Integer, ArrayList<Integer>> dsVsPort = new HashMap<Integer, ArrayList<Integer>>(); + + ArrayList<Integer> locatorPorts = new ArrayList<Integer>(); + dsVsPort.put(1, locatorPorts); + + Integer lnLocPort1 = (Integer)vm0.invoke(WANTestBase.class, + "createFirstLocatorWithDSId", new Object[] { 1 }); + locatorPorts.add(lnLocPort1); + + locatorPorts = new ArrayList<Integer>(); + dsVsPort.put(2, locatorPorts); + Integer nyLocPort1 = (Integer)vm1.invoke(WANTestBase.class, + "createFirstRemoteLocator", new Object[] { 2, lnLocPort1 }); + locatorPorts.add(nyLocPort1); + + locatorPorts = new ArrayList<Integer>(); + dsVsPort.put(3, locatorPorts); + Integer tkLocPort = (Integer)vm2.invoke(WANTestBase.class, + "createFirstRemoteLocator", new Object[] { 3, nyLocPort1 }); + locatorPorts.add(tkLocPort); + + + vm0.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + vm1.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + vm2.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + } + + public void test_NY_Recognises_TK_AND_HK_Simeltenously() { + Map<Integer, ArrayList<Integer>> dsVsPort = new HashMap<Integer, ArrayList<Integer>>(); + + ArrayList<Integer> locatorPortsln = new ArrayList<Integer>(); + dsVsPort.put(1, locatorPortsln); + Integer lnLocPort1 = (Integer)vm0.invoke(WANTestBase.class, + "createFirstLocatorWithDSId", new Object[] { 1 }); + locatorPortsln.add(lnLocPort1); + + ArrayList<Integer> locatorPortsny = new ArrayList<Integer>(); + dsVsPort.put(2, locatorPortsny); + Integer nyLocPort1 = (Integer)vm1.invoke(WANTestBase.class, + "createFirstRemoteLocator", new Object[] { 2, lnLocPort1 }); + locatorPortsny.add(nyLocPort1); + + int AsyncInvocationArrSize = 4; + AsyncInvocation[] async = new AsyncInvocation[AsyncInvocationArrSize]; + + ArrayList<Integer> locatorPortstk = new ArrayList<Integer>(); + dsVsPort.put(3, locatorPortstk); + async[0] = vm2.invokeAsync(WANTestBase.class, "createFirstRemoteLocator", + new Object[] { 3, lnLocPort1 }); + + ArrayList<Integer> locatorPortshk = new ArrayList<Integer>(); + dsVsPort.put(4, locatorPortshk); + async[1] = vm3.invokeAsync( + WANTestBase.class, "createFirstRemoteLocator", new Object[] {4, nyLocPort1}); + + ArrayList<Integer> locatorPortsln2 = new ArrayList<Integer>(); + async[2] = vm4.invokeAsync(WANTestBase.class, + "createSecondLocator", new Object[] { 1, lnLocPort1 }); + + ArrayList<Integer> locatorPortsny2 = new ArrayList<Integer>(); + async[3] = vm5.invokeAsync(WANTestBase.class, + "createSecondLocator", new Object[] { 2, nyLocPort1 }); + + + try { + async[0].join(); + async[1].join(); + async[2].join(); + async[3].join(); + } catch (InterruptedException e) { + e.printStackTrace(); + fail(); + } + + locatorPortstk.add((Integer)async[0].getReturnValue()); + locatorPortshk.add((Integer)async[1].getReturnValue()); + locatorPortsln.add((Integer)async[2].getReturnValue()); + locatorPortsny.add((Integer)async[3].getReturnValue()); + + vm0.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + vm1.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + vm2.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + vm3.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + } + + + public void test_LN_Sender_recogises_ALL_NY_Locators() { + + Integer lnLocPort1 = (Integer)vm0.invoke(WANTestBase.class, + "createFirstLocatorWithDSId", new Object[] { 1 }); + + Integer lnLocPort2 = (Integer)vm5.invoke(WANTestBase.class, + "createSecondLocator", new Object[] { 1, lnLocPort1 }); + + vm2.invoke(WANTestBase.class, "createCache", new Object[]{lnLocPort1, lnLocPort2}); + + vm2.invoke(WANTestBase.class, "createSender", + new Object[] {"ln",2,false,100,10,false,false, null, true}); + + Integer nyLocPort1 = (Integer)vm1.invoke(WANTestBase.class, + "createFirstRemoteLocator", new Object[] { 2, lnLocPort1 }); + + vm2.invoke(WANTestBase.class, "startSender",new Object[]{"ln"}); + + //Since to fix Bug#46289, we have moved call to initProxy in getConnection which will be called only when batch is getting dispatched. + //So for locator discovery callback to work, its now expected that atleast try to send a batch so that proxy will be initialized + vm2.invoke(WANTestBase.class, "createReplicatedRegion", new Object[] { + testName + "_RR", "ln", isOffHeap() }); + + vm2.invoke(WANTestBase.class, "doPuts", + new Object[] { testName + "_RR", 10}); + + Integer nyLocPort2 = (Integer)vm3 + .invoke(WANTestBase.class, "createSecondRemoteLocator", new Object[] { + 2, nyLocPort1, lnLocPort1 }); + + InetSocketAddress locatorToWaitFor = new InetSocketAddress("localhost", + nyLocPort2); + + vm2.invoke(WANTestBase.class, "checkLocatorsinSender", + new Object[] {"ln", locatorToWaitFor }); + + Integer nyLocPort3 = (Integer)vm4 + .invoke(WANTestBase.class, "createSecondRemoteLocator", new Object[] { + 2, nyLocPort1, lnLocPort1 }); + + locatorToWaitFor = new InetSocketAddress("localhost", nyLocPort3); + + vm2.invoke(WANTestBase.class, "checkLocatorsinSender", + new Object[] {"ln", locatorToWaitFor }); + + } + + + public void test_RingTopology() { + + final Set<String> site1LocatorsPort = new HashSet<String>(); + int site1Port1 = AvailablePortHelper.getRandomAvailablePortForDUnitSite(); + site1LocatorsPort.add("localhost["+site1Port1+"]"); + + final Set<String> site2LocatorsPort = new HashSet<String>(); + int site2Port1 = AvailablePortHelper.getRandomAvailablePortForDUnitSite(); + site2LocatorsPort.add("localhost["+site2Port1+"]"); + + final Set<String> site3LocatorsPort = new HashSet<String>(); + int site3Port1 = AvailablePortHelper.getRandomAvailablePortForDUnitSite(); + site3LocatorsPort.add("localhost["+site3Port1+"]"); + + final Set<String> site4LocatorsPort = new HashSet<String>(); + int site4Port1 = AvailablePortHelper.getRandomAvailablePortForDUnitSite(); + site4LocatorsPort.add("localhost["+site4Port1+"]"); + + Map<Integer, Set<String>> dsVsPort = new HashMap<Integer, Set<String>>(); + dsVsPort.put(1, site1LocatorsPort); + dsVsPort.put(2, site2LocatorsPort); + dsVsPort.put(3, site3LocatorsPort); + dsVsPort.put(4, site4LocatorsPort); + + int AsyncInvocationArrSize = 9; + AsyncInvocation[] async = new AsyncInvocation[AsyncInvocationArrSize]; + + async[0] = vm0.invokeAsync(WANTestBase.class, + "createLocator", new Object[] { 1, site1Port1, site1LocatorsPort, site2LocatorsPort}); + + async[1] = vm1.invokeAsync(WANTestBase.class, + "createLocator", new Object[] { 2, site2Port1, site2LocatorsPort, site3LocatorsPort}); + + async[2] = vm2.invokeAsync(WANTestBase.class, + "createLocator", new Object[] { 3, site3Port1, site3LocatorsPort, site4LocatorsPort}); + + async[3] = vm3.invokeAsync(WANTestBase.class, + "createLocator", new Object[] { 4, site4Port1, site4LocatorsPort, site1LocatorsPort}); + + // pause(5000); + try { + async[0].join(); + async[1].join(); + async[2].join(); + async[3].join(); + } catch (InterruptedException e) { + e.printStackTrace(); + fail("Could not join async operations"); + } + + vm0.invoke(WANTestBase.class, "checkAllSiteMetaDataFor3Sites", + new Object[] { dsVsPort }); + vm1.invoke(WANTestBase.class, "checkAllSiteMetaDataFor3Sites", + new Object[] { dsVsPort }); + vm2.invoke(WANTestBase.class, "checkAllSiteMetaDataFor3Sites", + new Object[] { dsVsPort }); + vm3.invoke(WANTestBase.class, "checkAllSiteMetaDataFor3Sites", + new Object[] { dsVsPort }); + } + + public void ___test_3Sites3Locators() { + final Set<String> site1LocatorsPort = new HashSet<String>(); + int site1Port1 = AvailablePortHelper.getRandomAvailablePortForDUnitSite(); + site1LocatorsPort.add("localhost["+site1Port1+"]"); + int site1Port2 = AvailablePortHelper.getRandomAvailablePortForDUnitSite(); + site1LocatorsPort.add("localhost["+site1Port2+"]"); + int site1Port3 = AvailablePortHelper.getRandomAvailablePortForDUnitSite(); + site1LocatorsPort.add("localhost["+site1Port3+"]"); + + final Set<String> site2LocatorsPort = new HashSet<String>(); + int site2Port1 = AvailablePortHelper.getRandomAvailablePortForDUnitSite(); + site2LocatorsPort.add("localhost["+site2Port1+"]"); + int site2Port2 = AvailablePortHelper.getRandomAvailablePortForDUnitSite(); + site2LocatorsPort.add("localhost["+site2Port2+"]"); + int site2Port3 = AvailablePortHelper.getRandomAvailablePortForDUnitSite(); + site2LocatorsPort.add("localhost["+site2Port3+"]"); + + final Set<String> site3LocatorsPort = new HashSet<String>(); + int site3Port1 = AvailablePortHelper.getRandomAvailablePortForDUnitSite(); + site3LocatorsPort.add("localhost["+site3Port1+"]"); + final int site3Port2 = AvailablePortHelper.getRandomAvailablePortForDUnitSite(); + site3LocatorsPort.add("localhost["+site3Port2+"]"); + int site3Port3 = AvailablePortHelper.getRandomAvailablePortForDUnitSite(); + site3LocatorsPort.add("localhost["+site3Port3+"]"); + + Map<Integer, Set<String>> dsVsPort = new HashMap<Integer, Set<String>>(); + dsVsPort.put(1, site1LocatorsPort); + dsVsPort.put(2, site2LocatorsPort); + dsVsPort.put(3, site3LocatorsPort); + + int AsyncInvocationArrSize = 9; + AsyncInvocation[] async = new AsyncInvocation[AsyncInvocationArrSize]; + + async[0] = vm0.invokeAsync(WANTestBase.class, + "createLocator", new Object[] { 1, site1Port1, site1LocatorsPort, site2LocatorsPort}); + + async[8] = vm0.invokeAsync(WANTestBase.class, + "checkAllSiteMetaDataFor3Sites", new Object[] {dsVsPort}); + + async[1] = vm1.invokeAsync(WANTestBase.class, + "createLocator", new Object[] { 1, site1Port2, site1LocatorsPort, site2LocatorsPort}); + async[2] = vm2.invokeAsync(WANTestBase.class, + "createLocator", new Object[] { 1, site1Port3, site1LocatorsPort, site2LocatorsPort}); + + async[3] = vm3.invokeAsync(WANTestBase.class, + "createLocator", new Object[] { 2, site2Port1, site2LocatorsPort, site3LocatorsPort}); + async[4] = vm4.invokeAsync(WANTestBase.class, + "createLocator", new Object[] { 2, site2Port2, site2LocatorsPort, site3LocatorsPort}); + async[5] = vm5.invokeAsync(WANTestBase.class, + "createLocator", new Object[] { 2, site2Port3, site2LocatorsPort, site3LocatorsPort}); + + async[6] = vm6.invokeAsync(WANTestBase.class, + "createLocator", new Object[] { 3, site3Port1, site3LocatorsPort, site1LocatorsPort}); + async[7] = vm7.invokeAsync(WANTestBase.class, + "createLocator", new Object[] { 3, site3Port2, site3LocatorsPort, site1LocatorsPort}); + + WANTestBase.createLocator(3, site3Port3, site3LocatorsPort, site1LocatorsPort); + long startTime = System.currentTimeMillis(); + + try { + async[0].join(); + async[1].join(); + async[2].join(); + async[3].join(); + async[4].join(); + async[5].join(); + async[6].join(); + async[7].join(); + async[8].join(); + } catch (InterruptedException e) { + e.printStackTrace(); + fail("Could not join async operations"); + } + Long endTime = null; + try { + endTime = (Long)async[8].getResult(); + } + catch (Throwable e) { + e.printStackTrace(); + fail("Could not get end time", e); + } + + getLogWriter().info("Time taken for all 9 locators discovery in 3 sites: " + (endTime.longValue() - startTime)); + + vm0.invoke(WANTestBase.class, "checkAllSiteMetaDataFor3Sites", + new Object[] { dsVsPort }); + vm1.invoke(WANTestBase.class, "checkAllSiteMetaDataFor3Sites", + new Object[] { dsVsPort }); + vm2.invoke(WANTestBase.class, "checkAllSiteMetaDataFor3Sites", + new Object[] { dsVsPort }); + vm3.invoke(WANTestBase.class, "checkAllSiteMetaDataFor3Sites", + new Object[] { dsVsPort }); + vm4.invoke(WANTestBase.class, "checkAllSiteMetaDataFor3Sites", + new Object[] { dsVsPort }); + vm5.invoke(WANTestBase.class, "checkAllSiteMetaDataFor3Sites", + new Object[] { dsVsPort }); + vm6.invoke(WANTestBase.class, "checkAllSiteMetaDataFor3Sites", + new Object[] { dsVsPort }); + vm7.invoke(WANTestBase.class, "checkAllSiteMetaDataFor3Sites", + new Object[] { dsVsPort }); + WANTestBase.checkAllSiteMetaDataFor3Sites(dsVsPort); + } + + + public void test_LN_Peer_Locators_Exchange_Information() { + ArrayList<Integer> locatorPorts = new ArrayList<Integer>(); + Map<Integer, ArrayList<Integer>> dsVsPort = new HashMap<Integer, ArrayList<Integer>>(); + dsVsPort.put(1, locatorPorts); + + Integer lnLocPort1 = (Integer)vm0.invoke( + WANTestBase.class, "createFirstPeerLocator", + new Object[] {1}); + locatorPorts.add(lnLocPort1); + + Integer lnLocPort2 = (Integer)vm1.invoke(WANTestBase.class, + "createSecondPeerLocator", new Object[] { 1, lnLocPort1 }); + locatorPorts.add(lnLocPort2); + + vm0.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + vm1.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + } + + public void test_LN_NY_TK_5_PeerLocators_1_ServerLocator() { + Map<Integer, ArrayList<Integer>> dsVsPort = new HashMap<Integer, ArrayList<Integer>>(); + + + ArrayList<Integer> locatorPorts = new ArrayList<Integer>(); + dsVsPort.put(1, locatorPorts); + Integer lnLocPort1 = (Integer)vm0.invoke( + WANTestBase.class, "createFirstPeerLocator", + new Object[] {1}); + locatorPorts.add(lnLocPort1); + Integer lnLocPort2 = (Integer)vm1.invoke(WANTestBase.class, + "createSecondPeerLocator", new Object[] { 1, lnLocPort1 }); + locatorPorts.add(lnLocPort2); + + locatorPorts = new ArrayList<Integer>(); + dsVsPort.put(2, locatorPorts); + Integer nyLocPort1 = (Integer)vm2.invoke( + WANTestBase.class, "createFirstRemotePeerLocator", + new Object[] {2, lnLocPort1}); + locatorPorts.add(nyLocPort1); + Integer nyLocPort2 = (Integer)vm3.invoke(WANTestBase.class, + "createSecondRemotePeerLocator", new Object[] { 2, nyLocPort1, lnLocPort2}); + locatorPorts.add(nyLocPort2); + + locatorPorts = new ArrayList<Integer>(); + dsVsPort.put(3, locatorPorts); + Integer tkLocPort1 = (Integer)vm4.invoke( + WANTestBase.class, "createFirstRemotePeerLocator", + new Object[] {3, nyLocPort1}); + locatorPorts.add(tkLocPort1); + Integer tkLocPort2 = (Integer)vm5.invoke(WANTestBase.class, + "createSecondRemotePeerLocator", new Object[] { 3, tkLocPort1, nyLocPort1}); + locatorPorts.add(tkLocPort2); + Integer tkLocPort3 = (Integer)vm6.invoke(WANTestBase.class, + "createSecondRemoteLocator", new Object[] { 3, tkLocPort1, nyLocPort2}); + locatorPorts.add(tkLocPort3); + + // pause(5000); + + vm0.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + vm1.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + vm2.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + vm3.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + vm4.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + vm5.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + vm6.invoke(WANTestBase.class, "checkAllSiteMetaData", + new Object[] { dsVsPort }); + + } + +}