added test for region multicast enabled

updated multicast test


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/81c472f7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/81c472f7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/81c472f7

Branch: refs/heads/feature/GEODE-291
Commit: 81c472f714967da158a1039e5efda4fc478b56b4
Parents: 1c42379
Author: Hitesh Khamesra <[email protected]>
Authored: Wed Dec 9 11:15:34 2015 -0800
Committer: Hitesh Khamesra <[email protected]>
Committed: Thu Dec 10 15:31:12 2015 -0800

----------------------------------------------------------------------
 .../gemfire/distributed/internal/DMStats.java   |   1 +
 .../distributed/internal/DistributionStats.java |   3 +
 .../internal/LonerDistributionManager.java      |   2 +
 .../DistributedMulticastRegionDUnitTest.java    | 197 +++++++++++++++++++
 4 files changed, 203 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/81c472f7/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/DMStats.java
----------------------------------------------------------------------
diff --git 
a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/DMStats.java
 
b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/DMStats.java
index e7b155a..e79a40b 100644
--- 
a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/DMStats.java
+++ 
b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/DMStats.java
@@ -205,6 +205,7 @@ public interface DMStats {
    * returns the current value of the mcastWrites statistic
    */
   public int getMcastWrites();
+  public int getMcastReads();
 
   public long startSerialization();
   public void endSerialization(long start, int bytes);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/81c472f7/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/DistributionStats.java
----------------------------------------------------------------------
diff --git 
a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/DistributionStats.java
 
b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/DistributionStats.java
index 39b4986..804b507 100644
--- 
a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/DistributionStats.java
+++ 
b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/DistributionStats.java
@@ -1094,6 +1094,9 @@ public class DistributionStats implements DMStats {
   public int getMcastWrites() {
     return stats.getInt(mcastWritesId);
   }
+  public int getMcastReads() {
+    return stats.getInt(mcastReadsId);
+  }
   public void incMcastReadBytes(int amount) {
     stats.incInt(mcastReadsId, 1);
     stats.incLong(mcastReadBytesId, amount);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/81c472f7/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/LonerDistributionManager.java
----------------------------------------------------------------------
diff --git 
a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/LonerDistributionManager.java
 
b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/LonerDistributionManager.java
index 1fc9f5b..60158d1 100644
--- 
a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/LonerDistributionManager.java
+++ 
b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/LonerDistributionManager.java
@@ -451,6 +451,8 @@ public class LonerDistributionManager implements DM {
     @Override
     public int getMcastWrites() { return 0; }
     @Override
+    public int getMcastReads() { return 0; }
+    @Override
     public void incUcastReadBytes(int amount) {}
     @Override
     public void incMcastReadBytes(int amount) {}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/81c472f7/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/DistributedMulticastRegionDUnitTest.java
----------------------------------------------------------------------
diff --git 
a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/DistributedMulticastRegionDUnitTest.java
 
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/DistributedMulticastRegionDUnitTest.java
new file mode 100755
index 0000000..f8296cc
--- /dev/null
+++ 
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/DistributedMulticastRegionDUnitTest.java
@@ -0,0 +1,197 @@
+package com.gemstone.gemfire.cache30;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import com.gemstone.gemfire.cache.AttributesFactory;
+import com.gemstone.gemfire.cache.CacheException;
+import com.gemstone.gemfire.cache.DataPolicy;
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.RegionAttributes;
+import com.gemstone.gemfire.cache.Scope;
+import com.gemstone.gemfire.distributed.Locator;
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.distributed.internal.InternalLocator;
+import com.gemstone.gemfire.distributed.internal.SharedConfiguration;
+import com.gemstone.gemfire.internal.AvailablePortHelper;
+import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
+import com.gemstone.gemfire.internal.cache.OffHeapTestUtil;
+
+import dunit.DistributedTestCase;
+import dunit.Host;
+import dunit.SerializableCallable;
+import dunit.SerializableRunnable;
+import dunit.VM;
+
+public class DistributedMulticastRegionDUnitTest extends CacheTestCase {
+
+  static int locatorVM = 3;
+  static String mcastport = "42786";
+  static String mcastttl = "0";
+  
+  private int locatorPort;
+
+  public DistributedMulticastRegionDUnitTest(String name) {
+    super(name);
+  }
+  
+  @Override
+  public void setUp() throws Exception {
+    clean();
+    super.setUp();    
+  }
+  
+  @Override
+  public void tearDown2() throws Exception {
+    clean();
+    super.tearDown2();
+  }
+  
+  private void clean(){
+    SerializableRunnable cleanVM =
+        new CacheSerializableRunnable("clean VM") {
+            public void run2() throws CacheException {
+              disconnectFromDS();
+            }
+        };
+    invokeInEveryVM(cleanVM);    
+  }
+  
+  public void testMulticastEnabled() {
+    final String name = "mcastRegion";
+    SerializableRunnable create =
+      new CacheSerializableRunnable("Create Region") {
+          public void run2() throws CacheException {
+            createRegion(name, getRegionAttributes());
+          }
+        };
+
+    locatorPort = startLocator();
+    Host host = Host.getHost(0);
+    final VM vm0 = host.getVM(0);
+    final VM vm1 = host.getVM(1);
+    //1. start locator with mcast port
+    vm0.invoke(create);
+    vm1.invoke(create);
+    
+    SerializableRunnable validateMulticastBeforeRegionOps =
+        new CacheSerializableRunnable("validateMulticast before region ops") {
+            public void run2() throws CacheException {
+              validateMulticastOpsBeforeRegionOps();
+            }
+        };
+      
+    vm0.invoke(validateMulticastBeforeRegionOps);
+    vm1.invoke(validateMulticastBeforeRegionOps);
+    
+    SerializableRunnable doPuts =
+      new CacheSerializableRunnable("do put") {
+          public void run2() throws CacheException {
+            final Region region =
+                getRootRegion().getSubregion(name);
+            for(int i =0 ; i < 5; i++) {
+              region.put(i, i);
+            }
+          }
+      };
+      
+    vm0.invoke(doPuts);
+    
+    SerializableRunnable validateMulticastAfterRegionOps =
+      new CacheSerializableRunnable("validateMulticast after region ops") {
+          public void run2() throws CacheException {
+            validateMulticastOpsAfterRegionOps();
+          }
+      };
+    
+      vm0.invoke(validateMulticastAfterRegionOps);
+      vm1.invoke(validateMulticastAfterRegionOps);
+   
+      closeLocator();      
+  }
+  
+  protected RegionAttributes getRegionAttributes() {
+    AttributesFactory factory = new AttributesFactory();
+    factory.setScope(Scope.DISTRIBUTED_ACK);
+    factory.setDataPolicy(DataPolicy.PRELOADED);
+    factory.setEarlyAck(false);
+    factory.setConcurrencyChecksEnabled(false);
+    factory.setMulticastEnabled(true);
+    return factory.create();
+  }
+  
+  public Properties getDistributedSystemProperties() {
+    Properties p = new Properties();
+    p.put(DistributionConfig.STATISTIC_SAMPLING_ENABLED_NAME, "true");
+    p.put(DistributionConfig.STATISTIC_ARCHIVE_FILE_NAME, "multicast");
+    p.put(DistributionConfig.MCAST_PORT_NAME, mcastport);
+    p.put(DistributionConfig.MCAST_TTL_NAME, mcastttl);
+    p.put(DistributionConfig.LOCATORS_NAME, "localhost[" + locatorPort +"]");
+    p.put(DistributionConfig.LOG_LEVEL_NAME, "info");
+    return p;
+  } 
+  
+  private void validateMulticastOpsAfterRegionOps() {
+    int writes = 
getGemfireCache().getDistributionManager().getStats().getMcastWrites();
+    int reads = 
getGemfireCache().getDistributionManager().getStats().getMcastReads();
+    assertTrue("Should have multicast writes or reads. Writes=  " + writes +  
" ,read= " + reads, 
+        writes > 0 || reads > 0);
+  }
+  
+  private void validateMulticastOpsBeforeRegionOps() {
+    int writes = 
getGemfireCache().getDistributionManager().getStats().getMcastWrites();
+    int reads = 
getGemfireCache().getDistributionManager().getStats().getMcastReads();
+    int total = writes + reads;
+    assertTrue("Should not have any multicast writes or reads before region 
ops. Writes=  " + writes +  " ,read= " + reads, 
+        total == 0);
+  }
+  
+  private int startLocator() {
+  final int [] ports = AvailablePortHelper.getRandomAvailableTCPPorts(3);
+  final int locatorPort = ports[0];
+  
+  VM locator1Vm = Host.getHost(0).getVM(locatorVM);;
+    locator1Vm.invoke(new SerializableCallable() {
+      @Override
+      public Object call() {
+        final File locatorLogFile = new File(testName + "-locator-" + 
locatorPort + ".log");
+        final Properties locatorProps = new Properties();
+        locatorProps.setProperty(DistributionConfig.NAME_NAME, 
"LocatorWithMcast");
+        locatorProps.setProperty(DistributionConfig.MCAST_PORT_NAME, 
mcastport);
+        locatorProps.setProperty(DistributionConfig.MCAST_TTL_NAME, mcastttl);
+        locatorProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "info");
+        
//locatorProps.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME,
 "true");
+        try {
+          final InternalLocator locator = (InternalLocator) 
Locator.startLocatorAndDS(locatorPort, null, null,
+              locatorProps);
+          System.out.println("test Locator started " + locatorPort);
+           } catch (IOException ioex) {
+          fail("Unable to create a locator with a shared configuration");
+        }
+  
+        return null;
+      }
+    });
+    return locatorPort;
+  }
+  
+  private void closeLocator() {
+    VM locator1Vm = Host.getHost(0).getVM(locatorVM);;
+    SerializableRunnable locatorCleanup = new SerializableRunnable() {
+      @Override
+      public void run() {
+        System.out.println("test Locator closing " + locatorPort);;
+        InternalLocator locator = InternalLocator.getLocator();
+        if (locator != null ) {
+          locator.stop();
+          System.out.println("test Locator closed " + locatorPort);;
+        }
+      }
+    };
+    locator1Vm.invoke(locatorCleanup);
+  }
+  
+}

Reply via email to