geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject [053/100] [abbrv] incubator-geode git commit: GEODE-929: Do not use AvailablePort.getRandomAvailablePort in this test to avoid intermittent PortNotAvailable error.
Date Mon, 22 Feb 2016 21:43:41 GMT
GEODE-929: Do not use AvailablePort.getRandomAvailablePort in this test to avoid intermittent
PortNotAvailable error.


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

Branch: refs/heads/feature/GEODE-870
Commit: 53b6319e4b2c0c08d7c592b797f728f2a3ba0f50
Parents: 53510e5
Author: Jinmei Liao <jiliao@pivotal.io>
Authored: Fri Feb 19 08:48:42 2016 -0800
Committer: Jinmei Liao <jiliao@pivotal.io>
Committed: Fri Feb 19 13:13:52 2016 -0800

----------------------------------------------------------------------
 .../security/ClientMultiUserAuthzDUnitTest.java | 288 +++++++++----------
 .../gemfire/security/SecurityTestUtil.java      |   2 +-
 2 files changed, 144 insertions(+), 146 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/53b6319e/gemfire-core/src/test/java/com/gemstone/gemfire/security/ClientMultiUserAuthzDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/security/ClientMultiUserAuthzDUnitTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/security/ClientMultiUserAuthzDUnitTest.java
index 74260ed..dc03990 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/security/ClientMultiUserAuthzDUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/security/ClientMultiUserAuthzDUnitTest.java
@@ -24,6 +24,7 @@ package com.gemstone.gemfire.security;
 import java.util.Iterator;
 import java.util.Properties;
 
+import com.gemstone.gemfire.test.dunit.VM;
 import security.AuthzCredentialGenerator;
 import security.CredentialGenerator;
 
@@ -81,37 +82,37 @@ public class ClientMultiUserAuthzDUnitTest extends ClientAuthorizationTestBase
{
       // Start servers with all required properties
       Properties serverProps = buildProperties(authenticator, accessor, false,
           extraAuthProps, extraAuthzProps);
-      Integer port1 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-      Integer port2 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-      createCacheServers(javaProps, serverProps, port1, port2);
+
+      Integer port1 = createCacheServerOnVM(server1, javaProps, serverProps);
+      Integer port2 = createCacheServerOnVM(server2, javaProps, serverProps);
 
       if (!prepareClientsForOps(gen, cGen, new OperationCode[] {
-          OperationCode.PUT, OperationCode.PUT}, new OperationCode[] {
-          OperationCode.GET, OperationCode.GET}, javaProps, authInit, port1,
+              OperationCode.PUT, OperationCode.PUT}, new OperationCode[] {
+              OperationCode.GET, OperationCode.GET}, javaProps, authInit, port1,
           port2)) {
         continue;
       }
       verifyPutsGets();
 
       if (!prepareClientsForOps(gen, cGen, new OperationCode[] {
-          OperationCode.PUT, OperationCode.CONTAINS_KEY}, new OperationCode[] {
-          OperationCode.DESTROY, OperationCode.DESTROY},
+              OperationCode.PUT, OperationCode.CONTAINS_KEY}, new OperationCode[] {
+              OperationCode.DESTROY, OperationCode.DESTROY},
           javaProps, authInit, port1, port2)) {
         continue;
       }
       verifyContainsKeyDestroys();
 
       if (!prepareClientsForOps(gen, cGen, new OperationCode[] {
-          OperationCode.PUT, OperationCode.CONTAINS_KEY}, new OperationCode[] {
-          OperationCode.INVALIDATE, OperationCode.INVALIDATE},
+              OperationCode.PUT, OperationCode.CONTAINS_KEY}, new OperationCode[] {
+              OperationCode.INVALIDATE, OperationCode.INVALIDATE},
           javaProps, authInit, port1, port2)) {
         continue;
       }
       verifyContainsKeyInvalidates();
 
       if (!prepareClientsForOps(gen, cGen, new OperationCode[] {
-          OperationCode.GET, OperationCode.GET}, new OperationCode[] {
-          OperationCode.REGION_DESTROY, OperationCode.REGION_DESTROY},
+              OperationCode.GET, OperationCode.GET}, new OperationCode[] {
+              OperationCode.REGION_DESTROY, OperationCode.REGION_DESTROY},
           javaProps, authInit, port1, port2)) {
         continue;
       }
