geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [14/16] incubator-geode git commit: GEODE-364: Amending Pool configuration to avoid the changing of connections, which could cause the test to fail.
Date Tue, 10 May 2016 21:10:01 GMT
GEODE-364: Amending Pool configuration to avoid the changing of connections, which could cause
the test to fail.


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

Branch: refs/heads/feature/GEODE-1371
Commit: bcf7c94fb8247754eb2d73749d05be3a5011624c
Parents: f93c87f
Author: Udo Kohlmeyer <ukohlmeyer@pivotal.io>
Authored: Wed May 11 05:47:10 2016 +1000
Committer: Udo Kohlmeyer <ukohlmeyer@pivotal.io>
Committed: Wed May 11 05:51:44 2016 +1000

----------------------------------------------------------------------
 .../internal/cache/SingleHopStatsDUnitTest.java | 448 ++++++++-----------
 1 file changed, 198 insertions(+), 250 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bcf7c94f/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/SingleHopStatsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/SingleHopStatsDUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/SingleHopStatsDUnitTest.java
index 307f18f..671bdf7 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/SingleHopStatsDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/SingleHopStatsDUnitTest.java
@@ -16,20 +16,8 @@
  */
 package com.gemstone.gemfire.internal.cache;
 
-import java.io.IOException;
-import java.util.Map;
-import java.util.Properties;
-
-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.PartitionAttributesFactory;
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.RegionAttributes;
-import com.gemstone.gemfire.cache.Scope;
+import com.gemstone.gemfire.cache.*;
+import com.gemstone.gemfire.cache.client.ClientCache;
 import com.gemstone.gemfire.cache.client.Pool;
 import com.gemstone.gemfire.cache.client.PoolManager;
 import com.gemstone.gemfire.cache.client.internal.ClientMetadataService;
@@ -37,71 +25,43 @@ import com.gemstone.gemfire.cache.client.internal.ClientPartitionAdvisor;
 import com.gemstone.gemfire.cache.server.CacheServer;
 import com.gemstone.gemfire.cache30.CacheTestCase;
 import com.gemstone.gemfire.distributed.DistributedSystem;
-import com.gemstone.gemfire.distributed.Locator;
-import com.gemstone.gemfire.internal.AvailablePort;
 import com.gemstone.gemfire.internal.cache.execute.data.CustId;
 import com.gemstone.gemfire.internal.cache.execute.data.OrderId;
 import com.gemstone.gemfire.internal.cache.execute.data.ShipmentId;
 import com.gemstone.gemfire.internal.cache.tier.sockets.CacheServerTestUtil;
-import com.gemstone.gemfire.test.dunit.Assert;
-import com.gemstone.gemfire.test.dunit.DistributedTestUtils;
-import com.gemstone.gemfire.test.dunit.Host;
-import com.gemstone.gemfire.test.dunit.Invoke;
-import com.gemstone.gemfire.test.dunit.LogWriterUtils;
-import com.gemstone.gemfire.test.dunit.SerializableRunnable;
-import com.gemstone.gemfire.test.dunit.VM;
-import com.gemstone.gemfire.test.dunit.Wait;
-import com.gemstone.gemfire.test.dunit.WaitCriterion;
+import com.gemstone.gemfire.test.dunit.*;
 import com.gemstone.gemfire.test.junit.categories.FlakyTest;
+import com.jayway.awaitility.Awaitility;
+import org.junit.experimental.categories.Category;
 
