You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by up...@apache.org on 2016/05/23 22:01:11 UTC

[09/11] incubator-geode git commit: GEODE-1367: More test fixes

GEODE-1367: More test fixes


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

Branch: refs/heads/feature/GEODE-837
Commit: 19d430dc0afad85f44818cf46688fdccb41051c2
Parents: 8bc3481
Author: Udo Kohlmeyer <uk...@pivotal.io>
Authored: Tue May 17 09:12:41 2016 +1000
Committer: Udo Kohlmeyer <uk...@pivotal.io>
Committed: Tue May 24 03:37:40 2016 +1000

----------------------------------------------------------------------
 .../RestAPIsAndInterOpsDUnitTest.java           | 118 +++++++++++-------
 .../internal/AutoConnectionSourceDUnitTest.java |   5 +-
 .../cache/client/internal/LocatorTestBase.java  | 123 +++++++++++++++----
 3 files changed, 181 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/19d430dc/geode-assembly/src/test/java/com/gemstone/gemfire/rest/internal/web/controllers/RestAPIsAndInterOpsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/com/gemstone/gemfire/rest/internal/web/controllers/RestAPIsAndInterOpsDUnitTest.java b/geode-assembly/src/test/java/com/gemstone/gemfire/rest/internal/web/controllers/RestAPIsAndInterOpsDUnitTest.java
index dd0a99c..3717074 100644
--- a/geode-assembly/src/test/java/com/gemstone/gemfire/rest/internal/web/controllers/RestAPIsAndInterOpsDUnitTest.java
+++ b/geode-assembly/src/test/java/com/gemstone/gemfire/rest/internal/web/controllers/RestAPIsAndInterOpsDUnitTest.java
@@ -162,17 +162,53 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
     disconnectAllFromDS();
   }
 