@@ -219,11 +220,11 @@ public class ClientMultiUserAuthzDUnitTest extends ClientAuthorizationTestBase
{
 
     // Verify that the gets succeed/fail
     if (isMultiuser) {
-    client2.invoke(SecurityTestUtil.class, "doMultiUserGets", new Object[] {
-        Integer.valueOf(2),
-        Integer.valueOf(2),
-        new Integer[] {SecurityTestUtil.NO_EXCEPTION,
-            SecurityTestUtil.NOTAUTHZ_EXCEPTION}});
+      client2.invoke(SecurityTestUtil.class, "doMultiUserGets", new Object[] {
+          Integer.valueOf(2),
+          Integer.valueOf(2),
+          new Integer[] {SecurityTestUtil.NO_EXCEPTION,
+              SecurityTestUtil.NOTAUTHZ_EXCEPTION}});
     } else {
       int expectedResult = (opAllowed) ? SecurityTestUtil.NO_EXCEPTION
           : SecurityTestUtil.NOTAUTHZ_EXCEPTION;
@@ -310,17 +311,17 @@ public class ClientMultiUserAuthzDUnitTest extends ClientAuthorizationTestBase
{
   private void verifyGetAllInTX() {
     server1.invoke(() -> ClientMultiUserAuthzDUnitTest.doPuts());
     client1.invoke(SecurityTestUtil.class, "doMultiUserGetAll", new Object[] {
-      Integer.valueOf(2),
-      new Integer[] {SecurityTestUtil.NO_EXCEPTION,
-          SecurityTestUtil.NOTAUTHZ_EXCEPTION}, Boolean.TRUE/*use TX*/});
+        Integer.valueOf(2),
+        new Integer[] {SecurityTestUtil.NO_EXCEPTION,
+            SecurityTestUtil.NOTAUTHZ_EXCEPTION}, Boolean.TRUE/*use TX*/});
   }
 
   private void verifyGetAllRegionDestroys() {
     server1.invoke(() -> ClientMultiUserAuthzDUnitTest.doPuts());
     client1.invoke(SecurityTestUtil.class, "doMultiUserGetAll", new Object[] {
-      Integer.valueOf(2),
-      new Integer[] {SecurityTestUtil.NO_EXCEPTION,
-          SecurityTestUtil.NOTAUTHZ_EXCEPTION}});
+        Integer.valueOf(2),
+        new Integer[] {SecurityTestUtil.NO_EXCEPTION,
+            SecurityTestUtil.NOTAUTHZ_EXCEPTION}});
 
     // Verify that the region destroys succeed/fail
     client2.invoke(SecurityTestUtil.class, "doMultiUserRegionDestroys",
@@ -329,7 +330,7 @@ public class ClientMultiUserAuthzDUnitTest extends ClientAuthorizationTestBase
{
             new Integer[] {SecurityTestUtil.NO_EXCEPTION,
                 SecurityTestUtil.NOTAUTHZ_EXCEPTION}});
   }