-public class SingleHopStatsDUnitTest extends CacheTestCase {
+import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
 
-  private static final String Region_Name = "42010";
+public class SingleHopStatsDUnitTest extends CacheTestCase {
 
+  private final String Region_Name = "42010";
+  private final String ORDER_REGION_NAME = "ORDER";
+  private final String SHIPMENT_REGION_NAME = "SHIPMENT";
+  private final String CUSTOMER_REGION_NAME = "CUSTOMER";
   private VM member0 = null;
-
   private VM member1 = null;
-
   private VM member2 = null;
-
   private VM member3 = null;
 
-  private static Region region = null;
-
-  private static Region customerRegion = null;
-
-  private static Region orderRegion = null;
-
-  private static Region shipmentRegion = null;
-
-  private static Region regionWithResolver = null;
-
-  private static Cache cache = null;
-
-  private static final int locatorPort = 12345;
-
-  private static Locator locator = null;
-  
   private static long metaDataRefreshCount;
-  
   private static long nonSingleHopsCount;
-  
   private static long metaDataRefreshCount_Customer;
-  
   private static long nonSingleHopsCount_Customer;
-  
   private static long metaDataRefreshCount_Order;
-  
   private static long nonSingleHopsCount_Order;
-  
   private static long metaDataRefreshCount_Shipment;
-  
   private static long nonSingleHopsCount_Shipment;
-  
+
+
   public SingleHopStatsDUnitTest(String name) {
     super(name);
-
-    // TODO Auto-generated constructor stub
   }
 
   @Override
@@ -116,13 +76,13 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
   @Override
   public final void preTearDownCacheTestCase() throws Exception {
     // close the clients first
-    member0.invoke(() -> SingleHopStatsDUnitTest.closeCacheAndDisconnect());
-    member1.invoke(() -> SingleHopStatsDUnitTest.closeCacheAndDisconnect());
-    member2.invoke(() -> SingleHopStatsDUnitTest.closeCacheAndDisconnect());
-    member3.invoke(() -> SingleHopStatsDUnitTest.closeCacheAndDisconnect());
+    member0.invoke(() -> closeCacheAndDisconnect());
+    member1.invoke(() -> closeCacheAndDisconnect());
+    member2.invoke(() -> closeCacheAndDisconnect());
+    member3.invoke(() -> closeCacheAndDisconnect());
     closeCacheAndDisconnect();
   }
-  
+
   @Override
   public final void postTearDownCacheTestCase() throws Exception {
     try {
@@ -130,104 +90,95 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
       member1 = null;
       member2 = null;
       member3 = null;
-      cache = null;
-      Invoke.invokeInEveryVM(new SerializableRunnable() { public void run() { cache = null;
} });
-
-    }
-    finally {
+    } finally {
       DistributedTestUtils.unregisterAllDataSerializersFromAllVms();
     }
   }
 
-  public static void closeCacheAndDisconnect() {
-    if (cache != null && !cache.isClosed()) {
-      cache.close();
-      cache.getDistributedSystem().disconnect();
+  private void closeCacheAndDisconnect() {
+    try {
+      Cache cache = CacheFactory.getAnyInstance();
+      if (cache != null && !cache.isClosed()) {
+        cache.close();
+        cache.getDistributedSystem().disconnect();
+      }
+    } catch (CacheClosedException e) {
     }
   }
 
   @Category(FlakyTest.class) // GEODE-364: random ports, time sensitive, waitForCriterions,
magic numbers (113, 226)
   public void testClientStatsPR() {
-    VM server1 = member0;
-    VM server2 = member1;
-    VM server3 = member2;
-    VM client1 = member3;
-    
-    Integer port0 = (Integer)member0.invoke(() -> SingleHopStatsDUnitTest.createServerForStats(
0, 113,"No_Colocation"));
-    Integer port1 = (Integer)member1.invoke(() -> SingleHopStatsDUnitTest.createServerForStats(
0, 113,"No_Colocation"));
-    Integer port2 = (Integer)member2.invoke(() -> SingleHopStatsDUnitTest.createServerForStats(
0, 113,"No_Colocation"));
-     client1.invoke(() -> SingleHopStatsDUnitTest.createClient(port0, port1, port2,"No_Colocation"));
-     
+    Integer port0 = (Integer) member0.invoke(() -> createServerForStats(0, 113, "No_Colocation"));
+    Integer port1 = (Integer) member1.invoke(() -> createServerForStats(0, 113, "No_Colocation"));
+    Integer port2 = (Integer) member2.invoke(() -> createServerForStats(0, 113, "No_Colocation"));
+
+    member3.invoke(() -> createClient(port0, port1, port2, "No_Colocation"));
     createClient(port0, port1, port2, "No_Colocation");
 
-    client1.invoke(() -> SingleHopStatsDUnitTest.createPR("FirstClient", "No_Colocation"));
+    member3.invoke(() -> createPR("FirstClient", "No_Colocation"));
     createPR("SecondClient", "No_Colocation");
-    
-    client1.invoke(() -> SingleHopStatsDUnitTest.getPR("FirstClient", "No_Colocation"));
+
+    member3.invoke(() -> getPR("FirstClient", "No_Colocation"));
     getPR("SecondClient", "No_Colocation");
-    
-    client1.invoke(() -> SingleHopStatsDUnitTest.updatePR("FirstClient", "No_Colocation"));
+
+    member3.invoke(() -> updatePR("FirstClient", "No_Colocation"));
   }
-  
-  public void testClientStatsColocationPR(){
-    VM server1 = member0;
-    VM server2 = member1;
-    VM server3 = member2;
-    VM client1 = member3;
-    
-    Integer port0 = (Integer)member0.invoke(() -> SingleHopStatsDUnitTest.createServerForStats(
0, 4, "Colocation" ));
-    Integer port1 = (Integer)member1.invoke(() -> SingleHopStatsDUnitTest.createServerForStats(
0, 4, "Colocation" ));
-    Integer port2 = (Integer)member2.invoke(() -> SingleHopStatsDUnitTest.createServerForStats(
0, 4, "Colocation"));
-     client1.invoke(() -> SingleHopStatsDUnitTest.createClient(port0, port1, port2, "Colocation"));
+
+  public void testClientStatsColocationPR() {
+    Integer port0 = (Integer) member0.invoke(() -> createServerForStats(0, 4, "Colocation"));
+    Integer port1 = (Integer) member1.invoke(() -> createServerForStats(0, 4, "Colocation"));
+    Integer port2 = (Integer) member2.invoke(() -> createServerForStats(0, 4, "Colocation"));
+    member3.invoke(() -> createClient(port0, port1, port2, "Colocation"));
     createClient(port0, port1, port2, "Colocation");
 
-    client1.invoke(() -> SingleHopStatsDUnitTest.createPR("FirstClient", "Colocation"));
-    
-    client1.invoke(() -> SingleHopStatsDUnitTest.getPR("FirstClient", "Colocation"));
+    member3.invoke(() -> createPR("FirstClient", "Colocation"));
+
+    member3.invoke(() -> getPR("FirstClient", "Colocation"));
   }
 
-  
-  public static void createClient(int port0, int port1, int port2, String colocation) {
+  private void createClient(int port0, int port1, int port2, String colocation) {
     Properties props = new Properties();
     props = new Properties();
     props.setProperty("mcast-port", "0");
     props.setProperty("locators", "");
     CacheTestCase test = new SingleHopStatsDUnitTest(
         "SingleHopStatsDUnitTest");
-    DistributedSystem ds = test.getSystem(props);
-    cache = CacheFactory.create(ds);
+    DistributedSystem distributedSystem = test.getSystem(props);
+    Cache cache = CacheFactory.create(distributedSystem);
     assertNotNull(cache);
     CacheServerTestUtil.disableShufflingOfEndpoints();
     Pool p;
     try {
-      p = PoolManager.createFactory().addServer("localhost", port0).addServer(
-          "localhost", port1).addServer("localhost", port2)
+      p = PoolManager.createFactory().addServer("localhost", port0)
+          .addServer("localhost", port1).addServer("localhost", port2)
+          .setRetryAttempts(5)
+          .setMinConnections(1)
+          .setMaxConnections(1)
           .setSubscriptionEnabled(false)
           .create(Region_Name);
-    }
-    finally {
+    } finally {
       CacheServerTestUtil.enableShufflingOfEndpoints();
     }
-    createRegionInClientCache(p.getName(), colocation);
+    createRegionInClientCache(p.getName(), colocation, cache);
   }
 
-  public static int createServerForStats(int redundantCopies, int totalNoofBuckets, String
colocation) {
+  private int createServerForStats(int redundantCopies, int totalNoofBuckets, String colocation)
{
     CacheTestCase test = new SingleHopStatsDUnitTest(
         "SingleHopStatsDUnitTest");
-    cache = test.getCache();
+    Cache cache = test.getCache();
     CacheServer server = cache.addCacheServer();
-    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-    server.setPort(port);
+    server.setPort(0);
     server.setHostnameForClients("localhost");
     try {
       server.start();
-    }
-    catch (IOException e) {
+    } catch (IOException e) {
       Assert.fail("Failed to start server ", e);
     }
 
+    Region region = null;
+
     if (colocation.equals("No_Colocation")) {
-      if(totalNoofBuckets == 0){ //DR
+      if (totalNoofBuckets == 0) { //DR
         AttributesFactory attr = new AttributesFactory();
         attr.setScope(Scope.DISTRIBUTED_ACK);
         attr.setDataPolicy(DataPolicy.REPLICATE);
@@ -236,27 +187,27 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
         LogWriterUtils.getLogWriter().info(
             "Distributed Region " + Region_Name + " created Successfully :"
                 + region.toString());
-      }else{
-      PartitionAttributesFactory paf = new PartitionAttributesFactory();
-      paf.setRedundantCopies(redundantCopies).setTotalNumBuckets(
-          totalNoofBuckets);
-      AttributesFactory attr = new AttributesFactory();
-      attr.setPartitionAttributes(paf.create());
-      region = cache.createRegion(Region_Name, attr.create());
-      assertNotNull(region);
-      LogWriterUtils.getLogWriter().info(
-          "Partitioned Region " + Region_Name + " created Successfully :"
-              + region.toString());
+      } else {
+        PartitionAttributesFactory paf = new PartitionAttributesFactory();
+        paf.setRedundantCopies(redundantCopies).setTotalNumBuckets(
+            totalNoofBuckets);
+        AttributesFactory attr = new AttributesFactory();
+        attr.setPartitionAttributes(paf.create());
+        region = cache.createRegion(Region_Name, attr.create());
+        assertNotNull(region);
+        LogWriterUtils.getLogWriter().info(
+            "Partitioned Region " + Region_Name + " created Successfully :"
+                + region.toString());
       }
-    }
-    else {
+    } else {
       PartitionAttributesFactory paf = new PartitionAttributesFactory();
       paf.setRedundantCopies(redundantCopies).setTotalNumBuckets(
           totalNoofBuckets).setPartitionResolver(
-          new CustomerIDPartitionResolver("CustomerIDPartitionResolver"));
+          new CustomerIDPartitionResolver("CustomerIDPartitio"
+              + "nResolver"));
       AttributesFactory attr = new AttributesFactory();
       attr.setPartitionAttributes(paf.create());
-      customerRegion = cache.createRegion("CUSTOMER", attr.create());
+      Region customerRegion = cache.createRegion(CUSTOMER_REGION_NAME, attr.create());
       assertNotNull(customerRegion);
       LogWriterUtils.getLogWriter().info(
           "Partitioned Region CUSTOMER created Successfully :"
@@ -264,11 +215,11 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
 
       paf = new PartitionAttributesFactory();
       paf.setRedundantCopies(redundantCopies).setTotalNumBuckets(
-          totalNoofBuckets).setColocatedWith("CUSTOMER").setPartitionResolver(
+          totalNoofBuckets).setColocatedWith(CUSTOMER_REGION_NAME).setPartitionResolver(
           new CustomerIDPartitionResolver("CustomerIDPartitionResolver"));
       attr = new AttributesFactory();
       attr.setPartitionAttributes(paf.create());
-      orderRegion = cache.createRegion("ORDER", attr.create());
+      Region orderRegion = cache.createRegion(ORDER_REGION_NAME, attr.create());
       assertNotNull(orderRegion);
       LogWriterUtils.getLogWriter().info(
           "Partitioned Region ORDER created Successfully :"
@@ -276,20 +227,21 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
 
       paf = new PartitionAttributesFactory();
       paf.setRedundantCopies(redundantCopies).setTotalNumBuckets(
-          totalNoofBuckets).setColocatedWith("ORDER").setPartitionResolver(
+          totalNoofBuckets).setColocatedWith(ORDER_REGION_NAME).setPartitionResolver(
           new CustomerIDPartitionResolver("CustomerIDPartitionResolver"));
       attr = new AttributesFactory();
       attr.setPartitionAttributes(paf.create());
-      shipmentRegion = cache.createRegion("SHIPMENT", attr.create());
+      Region shipmentRegion = cache.createRegion(SHIPMENT_REGION_NAME, attr.create());
       assertNotNull(shipmentRegion);
       LogWriterUtils.getLogWriter().info(
           "Partitioned Region SHIPMENT created Successfully :"
               + shipmentRegion.toString());
     }
-    return port;
+    return server.getPort();
   }
-  
-  private static void createRegionInClientCache(String poolName, String colocation) {
+
+  private void createRegionInClientCache(String poolName, String colocation, Cache cache)
{
+    Region region = null;
     if (colocation.equals("No_Colocation")) {
       AttributesFactory factory = new AttributesFactory();
       factory.setPoolName(poolName);
@@ -299,12 +251,11 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
       assertNotNull(region);
       LogWriterUtils.getLogWriter().info(
           "Region " + Region_Name + " created Successfully :" + region.toString());
-    }
-    else {
+    } else {
       AttributesFactory factory = new AttributesFactory();
       factory.setPoolName(poolName);
       RegionAttributes attrs = factory.create();
-      customerRegion = cache.createRegion("CUSTOMER", attrs);
+      Region customerRegion = cache.createRegion(CUSTOMER_REGION_NAME, attrs);
       assertNotNull(customerRegion);
       LogWriterUtils.getLogWriter().info(
           "Partitioned Region CUSTOMER created Successfully :"
@@ -313,7 +264,7 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
       factory = new AttributesFactory();
       factory.setPoolName(poolName);
       attrs = factory.create();
-      orderRegion = cache.createRegion("ORDER", attrs);
+      Region orderRegion = cache.createRegion(ORDER_REGION_NAME, attrs);
       assertNotNull(orderRegion);
       LogWriterUtils.getLogWriter().info(
           "Partitioned Region ORDER created Successfully :"
@@ -322,24 +273,27 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
       factory = new AttributesFactory();
       factory.setPoolName(poolName);
       attrs = factory.create();
-      shipmentRegion = cache.createRegion("SHIPMENT", attrs);
+      Region shipmentRegion = cache.createRegion("SHIPMENT", attrs);
       assertNotNull(shipmentRegion);
       LogWriterUtils.getLogWriter().info(
           "Partitioned Region SHIPMENT created Successfully :"
               + shipmentRegion.toString());
     }
   }
-  
-  public static void createPR(String fromClient,
-      String colocation) {
+
+  private void createPR(String fromClient, String colocation) {
+    GemFireCacheImpl cache = (GemFireCacheImpl) CacheFactory.getAnyInstance();
+    Region region = cache.getRegion(Region_Name);
+
+
     if (colocation.equals("No_Colocation")) {
       if (fromClient.equals("FirstClient")) {
-        
+
         System.out.println("first pass...");
         for (int i = 0; i < 113; i++) {
           region.create(new Integer(i), "create" + i);
         }
-        ClientMetadataService cms = ((GemFireCacheImpl)cache)
+        ClientMetadataService cms = ((GemFireCacheImpl) cache)
             .getClientMetadataService();
         final Map<String, ClientPartitionAdvisor> regionMetaData = cms
             .getClientPRMetadata_TEST_ONLY();
@@ -349,124 +303,121 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
         for (int i = 113; i < 226; i++) {
           region.create(new Integer(i), "create" + i);
         }
-        cms = ((GemFireCacheImpl)cache).getClientMetadataService();
+        cms = ((GemFireCacheImpl) cache).getClientMetadataService();
         // since PR metadata is fetched in a background executor thread
         // we need to wait for it to arrive for a bit
-        Wait.waitForCriterion(new WaitCriterion(){
-          public boolean done() {
-            return regionMetaData.size() == 1;
-          }
-          public String description() {
-            return "waiting for metadata to arrive: " + regionMetaData;
-          }
-          
-        }, 30000, 500, true);
+        Awaitility.await().timeout(120, TimeUnit.SECONDS).pollDelay(100, TimeUnit.MILLISECONDS)
+            .pollInterval(500, TimeUnit.MILLISECONDS).until(() -> {
+          return regionMetaData.size() == 1;
+        });
+
         assertTrue(regionMetaData.containsKey(region.getFullPath()));
-        ClientPartitionAdvisor prMetaData = regionMetaData.get(region
-            .getFullPath());
-        metaDataRefreshCount = ((LocalRegion)region).getCachePerfStats().getMetaDataRefreshCount();
-        nonSingleHopsCount = ((LocalRegion)region).getCachePerfStats().getNonSingleHopsCount();
+        regionMetaData.get(region.getFullPath());
+        metaDataRefreshCount = ((LocalRegion) region).getCachePerfStats().getMetaDataRefreshCount();
+        nonSingleHopsCount = ((LocalRegion) region).getCachePerfStats().getNonSingleHopsCount();
         assertTrue(metaDataRefreshCount != 0); // hops are not predictable
         assertTrue(nonSingleHopsCount != 0);
-      }
-      else {
+      } else {
         for (int i = 0; i < 226; i++) {
           region.create(new Integer(i), "create" + i);
         }
-        ClientMetadataService cms = ((GemFireCacheImpl)cache)
+        ClientMetadataService cms = ((GemFireCacheImpl) cache)
             .getClientMetadataService();
         Map<String, ClientPartitionAdvisor> regionMetaData = cms
             .getClientPRMetadata_TEST_ONLY();
         assertEquals(1, regionMetaData.size());
         assertTrue(regionMetaData.containsKey(region.getFullPath()));
-        ClientPartitionAdvisor prMetaData = regionMetaData.get(region
-            .getFullPath());
-        metaDataRefreshCount = ((LocalRegion)region).getCachePerfStats().getMetaDataRefreshCount();
-        nonSingleHopsCount = ((LocalRegion)region).getCachePerfStats().getNonSingleHopsCount();
+
+        regionMetaData.get(region.getFullPath());
+        metaDataRefreshCount = ((LocalRegion) region).getCachePerfStats().getMetaDataRefreshCount();
+        nonSingleHopsCount = ((LocalRegion) region).getCachePerfStats().getNonSingleHopsCount();
         assertTrue(metaDataRefreshCount != 0); // hops are not predictable
         assertTrue(nonSingleHopsCount != 0);
       }
+    } else {
+      createdColocatedPRData(cache);
     }
-    else {
-      for (int i = 0; i <= 20; i++) {
-        CustId custid = new CustId(i);
-        Customer customer = new Customer("name" + i, "Address" + i);
-        customerRegion.put(custid, customer);
-        for (int j = 1; j <= 10; j++) {
-          int oid = (i * 10) + j;
-          OrderId orderId = new OrderId(oid, custid);
-          Order order = new Order("OREDR" + oid);
-          orderRegion.put(orderId, order);
-          for (int k = 1; k <= 10; k++) {
-            int sid = (oid * 10) + k;
-            ShipmentId shipmentId = new ShipmentId(sid, orderId);
-            Shipment shipment = new Shipment("Shipment" + sid);
-            shipmentRegion.put(shipmentId, shipment);
-          }
+  }
+
+  private void createdColocatedPRData(GemFireCacheImpl cache) {
+    Region customerRegion = cache.getRegion(CUSTOMER_REGION_NAME);
+    Region orderRegion = cache.getRegion(ORDER_REGION_NAME);
+    Region shipmentRegion = cache.getRegion(SHIPMENT_REGION_NAME);
+    for (int i = 0; i <= 20; i++) {
+      CustId custid = new CustId(i);
+      Customer customer = new Customer("name" + i, "Address" + i);
+
+      customerRegion.put(custid, customer);
+      for (int j = 1; j <= 10; j++) {
+        int oid = (i * 10) + j;
+        OrderId orderId = new OrderId(oid, custid);
+        Order order = new Order(ORDER_REGION_NAME + oid);
+        orderRegion.put(orderId, order);
+        for (int k = 1; k <= 10; k++) {
+          int sid = (oid * 10) + k;
+          ShipmentId shipmentId = new ShipmentId(sid, orderId);
+          Shipment shipment = new Shipment("Shipment" + sid);
+          shipmentRegion.put(shipmentId, shipment);
         }
       }
-      ClientMetadataService cms = ((GemFireCacheImpl)cache)
-          .getClientMetadataService();
-      Map<String, ClientPartitionAdvisor> regionMetaData = cms
-          .getClientPRMetadata_TEST_ONLY();
-      assertEquals(3, regionMetaData.size());
-      assertTrue(regionMetaData.containsKey(customerRegion.getFullPath()));
-      ClientPartitionAdvisor prMetaData_Customer = regionMetaData
-          .get(customerRegion.getFullPath());
-      metaDataRefreshCount_Customer = ((LocalRegion)customerRegion).getCachePerfStats().getMetaDataRefreshCount();
-      nonSingleHopsCount_Customer = ((LocalRegion)customerRegion).getCachePerfStats().getNonSingleHopsCount();
-      assertTrue(metaDataRefreshCount_Customer != 0); // hops are not predictable
-      assertTrue(nonSingleHopsCount_Customer != 0);
-
-      ClientPartitionAdvisor prMetaData_Order = regionMetaData
-          .get(orderRegion.getFullPath());
-      metaDataRefreshCount_Order = ((LocalRegion)orderRegion).getCachePerfStats().getMetaDataRefreshCount();
-      nonSingleHopsCount_Order = ((LocalRegion)orderRegion).getCachePerfStats().getNonSingleHopsCount();
-      assertTrue(metaDataRefreshCount_Order == 0); 
-      assertTrue(nonSingleHopsCount_Order != 0);
-
-      ClientPartitionAdvisor prMetaData_Shipment = regionMetaData
-          .get(shipmentRegion.getFullPath());
-      metaDataRefreshCount_Shipment = ((LocalRegion)shipmentRegion).getCachePerfStats().getMetaDataRefreshCount();
-      nonSingleHopsCount_Shipment = ((LocalRegion)shipmentRegion).getCachePerfStats().getNonSingleHopsCount();
-      assertTrue(metaDataRefreshCount_Shipment == 0); 
-      assertTrue(nonSingleHopsCount_Shipment != 0);
     }
+    ClientMetadataService cms = cache.getClientMetadataService();
+    Map<String, ClientPartitionAdvisor> regionMetaData = cms
+        .getClientPRMetadata_TEST_ONLY();
+    assertEquals(3, regionMetaData.size());
+    assertTrue(regionMetaData.containsKey(customerRegion.getFullPath()));
+    regionMetaData.get(customerRegion.getFullPath());
+    metaDataRefreshCount_Customer = ((LocalRegion) customerRegion).getCachePerfStats().getMetaDataRefreshCount();
+    nonSingleHopsCount_Customer = ((LocalRegion) customerRegion).getCachePerfStats().getNonSingleHopsCount();
+    assertTrue(metaDataRefreshCount_Customer != 0); // hops are not predictable
+    assertTrue(nonSingleHopsCount_Customer != 0);
+
+    regionMetaData.get(orderRegion.getFullPath());
+    metaDataRefreshCount_Order = ((LocalRegion) orderRegion).getCachePerfStats().getMetaDataRefreshCount();
+    nonSingleHopsCount_Order = ((LocalRegion) orderRegion).getCachePerfStats().getNonSingleHopsCount();
+    assertTrue(metaDataRefreshCount_Order == 0);
+    assertTrue(nonSingleHopsCount_Order != 0);
+
+    regionMetaData.get(shipmentRegion.getFullPath());
+    metaDataRefreshCount_Shipment = ((LocalRegion) shipmentRegion).getCachePerfStats().getMetaDataRefreshCount();
+    nonSingleHopsCount_Shipment = ((LocalRegion) shipmentRegion).getCachePerfStats().getNonSingleHopsCount();
+    assertTrue(metaDataRefreshCount_Shipment == 0);
+    assertTrue(nonSingleHopsCount_Shipment != 0);
   }
-  
-  public static void getPR(String FromClient,
-      String colocation) {
+
+  private void getPR(String FromClient, String colocation) {
+    Cache cache = CacheFactory.getAnyInstance();
+    Region region = cache.getRegion(Region_Name);
+    Region customerRegion = cache.getRegion(CUSTOMER_REGION_NAME);
+    Region orderRegion = cache.getRegion(ORDER_REGION_NAME);
+    Region shipmentRegion = cache.getRegion("SHIPMENT");
     if (colocation.equals("No_Colocation")) {
       if (FromClient.equals("FirstClient")) {
         for (int i = 0; i < 226; i++) {
           region.get(new Integer(i));
         }
-        ClientMetadataService cms = ((GemFireCacheImpl)cache)
+        ClientMetadataService cms = ((GemFireCacheImpl) cache)
             .getClientMetadataService();
         Map<String, ClientPartitionAdvisor> regionMetaData = cms
             .getClientPRMetadata_TEST_ONLY();
         assertEquals(1, regionMetaData.size());
-        ClientPartitionAdvisor prMetaData = regionMetaData.get(region
-            .getFullPath());
-        assertEquals(metaDataRefreshCount , ((LocalRegion)region).getCachePerfStats().getMetaDataRefreshCount());
-        assertEquals(nonSingleHopsCount , ((LocalRegion)region).getCachePerfStats().getNonSingleHopsCount());
-      }
-      else {
+        regionMetaData.get(region.getFullPath());
+        assertEquals(metaDataRefreshCount, ((LocalRegion) region).getCachePerfStats().getMetaDataRefreshCount());
+        assertEquals(nonSingleHopsCount, ((LocalRegion) region).getCachePerfStats().getNonSingleHopsCount());
+      } else {
         for (int i = 0; i < 226; i++) {
           region.get(new Integer(i));
         }
-        ClientMetadataService cms = ((GemFireCacheImpl)cache)
+        ClientMetadataService cms = ((GemFireCacheImpl) cache)
             .getClientMetadataService();
         Map<String, ClientPartitionAdvisor> regionMetaData = cms
             .getClientPRMetadata_TEST_ONLY();
         assertEquals(1, regionMetaData.size());
-        ClientPartitionAdvisor prMetaData = regionMetaData.get(region
-            .getFullPath());
-        assertEquals(metaDataRefreshCount , ((LocalRegion)region).getCachePerfStats().getMetaDataRefreshCount());
-        assertEquals(nonSingleHopsCount , ((LocalRegion)region).getCachePerfStats().getNonSingleHopsCount());
+        regionMetaData.get(region.getFullPath());
+        assertEquals(metaDataRefreshCount, ((LocalRegion) region).getCachePerfStats().getMetaDataRefreshCount());
+        assertEquals(nonSingleHopsCount, ((LocalRegion) region).getCachePerfStats().getNonSingleHopsCount());
       }
-    }
-    else {
+    } else {
       for (int i = 0; i <= 20; i++) {
         CustId custid = new CustId(i);
         customerRegion.get(custid);
@@ -481,45 +432,42 @@ public class SingleHopStatsDUnitTest extends CacheTestCase {
           }
         }
       }
-      ClientMetadataService cms = ((GemFireCacheImpl)cache)
+      ClientMetadataService cms = ((GemFireCacheImpl) cache)
           .getClientMetadataService();
       Map<String, ClientPartitionAdvisor> regionMetaData = cms
           .getClientPRMetadata_TEST_ONLY();
       assertEquals(3, regionMetaData.size());
       assertTrue(regionMetaData.containsKey(customerRegion.getFullPath()));
-      ClientPartitionAdvisor prMetaData_Customer = regionMetaData
-          .get(customerRegion.getFullPath());
-      assertEquals(metaDataRefreshCount_Customer , ((LocalRegion)customerRegion).getCachePerfStats().getMetaDataRefreshCount());
-      assertEquals(nonSingleHopsCount_Customer , ((LocalRegion)customerRegion).getCachePerfStats().getNonSingleHopsCount());
-
-      ClientPartitionAdvisor prMetaData_Order = regionMetaData
-          .get(orderRegion.getFullPath());
-      assertEquals(metaDataRefreshCount_Order , ((LocalRegion)orderRegion).getCachePerfStats().getMetaDataRefreshCount());
-      assertEquals(nonSingleHopsCount_Order , ((LocalRegion)orderRegion).getCachePerfStats().getNonSingleHopsCount());
-
-      ClientPartitionAdvisor prMetaData_Shipment = regionMetaData
-          .get(shipmentRegion.getFullPath());
-      assertEquals(metaDataRefreshCount_Shipment , ((LocalRegion)shipmentRegion).getCachePerfStats().getMetaDataRefreshCount());
-      assertEquals(nonSingleHopsCount_Shipment , ((LocalRegion)shipmentRegion).getCachePerfStats().getNonSingleHopsCount());
+      regionMetaData.get(customerRegion.getFullPath());
+      assertEquals(metaDataRefreshCount_Customer, ((LocalRegion) customerRegion).getCachePerfStats().getMetaDataRefreshCount());
+      assertEquals(nonSingleHopsCount_Customer, ((LocalRegion) customerRegion).getCachePerfStats().getNonSingleHopsCount());
+
+      regionMetaData.get(orderRegion.getFullPath());
+      assertEquals(metaDataRefreshCount_Order, ((LocalRegion) orderRegion).getCachePerfStats().getMetaDataRefreshCount());
+      assertEquals(nonSingleHopsCount_Order, ((LocalRegion) orderRegion).getCachePerfStats().getNonSingleHopsCount());
+
+      regionMetaData.get(shipmentRegion.getFullPath());
+      assertEquals(metaDataRefreshCount_Shipment, ((LocalRegion) shipmentRegion).getCachePerfStats().getMetaDataRefreshCount());
+      assertEquals(nonSingleHopsCount_Shipment, ((LocalRegion) shipmentRegion).getCachePerfStats().getNonSingleHopsCount());
     }
   }
-  
-  public static void updatePR(String FromClient,
-      String colocation) {
+
+  private void updatePR(String FromClient, String colocation) {
+    Cache cache = CacheFactory.getAnyInstance();
+    Region region = cache.getRegion(Region_Name);
     if (colocation.equals("No_Colocation")) {
       if (FromClient.equals("FirstClient")) {
         for (int i = 0; i < 226; i++) {
           region.put(new Integer(i), "Update" + i);
         }
-        ClientMetadataService cms = ((GemFireCacheImpl)cache)
+        ClientMetadataService cms = ((GemFireCacheImpl) cache)
             .getClientMetadataService();
         Map<String, ClientPartitionAdvisor> regionMetaData = cms
             .getClientPRMetadata_TEST_ONLY();
         assertEquals(1, regionMetaData.size());
-        ClientPartitionAdvisor prMetaData = regionMetaData.get(region
-            .getFullPath());
-        assertEquals(metaDataRefreshCount , ((LocalRegion)region).getCachePerfStats().getMetaDataRefreshCount());
-        assertEquals(nonSingleHopsCount , ((LocalRegion)region).getCachePerfStats().getNonSingleHopsCount());
+        regionMetaData.get(region.getFullPath());
+        assertEquals(metaDataRefreshCount, ((LocalRegion) region).getCachePerfStats().getMetaDataRefreshCount());
+        assertEquals(nonSingleHopsCount, ((LocalRegion) region).getCachePerfStats().getNonSingleHopsCount());
       }
     }
   }


Mime
View raw message