-  public String startBridgeServerWithRestService(final String hostName, final String[] groups, final String locators
-      , final String[] regions, final ServerLoadProbe probe)
-      throws IOException {
+  public String startBridgeServerWithRestService(final String hostName, final String[] groups, final String locators, final String[] regions,
+      final ServerLoadProbe probe) {
+    final int serverPort = AvailablePortHelper.getRandomAvailableTCPPort();
 
     //create Cache of given VM and start HTTP service with REST APIs service
-    int serverPort = startBridgeServer(groups, locators, regions, probe);
+    startBridgeServer(hostName, serverPort, groups, locators, regions, probe);
 
     String restEndPoint = "http://" + hostName + ":" + serverPort + "/gemfire-api/v1";
     return restEndPoint;
   }
 
+  @SuppressWarnings("deprecation")
+  protected int startBridgeServer(String hostName, int restServicerPort, final String[] groups, final String locators, final String[] regions,
+      final ServerLoadProbe probe) {
+
+    Properties props = new Properties();
+    props.setProperty(DistributionConfig.MCAST_PORT_NAME, String.valueOf(0));
+    props.setProperty(DistributionConfig.LOCATORS_NAME, locators);
+    props.setProperty(DistributionConfig.START_DEV_REST_API_NAME, "true");
+    props.setProperty(DistributionConfig.HTTP_SERVICE_BIND_ADDRESS_NAME, hostName);
+    props.setProperty(DistributionConfig.HTTP_SERVICE_PORT_NAME, String.valueOf(restServicerPort));
+
+    DistributedSystem ds = getSystem(props);
+    Cache cache = CacheFactory.create(ds);
+    ((GemFireCacheImpl) cache).setReadSerialized(true);
+    AttributesFactory factory = new AttributesFactory();
+
+    factory.setEnableBridgeConflation(true);
+    factory.setDataPolicy(DataPolicy.REPLICATE);
+    RegionAttributes attrs = factory.create();
+    for (int i = 0; i < regions.length; i++) {
+      cache.createRegion(regions[i], attrs);
+    }
+
+    CacheServer server = cache.addCacheServer();
+    server.setPort(0);
+    server.setGroups(groups);
+    server.setLoadProbe(probe);
+    try {
+      server.start();
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+    remoteObjects.put(CACHE_KEY, cache);
+    return new Integer(server.getPort());
+  }
+
   public void doPutsInClientCache() {
     ClientCache cache = GemFireCacheImpl.getInstance();
     assertNotNull(cache);
@@ -318,7 +354,12 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
       if (value instanceof PdxInstance) {
         PdxInstance pi3 = (PdxInstance) value;
         Person actualPerson = (Person) pi3.getObject();
-        comparePersonObject(expectedPerson, actualPerson);
+        assertEquals(actualPerson.getId(), expectedPerson.getId());
+        assertEquals(actualPerson.getFirstName(), expectedPerson.getFirstName());
+        assertEquals(actualPerson.getMiddleName(), expectedPerson.getMiddleName());
+        assertEquals(actualPerson.getLastName(), expectedPerson.getLastName());
+        assertEquals(actualPerson.getBirthDate(), expectedPerson.getBirthDate());
+        assertEquals(actualPerson.getGender(), expectedPerson.getGender());
       } else if (value instanceof Person) {
         fail("VerifyUpdatesInClientCache, Get on key 3, Expected to get value of type PdxInstance ");
       }
@@ -350,7 +391,12 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
       if (value instanceof PdxInstance) {
         PdxInstance pi3 = (PdxInstance) value;
         Person actualPerson = (Person) pi3.getObject();
-        comparePersonObject(expectedPerson, actualPerson);
+        assertEquals(actualPerson.getId(), expectedPerson.getId());
+        assertEquals(actualPerson.getFirstName(), expectedPerson.getFirstName());
+        assertEquals(actualPerson.getMiddleName(), expectedPerson.getMiddleName());
+        assertEquals(actualPerson.getLastName(), expectedPerson.getLastName());
+        assertEquals(actualPerson.getBirthDate(), expectedPerson.getBirthDate());
+        assertEquals(actualPerson.getGender(), expectedPerson.getGender());
       } else {
         fail("VerifyUpdatesInClientCache, Get on key 2, Expected to get value of type PdxInstance ");
       }
@@ -373,15 +419,6 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
 
   }
 
-  private void comparePersonObject(Person expectedPerson, Person actualPerson) {
-    assertEquals(actualPerson.getId(), expectedPerson.getId());
-    assertEquals(actualPerson.getFirstName(), expectedPerson.getFirstName());
-    assertEquals(actualPerson.getMiddleName(), expectedPerson.getMiddleName());
-    assertEquals(actualPerson.getLastName(), expectedPerson.getLastName());
-    assertEquals(actualPerson.getBirthDate(), expectedPerson.getBirthDate());
-    assertEquals(actualPerson.getGender(), expectedPerson.getGender());
-  }
-
   public void doUpdatesUsingRestApis(String restEndpoint) {
     //UPdate keys using REST calls
     {
@@ -702,16 +739,17 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
     assertNotNull(cache);
     ClientRegionFactory<String, Object> crf = cache
         .createClientRegionFactory(ClientRegionShortcut.PROXY);
-    crf.create(PEOPLE_REGION_NAME);
+    Region<String, Object> region = crf.create(PEOPLE_REGION_NAME);
+
   }
 
   public void createRegion() {
     Cache cache = GemFireCacheImpl.getInstance();
     assertNotNull(cache);
 
-    RegionFactory<String, Object> regionFactory = cache
+    RegionFactory<String, Object> rf = cache
         .createRegionFactory(RegionShortcut.REPLICATE);
-    regionFactory.create(PEOPLE_REGION_NAME);
+    Region<String, Object> region = rf.create(PEOPLE_REGION_NAME);
   }
 
   /**
@@ -730,35 +768,30 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
 
     // start locator
     int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-
-    String locatorHostName = NetworkUtils.getServerHostName(locator.getHost());
-    locator.invoke("Start Locator", () -> startLocator(locatorHostName, locatorPort, ""));
+    final String locatorHostName = NetworkUtils.getServerHostName(locator.getHost());
+    locator.invoke(() -> startLocator(locatorHostName, locatorPort, ""));
 
     // find locators
     String locators = locatorHostName + "[" + locatorPort + "]";
 
     // start manager (peer cache)
-    manager.invoke("Start manager", () -> startManager(null, locators,
-        new String[] { REGION_NAME }, CacheServer.DEFAULT_LOAD_PROBE));
+    manager.invoke(() -> startManager(/* groups */null, locators, new String[] { REGION_NAME }, CacheServer.DEFAULT_LOAD_PROBE));
 
     //start startCacheServer With RestService enabled
-    String restEndpoint = server.invoke("startBridgeServer with Rest Service", () -> {
-      final String hostName = NetworkUtils.getServerHostName(server.getHost());
-      final int restServicePort = AvailablePortHelper.getRandomAvailableTCPPort();
-      startBridgeServer(hostName, restServicePort, null, locators, new String[] { REGION_NAME }, null);
-      return "https://" + hostName + ":" + restServicePort + "/gemfire-api/v1";
-    });
+    final String serverHostName = server.getHost().getHostName();
+    String restEndpoint = (String) server.invoke(() -> startBridgeServerWithRestService(serverHostName, null, locators
+        , new String[] { REGION_NAME }, CacheServer.DEFAULT_LOAD_PROBE));
 
     // create a client cache
-    client.invoke("Create Client", () -> createClientCache(NetworkUtils.getServerHostName(locator.getHost()), locatorPort));
+    client.invoke(() -> createClientCache(locatorHostName, locatorPort));
 
     // create region in Manager, peer cache and Client cache nodes
-    manager.invoke("create region", () -> createRegion());
-    server.invoke("create region", () -> createRegion());
-    client.invoke("create region", () -> createRegionInClientCache());
+    manager.invoke(() -> createRegion());
+    server.invoke(() -> createRegion());
+    client.invoke(() -> createRegionInClientCache());
 
     // do some person puts from clientcache
-    client.invoke("doPutsInClientCache", () -> doPutsInClientCache());
+    client.invoke(() -> doPutsInClientCache());
 
     //TEST: fetch all available REST endpoints
     fetchRestServerEndpoints(restEndpoint);
@@ -769,7 +802,7 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
     //update Data using REST APIs
     doUpdatesUsingRestApis(restEndpoint);
 
-    client.invoke("verifyUpdatesInClientCache", () -> verifyUpdatesInClientCache());
+    client.invoke(() -> verifyUpdatesInClientCache());
 
     //Querying
     doQueryOpsUsingRestApis(restEndpoint);
@@ -785,14 +818,18 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
 
   private void createClientCache(final String host, final int port) throws Exception {
     // Connect using the GemFire locator and create a Caching_Proxy cache
-    ClientCache cache = new ClientCacheFactory().setPdxReadSerialized(true).addPoolLocator(host, port).create();
-    cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
+    ClientCache c = new ClientCacheFactory().setPdxReadSerialized(true).addPoolLocator(host, port)
+        .create();
+
+    c.createClientRegionFactory(
+        ClientRegionShortcut.PROXY).create(REGION_NAME);
   }
 
-  private int startManager(final String[] groups,
-      final String locators, final String[] regions, final ServerLoadProbe probe) throws IOException {
+  private int startManager(final String[] groups, final String locators, final String[] regions
+      , final ServerLoadProbe probe) throws IOException {
     Properties props = new Properties();
-    props.setProperty(DistributionConfig.MCAST_PORT_NAME, String.valueOf(0));
+    props
+        .setProperty(DistributionConfig.MCAST_PORT_NAME, String.valueOf(0));
     props.setProperty(DistributionConfig.LOCATORS_NAME, locators);
 
     props.setProperty("jmx-manager", "true");
@@ -811,7 +848,6 @@ public class RestAPIsAndInterOpsDUnitTest extends LocatorTestBase {
 
     factory.setEnableBridgeConflation(true);
     factory.setDataPolicy(DataPolicy.REPLICATE);
-    factory.setScope(Scope.DISTRIBUTED_ACK);
     RegionAttributes attrs = factory.create();
     for (int i = 0; i < regions.length; i++) {
       cache.createRegion(regions[i], attrs);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/19d430dc/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/AutoConnectionSourceDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/AutoConnectionSourceDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/AutoConnectionSourceDUnitTest.java
index 0488e23..fddf108 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/AutoConnectionSourceDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/AutoConnectionSourceDUnitTest.java
@@ -317,7 +317,10 @@ public class AutoConnectionSourceDUnitTest extends LocatorTestBase {
 
     //start a bridge client with a listener
     addBridgeListener(clientVM);
-    clientVM.invoke("StartBridgeClient", () -> startBridgeClient(null, NetworkUtils.getServerHostName(locatorVM.getHost()), locatorPort));
+    clientVM.invoke("StartBridgeClient", () -> {
+      String locatorHostName = NetworkUtils.getServerHostName(locatorVM.getHost());
+      startBridgeClient(null, locatorHostName, locatorPort);
+    });
     // wait for client to connect
     checkEndpoints(clientVM, new int[] { serverPort1 });
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/19d430dc/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/LocatorTestBase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/LocatorTestBase.java b/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/LocatorTestBase.java
index 98e8835..54c819e 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/LocatorTestBase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/LocatorTestBase.java
@@ -91,31 +91,52 @@ public abstract class LocatorTestBase extends DistributedTestCase {
   }
 
   protected void startLocator(final String hostName, final int locatorPort, final String otherLocators) {
+    final String testName = getUniqueName();
     disconnectFromDS();
     Properties props = new Properties();
     props.setProperty(DistributionConfig.MCAST_PORT_NAME, String.valueOf(0));
     props.setProperty(DistributionConfig.LOCATORS_NAME, otherLocators);
     props.setProperty(DistributionConfig.LOG_LEVEL_NAME, LogWriterUtils.getDUnitLogLevel());
     props.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "false");
-    File logFile = new File(getUniqueName() + "-locator" + locatorPort + ".log");
     try {
-      InetAddress bindAddress = InetAddress.getByName(hostName);
-      Locator locator = Locator.startLocatorAndDS(locatorPort, logFile, bindAddress, props);
+      File logFile = new File(testName + "-locator" + locatorPort + ".log");
+      InetAddress bindAddr = null;
+      try {
+        bindAddr = InetAddress.getByName(hostName);
+      } catch (UnknownHostException uhe) {
+        Assert.fail("While resolving bind address ", uhe);
+      }
+      Locator locator = Locator.startLocatorAndDS(locatorPort, logFile, bindAddr, props);
       remoteObjects.put(LOCATOR_KEY, locator);
-    } catch (UnknownHostException uhe) {
-      Assert.fail("While resolving bind address ", uhe);
     } catch (IOException ex) {
       Assert.fail("While starting locator on port " + locatorPort, ex);
     }
   }
 
+  protected void startLocatorInVM(final VM vm, final int locatorPort, final String otherLocators) {
+    vm.invoke(new SerializableRunnable("Create Locator") {
+      public void run() {
+        String hostName = NetworkUtils.getServerHostName(vm.getHost());
+        startLocator(hostName, locatorPort, otherLocators);
+      }
+    });
+  }
+
+  protected void stopLocatorInVM(VM vm) {
+    vm.invoke(new SerializableRunnable("Stop Locator") {
+      public void run() {
+        stopLocator();
+      }
+    });
+  }
+
   protected void stopLocator() {
     Locator locator = (Locator) remoteObjects.remove(LOCATOR_KEY);
     locator.stop();
   }
 
-  protected int startBridgeServer(String[] groups, String locators) throws IOException {
-    return startBridgeServer(groups, locators, new String[] { REGION_NAME });
+  protected int startBridgeServerInVM(VM vm, String[] groups, String locators) {
+    return startBridgeServerInVM(vm, groups, locators, new String[] { REGION_NAME });
   }
 
   protected int addCacheServer(final String[] groups) throws IOException {
@@ -127,42 +148,59 @@ public abstract class LocatorTestBase extends DistributedTestCase {
     return new Integer(server.getPort());
   }
 
+  protected int addCacheServerInVM(VM vm, final String[] groups) {
+    SerializableCallable connect =
+        new SerializableCallable("Add Bridge server") {
+          public Object call() throws Exception {
+            return addCacheServer(groups);
+          }
+        };
+    Integer port = (Integer) vm.invoke(connect);
+    return port.intValue();
+  }
+
+  protected int startBridgeServerInVM(VM vm, final String[] groups, final String locators, final String[] regions) {
+    return startBridgeServerInVM(vm, groups, locators, regions, CacheServer.DEFAULT_LOAD_PROBE);
+  }
+
+  protected int startBridgeServerInVM(VM vm, final String[] groups, final String locators, final String[] regions, final ServerLoadProbe probe) {
+    SerializableCallable connect =
+        new SerializableCallable("Start bridge server") {
+          public Object call() throws IOException {
+            return startBridgeServer(groups, locators, regions, probe);
+          }
+        };
+    Integer port = (Integer) vm.invoke(connect);
+    return port.intValue();
+  }
+
+  protected int startBridgeServer(String[] groups, String locators) throws IOException {
+    return startBridgeServer(groups, locators, new String[] { REGION_NAME });
+  }
+
   protected int startBridgeServer(final String[] groups, final String locators, final String[] regions) throws IOException {
     return startBridgeServer(groups, locators, regions, CacheServer.DEFAULT_LOAD_PROBE);
   }
 
   protected int startBridgeServer(final String[] groups, final String locators, final String[] regions, final ServerLoadProbe probe)
       throws IOException {
-    return startBridgeServer(null, -1, groups, locators, regions, probe);
-  }
-
-  protected int startBridgeServer(final String hostName, final int restServicePort, final String[] groups
-      , final String locators, final String[] regions, final ServerLoadProbe probe) throws IOException {
     Properties props = new Properties();
     props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
     props.setProperty(DistributionConfig.LOCATORS_NAME, locators);
-    if (hostName != null) {
-      props.setProperty(DistributionConfig.START_DEV_REST_API_NAME, "true");
-      props.setProperty(DistributionConfig.HTTP_SERVICE_BIND_ADDRESS_NAME, hostName);
-      props.setProperty(DistributionConfig.HTTP_SERVICE_PORT_NAME, String.valueOf(restServicePort));
-    }
-
     DistributedSystem ds = getSystem(props);
     Cache cache = CacheFactory.create(ds);
     AttributesFactory factory = new AttributesFactory();
     factory.setScope(Scope.DISTRIBUTED_ACK);
     factory.setEnableBridgeConflation(true);
     factory.setDataPolicy(DataPolicy.REPLICATE);
-    RegionAttributes attributes = factory.create();
+    RegionAttributes attrs = factory.create();
     for (int i = 0; i < regions.length; i++) {
-      cache.createRegion(regions[i], attributes);
+      cache.createRegion(regions[i], attrs);
     }
     CacheServer server = cache.addCacheServer();
     server.setPort(0);
     server.setGroups(groups);
-    if (probe != null) {
-      server.setLoadProbe(probe);
-    }
+    server.setLoadProbe(probe);
     server.start();
 
     remoteObjects.put(CACHE_KEY, cache);
@@ -197,6 +235,45 @@ public abstract class LocatorTestBase extends DistributedTestCase {
     return new Integer(server.getPort());
   }
 
+  protected int startBridgeServerWithEmbeddedLocatorInVM(VM vm, final String[] groups, final String locators, final String[] regions,
+      final ServerLoadProbe probe) {
+    SerializableCallable connect =
+        new SerializableCallable("Start bridge server") {
+          public Object call() throws IOException {
+            return startBridgeServerWithEmbeddedLocator(groups, locators, regions, probe);
+          }
+        };
+    Integer port = (Integer) vm.invoke(connect);
+    return port.intValue();
+  }
+
+  protected void startBridgeClientInVM(VM vm, final String group, final String host, final int port) throws Exception {
+    startBridgeClientInVM(vm, group, host, port, new String[] { REGION_NAME });
+  }
+
+  protected void startBridgeClientInVM(VM vm, final String group, final String host, final int port, final String[] regions) throws Exception {
+    PoolFactoryImpl pf = new PoolFactoryImpl(null);
+    pf.addLocator(host, port)
+        .setServerGroup(group)
+        .setPingInterval(200)
+        .setSubscriptionEnabled(true)
+        .setSubscriptionRedundancy(-1);
+    startBridgeClientInVM(vm, pf.getPoolAttributes(), regions);
+  }
+
+  protected void startBridgeClientInVM(VM vm, final Pool pool, final String[] regions) throws Exception {
+    SerializableRunnable connect = new SerializableRunnable("Start bridge client") {
+      public void run() throws Exception {
+        startBridgeClient(pool, regions);
+      }
+    };
+    if (vm == null) {
+      connect.run();
+    } else {
+      vm.invoke(connect);
+    }
+  }
+
   protected void startBridgeClient(final String group, final String host, final int port) throws Exception {
     startBridgeClient(group, host, port, new String[] { REGION_NAME });
   }