-  
+
   public static void doPuts() {
     Region region = GemFireCacheImpl.getInstance().getRegion(SecurityTestUtil.regionName);
     region.put("key1", "value1");
@@ -338,134 +339,132 @@ public class ClientMultiUserAuthzDUnitTest extends ClientAuthorizationTestBase
{
 
   // Test query/function execute
   public void testOps2() throws Exception {
-      AuthzCredentialGenerator gen = getXmlAuthzGenerator();
-      CredentialGenerator cGen = gen.getCredentialGenerator();
-      Properties extraAuthProps = cGen.getSystemProperties();
-      Properties javaProps = cGen.getJavaProperties();
-      Properties extraAuthzProps = gen.getSystemProperties();
-      String authenticator = cGen.getAuthenticator();
-      String authInit = cGen.getAuthInit();
-      String accessor = gen.getAuthorizationCallback();
+    AuthzCredentialGenerator gen = getXmlAuthzGenerator();
+    CredentialGenerator cGen = gen.getCredentialGenerator();
+    Properties extraAuthProps = cGen.getSystemProperties();
+    Properties javaProps = cGen.getJavaProperties();
+    Properties extraAuthzProps = gen.getSystemProperties();
+    String authenticator = cGen.getAuthenticator();
+    String authInit = cGen.getAuthInit();
+    String accessor = gen.getAuthorizationCallback();
+
+    LogWriterUtils.getLogWriter().info("testOps2: Using authinit: " + authInit);
+    LogWriterUtils.getLogWriter().info("testOps2: Using authenticator: " + authenticator);
+    LogWriterUtils.getLogWriter().info("testOps2: Using accessor: " + accessor);
+
+    // Start servers with all required properties
+    Properties serverProps = buildProperties(authenticator, accessor, false,
+        extraAuthProps, extraAuthzProps);
+    Integer port1 = createCacheServerOnVM(server1, javaProps, serverProps);
+    Integer port2 = createCacheServerOnVM(server2, javaProps, serverProps);
+
+    // Start client1 with valid/invalid QUERY credentials
+    Properties[] client1Credentials = new Properties[] {
+        gen.getAllowedCredentials(
+            new OperationCode[] {OperationCode.PUT, OperationCode.QUERY},
+            new String[] {regionName},
+            1),
+        gen.getDisallowedCredentials(
+            new OperationCode[] {OperationCode.PUT, OperationCode.QUERY},
+            new String[] {regionName},
+            1)
+    };
 
-      LogWriterUtils.getLogWriter().info("testOps2: Using authinit: " + authInit);
-      LogWriterUtils.getLogWriter().info("testOps2: Using authenticator: " + authenticator);
-      LogWriterUtils.getLogWriter().info("testOps2: Using accessor: " + accessor);
+    javaProps = cGen.getJavaProperties();
+    LogWriterUtils.getLogWriter().info(
+        "testOps2: For first client credentials: " + client1Credentials[0]
+            + "\n" + client1Credentials[1]);
+    client1.invoke(SecurityTestUtil.class,
+        "createCacheClientForMultiUserMode", new Object[] {
+            Integer.valueOf(2), authInit, client1Credentials, javaProps,
+            new Integer[] {port1, port2}, null, Boolean.FALSE,
+            SecurityTestUtil.NO_EXCEPTION});
 
-      // Start servers with all required properties
-      Properties serverProps = buildProperties(authenticator, accessor, false,
-          extraAuthProps, extraAuthzProps);
-      Integer port1 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-      Integer port2 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-      createCacheServers(javaProps, serverProps, port1, port2);
-
-      // Start client1 with valid/invalid QUERY credentials
-      Properties[] client1Credentials = new Properties[] {
-          gen.getAllowedCredentials(
-                  new OperationCode[] {OperationCode.PUT, OperationCode.QUERY},
-                  new String[] {regionName},
-                  1),
-          gen.getDisallowedCredentials(
-                  new OperationCode[] {OperationCode.PUT, OperationCode.QUERY},
-                  new String[] {regionName},
-                  1)
-      };
-
-      javaProps = cGen.getJavaProperties();
-      LogWriterUtils.getLogWriter().info(
-          "testOps2: For first client credentials: " + client1Credentials[0]
-              + "\n" + client1Credentials[1]);
-      client1.invoke(SecurityTestUtil.class,
-          "createCacheClientForMultiUserMode", new Object[] {
-              Integer.valueOf(2), authInit, client1Credentials, javaProps,
-              new Integer[] {port1, port2}, null, Boolean.FALSE,
-              SecurityTestUtil.NO_EXCEPTION});
+    // Start client2 with valid/invalid EXECUTE_FUNCTION credentials
+    Properties[] client2Credentials = new Properties[] {
+        gen.getAllowedCredentials(new OperationCode[] {OperationCode.EXECUTE_FUNCTION},
+            new String[] {regionName}, 2),
+        gen.getDisallowedCredentials(new OperationCode[] {OperationCode.EXECUTE_FUNCTION},
+            new String[] {regionName}, 9)};
 
-      // Start client2 with valid/invalid EXECUTE_FUNCTION credentials
-      Properties[] client2Credentials = new Properties[] {
-          gen.getAllowedCredentials(new OperationCode[] {OperationCode.EXECUTE_FUNCTION},
-              new String[] {regionName}, 2),
-          gen.getDisallowedCredentials(new OperationCode[] {OperationCode.EXECUTE_FUNCTION},
-              new String[] {regionName}, 9)};
+    javaProps = cGen.getJavaProperties();
+    LogWriterUtils.getLogWriter().info(
+        "testOps2: For second client credentials: " + client2Credentials[0]
+            + "\n" + client2Credentials[1]);
+    client2.invoke(SecurityTestUtil.class,
+        "createCacheClientForMultiUserMode", new Object[] {
+            Integer.valueOf(2), authInit, client2Credentials, javaProps,
+            new Integer[] {port1, port2}, null, Boolean.FALSE,
+            SecurityTestUtil.NO_EXCEPTION});
+    Function function = new TestFunction(true,TestFunction.TEST_FUNCTION1);
+    server1.invoke(PRClientServerTestBase.class,
+        "registerFunction", new Object []{function});
 
-      javaProps = cGen.getJavaProperties();
-      LogWriterUtils.getLogWriter().info(
-          "testOps2: For second client credentials: " + client2Credentials[0]
-              + "\n" + client2Credentials[1]);
-      client2.invoke(SecurityTestUtil.class,
-          "createCacheClientForMultiUserMode", new Object[] {
-              Integer.valueOf(2), authInit, client2Credentials, javaProps,
-              new Integer[] {port1, port2}, null, Boolean.FALSE,
-              SecurityTestUtil.NO_EXCEPTION});
-      Function function = new TestFunction(true,TestFunction.TEST_FUNCTION1);
-      server1.invoke(PRClientServerTestBase.class,
-          "registerFunction", new Object []{function});
-      
-      server2.invoke(PRClientServerTestBase.class,
-          "registerFunction", new Object []{function});
-      
-      // Perform some put operations before verifying queries
-      client1.invoke(SecurityTestUtil.class, "doMultiUserPuts", new Object[] {
-          Integer.valueOf(4),
-          Integer.valueOf(2),
-          new Integer[] {SecurityTestUtil.NO_EXCEPTION,
-              SecurityTestUtil.NOTAUTHZ_EXCEPTION}});
-      client1.invoke(SecurityTestUtil.class, "doMultiUserQueries",
-          new Object[] {
-              Integer.valueOf(2),
-              new Integer[] {SecurityTestUtil.NO_EXCEPTION,
-                  SecurityTestUtil.NOTAUTHZ_EXCEPTION}, Integer.valueOf(4)});
-      client1.invoke(SecurityTestUtil.class, "doMultiUserQueryExecute",
-          new Object[] {
-              Integer.valueOf(2),
-              new Integer[] {SecurityTestUtil.NO_EXCEPTION,
-                  SecurityTestUtil.NOTAUTHZ_EXCEPTION}, Integer.valueOf(4)});
+    server2.invoke(PRClientServerTestBase.class,
+        "registerFunction", new Object []{function});
 
-      // Verify that the FE succeeds/fails
-      client2.invoke(SecurityTestUtil.class, "doMultiUserFE", new Object[] {
-          Integer.valueOf(2),
-          function,
-          new Integer[] {SecurityTestUtil.NO_EXCEPTION,
-              SecurityTestUtil.NOTAUTHZ_EXCEPTION}, new Object[] {null, null},
-          Boolean.FALSE});
+    // Perform some put operations before verifying queries
+    client1.invoke(SecurityTestUtil.class, "doMultiUserPuts", new Object[] {
+        Integer.valueOf(4),
+        Integer.valueOf(2),
+        new Integer[] {SecurityTestUtil.NO_EXCEPTION,
+            SecurityTestUtil.NOTAUTHZ_EXCEPTION}});
+    client1.invoke(SecurityTestUtil.class, "doMultiUserQueries",
+        new Object[] {
+            Integer.valueOf(2),
+            new Integer[] {SecurityTestUtil.NO_EXCEPTION,
+                SecurityTestUtil.NOTAUTHZ_EXCEPTION}, Integer.valueOf(4)});
+    client1.invoke(SecurityTestUtil.class, "doMultiUserQueryExecute",
+        new Object[] {
+            Integer.valueOf(2),
+            new Integer[] {SecurityTestUtil.NO_EXCEPTION,
+                SecurityTestUtil.NOTAUTHZ_EXCEPTION}, Integer.valueOf(4)});
 
-      // Failover
-      server1.invoke(() -> SecurityTestUtil.closeCache());
-      Thread.sleep(2000);
+    // Verify that the FE succeeds/fails
+    client2.invoke(SecurityTestUtil.class, "doMultiUserFE", new Object[] {
+        Integer.valueOf(2),
+        function,
+        new Integer[] {SecurityTestUtil.NO_EXCEPTION,
+            SecurityTestUtil.NOTAUTHZ_EXCEPTION}, new Object[] {null, null},
+        Boolean.FALSE});
 
-      client1.invoke(SecurityTestUtil.class, "doMultiUserPuts", new Object[] {
-          Integer.valueOf(4),
-          Integer.valueOf(2),
-          new Integer[] {SecurityTestUtil.NO_EXCEPTION,
-              SecurityTestUtil.NOTAUTHZ_EXCEPTION}});
+    // Failover
+    server1.invoke(() -> SecurityTestUtil.closeCache());
+    Thread.sleep(2000);
 
-      client1.invoke(SecurityTestUtil.class, "doMultiUserQueries",
-          new Object[] {
-              Integer.valueOf(2),
-              new Integer[] {SecurityTestUtil.NO_EXCEPTION,
-                  SecurityTestUtil.NOTAUTHZ_EXCEPTION}, Integer.valueOf(4)});
-      client1.invoke(SecurityTestUtil.class, "doMultiUserQueryExecute",
-          new Object[] {
-              Integer.valueOf(2),
-              new Integer[] {SecurityTestUtil.NO_EXCEPTION,
-                  SecurityTestUtil.NOTAUTHZ_EXCEPTION}, Integer.valueOf(4)});
+    client1.invoke(SecurityTestUtil.class, "doMultiUserPuts", new Object[] {
+        Integer.valueOf(4),
+        Integer.valueOf(2),
+        new Integer[] {SecurityTestUtil.NO_EXCEPTION,
+            SecurityTestUtil.NOTAUTHZ_EXCEPTION}});
 
-      // Verify that the FE succeeds/fails
-      client2.invoke(SecurityTestUtil.class, "doMultiUserFE", new Object[] {
-          Integer.valueOf(2),
-          function,
-          new Integer[] {SecurityTestUtil.NO_EXCEPTION,
-              SecurityTestUtil.NOTAUTHZ_EXCEPTION}, new Object[] {null, null},
-          Boolean.TRUE});
+    client1.invoke(SecurityTestUtil.class, "doMultiUserQueries",
+        new Object[] {
+            Integer.valueOf(2),
+            new Integer[] {SecurityTestUtil.NO_EXCEPTION,
+                SecurityTestUtil.NOTAUTHZ_EXCEPTION}, Integer.valueOf(4)});
+    client1.invoke(SecurityTestUtil.class, "doMultiUserQueryExecute",
+        new Object[] {
+            Integer.valueOf(2),
+            new Integer[] {SecurityTestUtil.NO_EXCEPTION,
+                SecurityTestUtil.NOTAUTHZ_EXCEPTION}, Integer.valueOf(4)});
+
+    // Verify that the FE succeeds/fails
+    client2.invoke(SecurityTestUtil.class, "doMultiUserFE", new Object[] {
+        Integer.valueOf(2),
+        function,
+        new Integer[] {SecurityTestUtil.NO_EXCEPTION,
+            SecurityTestUtil.NOTAUTHZ_EXCEPTION}, new Object[] {null, null},
+        Boolean.TRUE});
 
 
   }
 
-  protected void createCacheServers(Properties javaProps,
-      Properties serverProps, Integer port1, Integer port2) {
-    server1.invoke(() -> ClientAuthorizationTestBase.createCacheServer(SecurityTestUtil.getLocatorPort(),
port1, serverProps,
-            javaProps));
-    server2.invoke(() -> ClientAuthorizationTestBase.createCacheServer(SecurityTestUtil.getLocatorPort(),
port2, serverProps,
-            javaProps));
+
+  protected Integer createCacheServerOnVM(VM server, Properties javaProps, Properties serverProps)
{
+    return (Integer)server.invoke(() -> ClientAuthorizationTestBase.createCacheServer(SecurityTestUtil.getLocatorPort(),
serverProps,
+        javaProps));
+
   }
 
   public void testOpsWithClientsInDifferentModes() throws Exception {
@@ -488,21 +487,20 @@ public class ClientMultiUserAuthzDUnitTest extends ClientAuthorizationTestBase
{
       // Start servers with all required properties
       Properties serverProps = buildProperties(authenticator, accessor, false,
           extraAuthProps, extraAuthzProps);
-      Integer port1 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-      Integer port2 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-      createCacheServers(javaProps, serverProps, port1, port2);
+      Integer port1 = createCacheServerOnVM(server1, javaProps, serverProps);
+      Integer port2 = createCacheServerOnVM(server2, javaProps, serverProps);
 
       if (!prepareClientsForOps(gen, cGen, new OperationCode[] {
-          OperationCode.PUT, OperationCode.PUT}, new OperationCode[] {
-          OperationCode.GET, OperationCode.GET}, javaProps, authInit, port1,
+              OperationCode.PUT, OperationCode.PUT}, new OperationCode[] {
+              OperationCode.GET, OperationCode.GET}, javaProps, authInit, port1,
           port2, Boolean.FALSE, Boolean.TRUE)) {
         continue;
       }
       verifyPutsGets(false, true);
 
       if (!prepareClientsForOps(gen, cGen, new OperationCode[] {
-          OperationCode.PUT, OperationCode.CONTAINS_KEY}, new OperationCode[] {
-          OperationCode.DESTROY, OperationCode.DESTROY},
+              OperationCode.PUT, OperationCode.CONTAINS_KEY}, new OperationCode[] {
+              OperationCode.DESTROY, OperationCode.DESTROY},
           javaProps, authInit, port1, port2, Boolean.FALSE, Boolean.FALSE)) {
         continue;
       }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/53b6319e/gemfire-core/src/test/java/com/gemstone/gemfire/security/SecurityTestUtil.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/security/SecurityTestUtil.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/security/SecurityTestUtil.java
index 6e24398..ad9b3e1 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/security/SecurityTestUtil.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/security/SecurityTestUtil.java
@@ -341,7 +341,7 @@ public class SecurityTestUtil extends DistributedTestCase {
     cache.createRegion(regionName, attrs);
     int port;
     if (serverPort == null || serverPort.intValue() <= 0) {
-      port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
+      port = 0;
     }
     else {
       port = serverPort.intValue();


Mime
View raw message