geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From upthewatersp...@apache.org
Subject [19/83] [abbrv] [partial] incubator-geode git commit: Merge remote-tracking branch 'origin/develop' into feature/GEODE-917
Date Mon, 22 Feb 2016 18:35:41 GMT
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5beaaedc/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnitTest.java
----------------------------------------------------------------------
diff --cc geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnitTest.java
index 9bdf56c,0000000..5fa4fc4
mode 100644,000000..100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/CacheServerSSLConnectionDUnitTest.java
@@@ -1,424 -1,0 +1,424 @@@
 +/*
 + * Licensed to the Apache Software Foundation (ASF) under one or more
 + * contributor license agreements.  See the NOTICE file distributed with
 + * this work for additional information regarding copyright ownership.
 + * The ASF licenses this file to You under the Apache License, Version 2.0
 + * (the "License"); you may not use this file except in compliance with
 + * the License.  You may obtain a copy of the License at
 + *
 + *      http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package com.gemstone.gemfire.cache.client.internal;
 +
 +import java.io.IOException;
 +import java.io.PrintWriter;
 +import java.io.StringWriter;
 +import java.util.Properties;
 +import com.gemstone.gemfire.cache.Cache;
 +import com.gemstone.gemfire.cache.CacheFactory;
 +import com.gemstone.gemfire.cache.Region;
 +import com.gemstone.gemfire.cache.RegionFactory;
 +import com.gemstone.gemfire.cache.RegionShortcut;
 +import com.gemstone.gemfire.cache.client.ClientCache;
 +import com.gemstone.gemfire.cache.client.ClientCacheFactory;
 +import com.gemstone.gemfire.cache.client.ClientRegionFactory;
 +import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
 +import com.gemstone.gemfire.cache.server.CacheServer;
 +import com.gemstone.gemfire.distributed.internal.DistributionConfig;
 +import com.gemstone.gemfire.internal.AvailablePortHelper;
 +import com.gemstone.gemfire.security.AuthenticationRequiredException;
 +import com.gemstone.gemfire.test.dunit.DistributedTestCase;
 +import com.gemstone.gemfire.test.dunit.IgnoredException;
 +import com.gemstone.gemfire.test.dunit.Host;
 +import com.gemstone.gemfire.test.dunit.VM;
 +import com.gemstone.gemfire.util.test.TestUtil;
 +
 +/**
 + * Tests cacheserver ssl support added. See https://svn.gemstone.com/trac/gemfire/ticket/48995 for details
 + * @author tushark
 + *
 + */
 +public class CacheServerSSLConnectionDUnitTest extends DistributedTestCase {
 +  
 +  private static final long serialVersionUID = 1L;
 +  private Cache cache;
 +  private CacheServer cacheServer;
 +  private ClientCache clientCache;
 +  private int cacheServerPort;
 +  private String hostName;
 +  
 +  private static final String TRUSTED_STORE = "trusted.keystore";
 +  private static final String CLIENT_KEY_STORE = "client.keystore";
 +  private static final String CLIENT_TRUST_STORE = "client.truststore";
 +  private static final String SERVER_KEY_STORE = "cacheserver.keystore";
 +  private static final String SERVER_TRUST_STORE = "cacheserver.truststore";
 +  
 +  private static CacheServerSSLConnectionDUnitTest instance = new CacheServerSSLConnectionDUnitTest("CacheServerSSLConnectionDUnit");
 +  
 +  
 +  public void setUp() throws Exception {
 +    disconnectAllFromDS();
 +    super.setUp();
 +  }
 +
 +  public CacheServerSSLConnectionDUnitTest(String name) {
 +    super(name);
 +  }  
 +
 +  public Cache createCache(Properties props) throws Exception
 +  {
 +    props.setProperty("mcast-port", "0");
 +    props.setProperty("locators", "");
 +    cache = new CacheFactory(props).create();
 +    if (cache == null) {
 +      throw new Exception("CacheFactory.create() returned null ");
 +    }
 +    return cache;
 +  }
 +  
 +  private void createServer() throws IOException{
 +    cacheServerPort = AvailablePortHelper.getRandomAvailableTCPPort();
 +    cacheServer = cache.addCacheServer();
 +    cacheServer.setPort(cacheServerPort);
 +    cacheServer.start();
 +    hostName = cacheServer.getHostnameForClients();
 +  }
 +  
 +  public int getCacheServerPort(){
 +    return cacheServerPort;
 +  }
 +  
 +  public String getCacheServerHost(){
 +    return hostName;
 +  }
 +  
 +  public void stopCacheServer(){
 +    this.cacheServer.stop();
 +  }
 +  
 +  
 +  @SuppressWarnings("rawtypes")
 +  public void setUpServerVM(boolean cacheServerSslenabled) throws Exception {
 +    Properties gemFireProps = new Properties();
 +
 +    String cacheServerSslprotocols = "any";
 +    String cacheServerSslciphers = "any";
 +    boolean cacheServerSslRequireAuth = true;
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_ENABLED_NAME,
 +        String.valueOf(cacheServerSslenabled));
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_PROTOCOLS_NAME,
 +        cacheServerSslprotocols);
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_CIPHERS_NAME,
 +        cacheServerSslciphers);
 +    gemFireProps.put(
 +        DistributionConfig.SERVER_SSL_REQUIRE_AUTHENTICATION_NAME,
 +        String.valueOf(cacheServerSslRequireAuth));
 +
 +    String keyStore = TestUtil.getResourcePath(CacheServerSSLConnectionDUnitTest.class, SERVER_KEY_STORE);
 +    String trustStore = TestUtil.getResourcePath(CacheServerSSLConnectionDUnitTest.class, SERVER_TRUST_STORE);
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_TYPE_NAME, "jks");
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_NAME, keyStore);
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_PASSWORD_NAME, "password");
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_NAME, trustStore);
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_PASSWORD_NAME, "password");
 +    
 +    StringWriter sw = new StringWriter();
 +    PrintWriter writer = new PrintWriter(sw);
 +    gemFireProps.list(writer);
 +    System.out.println("Starting cacheserver ds with following properties \n" + sw);
 +    createCache(gemFireProps);
 +    
 +    RegionFactory factory = cache.createRegionFactory(RegionShortcut.REPLICATE);
 +    Region r = factory.create("serverRegion");
 +    r.put("serverkey", "servervalue");
 +  }
 +  
 +  public void setUpClientVM(String host, int port,
 +      boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth,
 +      String keyStore, String trustStore, boolean subscription) {
 +
 +    Properties gemFireProps = new Properties();
 +
 +    String cacheServerSslprotocols = "any";
 +    String cacheServerSslciphers = "any";
 +
 +    String keyStorePath = TestUtil.getResourcePath(CacheServerSSLConnectionDUnitTest.class, keyStore);
 +    String trustStorePath = TestUtil.getResourcePath(CacheServerSSLConnectionDUnitTest.class, trustStore);
 +    //using new server-ssl-* properties
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_ENABLED_NAME,
 +        String.valueOf(cacheServerSslenabled));
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_PROTOCOLS_NAME,
 +        cacheServerSslprotocols);
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_CIPHERS_NAME,
 +        cacheServerSslciphers);
 +    gemFireProps.put(
 +        DistributionConfig.SERVER_SSL_REQUIRE_AUTHENTICATION_NAME,
 +        String.valueOf(cacheServerSslRequireAuth));
 +
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_TYPE_NAME, "jks");
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_NAME, keyStorePath);
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_PASSWORD_NAME, "password");
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_NAME, trustStorePath);
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_PASSWORD_NAME, "password");
 +
 +    StringWriter sw = new StringWriter();
 +    PrintWriter writer = new PrintWriter(sw);
 +    gemFireProps.list(writer);
 +    System.out.println("Starting client ds with following properties \n" + sw.getBuffer());
 +    
 +    ClientCacheFactory clientCacheFactory = new ClientCacheFactory(gemFireProps);
 +    clientCacheFactory.setPoolSubscriptionEnabled(subscription).addPoolServer(host, port);
 +    clientCache = clientCacheFactory.create();
 +    
 +    ClientRegionFactory<String,String> regionFactory = clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY);
 +    Region<String, String> region = regionFactory.create("serverRegion");  
 +    assertNotNull(region);
 +  }
 +  
 +  public void doClientRegionTest(){
 +    Region<String, String> region = clientCache.getRegion("serverRegion");
 +    assertEquals("servervalue",region.get("serverkey"));
 +    region.put("clientkey", "clientvalue");
 +    assertEquals("clientvalue",region.get("clientkey"));
 +  }
 +  
 +  public void doServerRegionTest(){
 +    Region<String, String> region = cache.getRegion("serverRegion");
 +    assertEquals("servervalue",region.get("serverkey"));    
 +    assertEquals("clientvalue",region.get("clientkey"));
 +  }
 +  
 +  
 +  public static void setUpServerVMTask(boolean cacheServerSslenabled) throws Exception{
 +    instance.setUpServerVM(cacheServerSslenabled);
 +  }
 +  
 +  public static void createServerTask() throws Exception {
 +    instance.createServer();
 +  }
 +  
 +  public static void setUpClientVMTask(String host, int port,
 +      boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth, String keyStore, String trustStore)
 +      throws Exception {
 +    instance.setUpClientVM(host, port, cacheServerSslenabled,
 +        cacheServerSslRequireAuth, keyStore, trustStore, true);
 +  }
 +  public static void setUpClientVMTaskNoSubscription(String host, int port,
 +      boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth, String keyStore, String trustStore)
 +      throws Exception {
 +    instance.setUpClientVM(host, port, cacheServerSslenabled,
 +        cacheServerSslRequireAuth, keyStore, trustStore, false);
 +  }
 +  
 +  public static void doClientRegionTestTask() {
 +    instance.doClientRegionTest();
 +  }
 +  
 +  public static void doServerRegionTestTask() {
 +    instance.doServerRegionTest();
 +  }
 +  
 +  public static Object[] getCacheServerEndPointTask() {
 +    Object[] array = new Object[2];
 +    array[0] = instance.getCacheServerHost();
 +    array[1] = instance.getCacheServerPort();
 +    return array;
 +  }
 +  
 +  public static void closeCacheTask(){
 +    if (instance != null && instance.cache != null) {
 +      instance.cache.close();
 +    }
 +  }
 +  
 +  public static void closeClientCacheTask(){
 +    if (instance != null && instance.clientCache != null) {
 +      instance.clientCache.close();
 +    }
 +  }
 +  
 +  public void testCacheServerSSL() throws Exception {
 +    final Host host = Host.getHost(0);
 +    VM serverVM = host.getVM(1);
 +    VM clientVM = host.getVM(2);
 +    
 +    boolean cacheServerSslenabled = true;
 +    boolean cacheClientSslenabled = true;
 +    boolean cacheClientSslRequireAuth = true;
 +    
-     serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled});
-     serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "createServerTask");
++    serverVM.invoke(() -> CacheServerSSLConnectionDUnitTest.setUpServerVMTask(cacheServerSslenabled));
++    serverVM.invoke(() -> CacheServerSSLConnectionDUnitTest.createServerTask());
 +    
-     Object array[] = (Object[])serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "getCacheServerEndPointTask"); 
++    Object array[] = (Object[])serverVM.invoke(() -> CacheServerSSLConnectionDUnitTest.getCacheServerEndPointTask()); 
 +    String hostName = (String)array[0];
 +    int port = (Integer) array[1];
 +    Object params[] = new Object[6];
 +    params[0] = hostName;
 +    params[1] = port;
 +    params[2] = cacheClientSslenabled;
 +    params[3] = cacheClientSslRequireAuth;
 +    params[4] = CLIENT_KEY_STORE;
 +    params[5] = CLIENT_TRUST_STORE;
 +    //getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);
 +    clientVM.invoke(CacheServerSSLConnectionDUnitTest.class, "setUpClientVMTask", params);
-     clientVM.invoke(CacheServerSSLConnectionDUnitTest.class, "doClientRegionTestTask");
-     serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "doServerRegionTestTask");
++    clientVM.invoke(() -> CacheServerSSLConnectionDUnitTest.doClientRegionTestTask());
++    serverVM.invoke(() -> CacheServerSSLConnectionDUnitTest.doServerRegionTestTask());
 +    
 +  }
 +  
 +  
 +  public void testNonSSLClient() throws Exception {
 +    final Host host = Host.getHost(0);
 +    VM serverVM = host.getVM(1);
 +    VM clientVM = host.getVM(2);
 +    
 +    boolean cacheServerSslenabled = true;
 +    boolean cacheClientSslenabled = false;
 +    boolean cacheClientSslRequireAuth = true;
 +    
-     serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled});
-     serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "createServerTask");
++    serverVM.invoke(() -> CacheServerSSLConnectionDUnitTest.setUpServerVMTask(cacheServerSslenabled));
++    serverVM.invoke(() -> CacheServerSSLConnectionDUnitTest.createServerTask());
 +    
-     Object array[] = (Object[])serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "getCacheServerEndPointTask"); 
++    Object array[] = (Object[])serverVM.invoke(() -> CacheServerSSLConnectionDUnitTest.getCacheServerEndPointTask()); 
 +    String hostName = (String)array[0];
 +    int port = (Integer) array[1];
 +    Object params[] = new Object[6];
 +    params[0] = hostName;
 +    params[1] = port;
 +    params[2] = cacheClientSslenabled;
 +    params[3] = cacheClientSslRequireAuth;
 +    params[4] = TRUSTED_STORE;
 +    params[5] = TRUSTED_STORE;
 +    IgnoredException expect = IgnoredException.addIgnoredException("javax.net.ssl.SSLException", serverVM);
 +    IgnoredException expect2 = IgnoredException.addIgnoredException("IOException", serverVM);
 +    try{
 +      //getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);    
 +      clientVM.invoke(CacheServerSSLConnectionDUnitTest.class, "setUpClientVMTaskNoSubscription", params);
-       clientVM.invoke(CacheServerSSLConnectionDUnitTest.class, "doClientRegionTestTask");
-       serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "doServerRegionTestTask");
++      clientVM.invoke(() -> CacheServerSSLConnectionDUnitTest.doClientRegionTestTask());
++      serverVM.invoke(() -> CacheServerSSLConnectionDUnitTest.doServerRegionTestTask());
 +      fail("Test should fail as non-ssl client is trying to connect to ssl configured server");
 +    } catch (Exception rmiException) {
 +      Throwable e = rmiException.getCause();
 +      //getLogWriter().info("ExceptionCause at clientVM " + e);
 +      if (e instanceof com.gemstone.gemfire.cache.client.ServerOperationException) {
 +        Throwable t = e.getCause();
 +        //getLogWriter().info("Cause is " + t);
 +        assertTrue(t instanceof com.gemstone.gemfire.security.AuthenticationRequiredException);
 +      } else {
 +        //getLogWriter().error("Unexpected exception ", e);
 +        fail("Unexpected Exception: " + e + " expected: "
 +            + AuthenticationRequiredException.class);
 +      }
 +    } finally {
 +      expect.remove();
 +      expect2.remove();
 +    }
 +  }
 +  
 +  public void testSSLClientWithNoAuth() throws Exception {
 +    final Host host = Host.getHost(0);
 +    VM serverVM = host.getVM(1);
 +    VM clientVM = host.getVM(2);
 +
 +    boolean cacheServerSslenabled = true;
 +    boolean cacheClientSslenabled = true;
 +    boolean cacheClientSslRequireAuth = false;
 +
-     serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled});
-     serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "createServerTask");
++    serverVM.invoke(() -> CacheServerSSLConnectionDUnitTest.setUpServerVMTask(cacheServerSslenabled));
++    serverVM.invoke(() -> CacheServerSSLConnectionDUnitTest.createServerTask());
 +
-     Object array[] = (Object[])serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "getCacheServerEndPointTask"); 
++    Object array[] = (Object[])serverVM.invoke(() -> CacheServerSSLConnectionDUnitTest.getCacheServerEndPointTask()); 
 +    String hostName = (String)array[0];
 +    int port = (Integer) array[1];
 +    Object params[] = new Object[6];
 +    params[0] = hostName;
 +    params[1] = port;
 +    params[2] = cacheClientSslenabled;
 +    params[3] = cacheClientSslRequireAuth;
 +    params[4] = CLIENT_KEY_STORE;
 +    params[5] = CLIENT_TRUST_STORE;
 +    //getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);
 +    try {
 +      clientVM.invoke(CacheServerSSLConnectionDUnitTest.class, "setUpClientVMTask", params);
-       clientVM.invoke(CacheServerSSLConnectionDUnitTest.class, "doClientRegionTestTask");
-       serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "doServerRegionTestTask");
++      clientVM.invoke(() -> CacheServerSSLConnectionDUnitTest.doClientRegionTestTask());
++      serverVM.invoke(() -> CacheServerSSLConnectionDUnitTest.doServerRegionTestTask());
 +    } catch (Exception rmiException) {
 +      Throwable e = rmiException.getCause();
 +      //getLogWriter().info("ExceptionCause at clientVM " + e);
 +      if (e instanceof com.gemstone.gemfire.cache.client.ServerOperationException) {
 +        Throwable t = e.getCause();
 +        //getLogWriter().info("Cause is " + t);
 +        assertTrue(t instanceof com.gemstone.gemfire.security.AuthenticationRequiredException);
 +      } else {
 +        //getLogWriter().error("Unexpected exception ", e);
 +        fail("Unexpected Exception...expected "
 +            + AuthenticationRequiredException.class);
 +      }
 +    }
 +  }
 +  
 +  public void testSSLClientWithNonSSLServer() throws Exception {
 +    final Host host = Host.getHost(0);
 +    VM serverVM = host.getVM(1);
 +    VM clientVM = host.getVM(2);
 +    
 +    boolean cacheServerSslenabled = false;
 +    boolean cacheClientSslenabled = true;
 +    boolean cacheClientSslRequireAuth = true;
 +    
-     serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled});
-     serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "createServerTask");
++    serverVM.invoke(() -> CacheServerSSLConnectionDUnitTest.setUpServerVMTask(cacheServerSslenabled));
++    serverVM.invoke(() -> CacheServerSSLConnectionDUnitTest.createServerTask());
 +    
-     Object array[] = (Object[])serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "getCacheServerEndPointTask"); 
++    Object array[] = (Object[])serverVM.invoke(() -> CacheServerSSLConnectionDUnitTest.getCacheServerEndPointTask()); 
 +    String hostName = (String)array[0];
 +    int port = (Integer) array[1];
 +    Object params[] = new Object[6];
 +    params[0] = hostName;
 +    params[1] = port;
 +    params[2] = cacheClientSslenabled;
 +    params[3] = cacheClientSslRequireAuth;
 +    params[4] = TRUSTED_STORE;
 +    params[5] = TRUSTED_STORE;
 +    IgnoredException expect = IgnoredException.addIgnoredException("javax.net.ssl.SSLHandshakeException", serverVM);
 +    try{
 +      //getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);    
 +      clientVM.invoke(CacheServerSSLConnectionDUnitTest.class, "setUpClientVMTask", params);
-       clientVM.invoke(CacheServerSSLConnectionDUnitTest.class, "doClientRegionTestTask");
-       serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "doServerRegionTestTask");
++      clientVM.invoke(() -> CacheServerSSLConnectionDUnitTest.doClientRegionTestTask());
++      serverVM.invoke(() -> CacheServerSSLConnectionDUnitTest.doServerRegionTestTask());
 +      fail("Test should fail as ssl client with ssl enabled is trying to connect to server with ssl disabled");
 +    }catch (Exception rmiException) {
 +      
 +      //ignore
 +      
 +      /*Throwable e = rmiException.getCause();
 +      getLogWriter().info("ExceptionCause at clientVM " + e);
 +      if (e instanceof com.gemstone.gemfire.cache.client.ServerOperationException) {
 +        Throwable t = e.getCause();
 +        getLogWriter().info("Cause is " + t);
 +        assertTrue(t instanceof com.gemstone.gemfire.security.AuthenticationRequiredException);
 +      } else {
 +        getLogWriter().error("Unexpected exception ", e);
 +        fail("Unexpected Exception...expected "
 +            + AuthenticationRequiredException.class);
 +      }*/
 +    } finally {
 +      expect.remove();
 +    }
 +  }
 +  
 +  @Override
 +  protected final void preTearDown() throws Exception {
 +    final Host host = Host.getHost(0);
 +    VM serverVM = host.getVM(1);
 +    VM clientVM = host.getVM(2);
-     clientVM.invoke(CacheServerSSLConnectionDUnitTest.class, "closeClientCacheTask");
-     serverVM.invoke(CacheServerSSLConnectionDUnitTest.class, "closeCacheTask");
++    clientVM.invoke(() -> CacheServerSSLConnectionDUnitTest.closeClientCacheTask());
++    serverVM.invoke(() -> CacheServerSSLConnectionDUnitTest.closeCacheTask());
 +  }
 +}
 +

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5beaaedc/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/LocatorLoadBalancingDUnitTest.java
----------------------------------------------------------------------
diff --cc geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/LocatorLoadBalancingDUnitTest.java
index 3c6a980,0000000..6f4d404
mode 100644,000000..100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/LocatorLoadBalancingDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/LocatorLoadBalancingDUnitTest.java
@@@ -1,499 -1,0 +1,502 @@@
 +/*
 + * Licensed to the Apache Software Foundation (ASF) under one or more
 + * contributor license agreements.  See the NOTICE file distributed with
 + * this work for additional information regarding copyright ownership.
 + * The ASF licenses this file to You under the Apache License, Version 2.0
 + * (the "License"); you may not use this file except in compliance with
 + * the License.  You may obtain a copy of the License at
 + *
 + *      http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package com.gemstone.gemfire.cache.client.internal;
 +
 +import java.io.IOException;
 +import java.io.Serializable;
 +import java.net.InetAddress;
 +import java.net.UnknownHostException;
 +import java.util.Collections;
 +import java.util.HashMap;
 +import java.util.List;
 +import java.util.Map;
 +
 +import org.junit.Assert;
 +
 +import com.gemstone.gemfire.cache.Cache;
 +import com.gemstone.gemfire.cache.client.PoolManager;
 +import com.gemstone.gemfire.cache.client.internal.locator.ClientConnectionRequest;
 +import com.gemstone.gemfire.cache.client.internal.locator.ClientConnectionResponse;
 +import com.gemstone.gemfire.cache.client.internal.locator.QueueConnectionRequest;
 +import com.gemstone.gemfire.cache.client.internal.locator.QueueConnectionResponse;
 +import com.gemstone.gemfire.cache.server.CacheServer;
 +import com.gemstone.gemfire.cache.server.ServerLoad;
 +import com.gemstone.gemfire.cache.server.ServerLoadProbeAdapter;
 +import com.gemstone.gemfire.cache.server.ServerMetrics;
 +import com.gemstone.gemfire.distributed.Locator;
 +import com.gemstone.gemfire.distributed.internal.InternalLocator;
 +import com.gemstone.gemfire.distributed.internal.ServerLocation;
 +import com.gemstone.gemfire.distributed.internal.ServerLocator;
 +import com.gemstone.gemfire.distributed.internal.tcpserver.TcpClient;
 +import com.gemstone.gemfire.internal.AvailablePort;
 +import com.gemstone.gemfire.internal.cache.CacheServerImpl;
 +import com.gemstone.gemfire.internal.cache.PoolFactoryImpl;
 +import com.gemstone.gemfire.internal.logging.InternalLogWriter;
 +import com.gemstone.gemfire.internal.logging.LocalLogWriter;
 +import com.gemstone.gemfire.test.dunit.Host;
 +import com.gemstone.gemfire.test.dunit.LogWriterUtils;
 +import com.gemstone.gemfire.test.dunit.NetworkUtils;
 +import com.gemstone.gemfire.test.dunit.SerializableRunnable;
 +import com.gemstone.gemfire.test.dunit.SerializableRunnableIF;
 +import com.gemstone.gemfire.test.dunit.VM;
 +import com.gemstone.gemfire.test.dunit.Wait;
 +import com.gemstone.gemfire.test.dunit.WaitCriterion;
 +
 +/**
 + * @author dsmith
 + *
 + */
 +public class LocatorLoadBalancingDUnitTest extends LocatorTestBase {
 +  
 +  /**
 +   * The number of connections that we can be off by in the balancing tests
 +   * We need this little fudge factor, because the locator can receive an update
 +   * from the bridge server after it has made incremented its counter for a client
 +   * connection, but the client hasn't connected yet. This wipes out the estimation
 +   * on the locator.  This means that we may be slighly off in our balance.
 +   * 
 +   * TODO grid fix this hole in the locator.
 +   */
 +  private static final int ALLOWABLE_ERROR_IN_COUNT = 1;
 +  protected static final long MAX_WAIT = 60000;
 +
 +  public LocatorLoadBalancingDUnitTest(String name) {
 +    super(name);
 +  }
 +
 +  /**
 +   * Test the locator discovers a bridge server and is initialized with 
 +   * the correct load for that bridge server.
 +   */
 +  public void testDiscovery() {
 +    Host host = Host.getHost(0);
 +    VM vm0 = host.getVM(0);
 +    VM vm1 = host.getVM(1);
 +    VM vm2 = host.getVM(2);
 +//    vm0.invoke(new SerializableRunnable() {
 +//      public void run() {
 +//        System.setProperty("gemfire.DistributionAdvisor.VERBOSE", "true");
 +//      }
 +//    });
 +    
 +    int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
 +    startLocatorInVM(vm0, locatorPort, "");
 +    
 +    String locators = getLocatorString(host, locatorPort);
 +    
 +    int serverPort = startBridgeServerInVM(vm1, new String[] {"a", "b"},  locators);
 +    
 +    ServerLoad expectedLoad = new ServerLoad(0f, 1 / 800.0f, 0f, 1f);
 +    ServerLocation expectedLocation = new ServerLocation(NetworkUtils.getServerHostName(vm0
 +        .getHost()), serverPort);
 +    Map expected = new HashMap();
 +    expected.put(expectedLocation, expectedLoad);
 +    
 +    checkLocatorLoad(vm0, expected);
 +    
 +    int serverPort2 = startBridgeServerInVM(vm2, new String[] {"a", "b"},  locators);
 +    
 +    ServerLocation expectedLocation2 = new ServerLocation(NetworkUtils.getServerHostName(vm0
 +        .getHost()), serverPort2);
 +    
 +    expected.put(expectedLocation2, expectedLoad);
 +    checkLocatorLoad(vm0, expected);
 +  }
 +  
 +  /**
 +   * Test that the locator will properly estimate the load for servers when
 +   * it receives connection requests. 
 +   */
 +  public void testEstimation() throws UnknownHostException, IOException, ClassNotFoundException {
 +    Host host = Host.getHost(0);
 +    VM vm0 = host.getVM(0);
 +    VM vm1 = host.getVM(1);
 +    
 +    int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
 +    startLocatorInVM(vm0, locatorPort, "");
 +    String locators = getLocatorString(host, locatorPort);
 +    
 +    int serverPort = startBridgeServerInVM(vm1, new String[] {"a", "b"},  locators);
 +    
 +    ServerLoad expectedLoad = new ServerLoad(2/800f, 1 / 800.0f, 0f, 1f);
 +    ServerLocation expectedLocation = new ServerLocation(NetworkUtils.getServerHostName(host), serverPort);
 +    Map expected = new HashMap();
 +    expected.put(expectedLocation, expectedLoad);
 +    
 +    ClientConnectionResponse response;
 +    response = (ClientConnectionResponse) TcpClient.requestToServer(InetAddress
 +        .getByName(NetworkUtils.getServerHostName(host)), locatorPort,
 +        new ClientConnectionRequest(Collections.EMPTY_SET, null), 10000);
 +    Assert.assertEquals(expectedLocation, response.getServer());
 +    
 +    response = (ClientConnectionResponse) TcpClient.requestToServer(InetAddress
 +        .getByName(NetworkUtils.getServerHostName(host)), locatorPort,
 +        new ClientConnectionRequest(Collections.EMPTY_SET, null), 10000, true);
 +    Assert.assertEquals(expectedLocation, response.getServer());
 +    
 +    //we expect that the connection load load will be 2 * the loadPerConnection
 +    checkLocatorLoad(vm0, expected);
 +    
 +    QueueConnectionResponse response2;
 +    response2 = (QueueConnectionResponse) TcpClient.requestToServer(InetAddress
 +        .getByName(NetworkUtils.getServerHostName(host)), locatorPort,
 +        new QueueConnectionRequest(null, 2,
 +            Collections.EMPTY_SET, null, false), 10000, true);
 +    Assert.assertEquals(Collections.singletonList(expectedLocation), response2.getServers());
 +    
 +    response2 = (QueueConnectionResponse) TcpClient
 +        .requestToServer(InetAddress.getByName(NetworkUtils.getServerHostName(host)),
 +            locatorPort, new QueueConnectionRequest(null, 5, Collections.EMPTY_SET, null,
 +                false), 10000, true);
 +    
 +    Assert.assertEquals(Collections.singletonList(expectedLocation), response2.getServers());
 +
 +    //we expect that the queue load will increase by 2
 +    expectedLoad.setSubscriptionConnectionLoad(2f);
 +    checkLocatorLoad(vm0, expected);
 +  }
 +  
 +  /**
 +   * Test to make sure the bridge servers communicate
 +   * their updated load to the controller when the load
 +   * on the bridge server changes.
++   * @throws Exception 
 +   */
-   public void testLoadMessaging() {
++  public void testLoadMessaging() throws Exception {
 +    final Host host = Host.getHost(0);
 +    VM vm0 = host.getVM(0);
 +    VM vm1 = host.getVM(1);
 +    VM vm2 = host.getVM(2);
 +    
 +    int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
 +    startLocatorInVM(vm0, locatorPort, "");
 +    String locators = getLocatorString(host, locatorPort);
 +    
 +    final int serverPort = startBridgeServerInVM(vm1, new String[] {"a", "b"},  locators);
 +    
 +    //We expect 0 load
 +    Map expected = new HashMap();
 +    ServerLocation expectedLocation = new ServerLocation(NetworkUtils.getServerHostName(host), serverPort);
 +    ServerLoad expectedLoad = new ServerLoad(0f, 1 / 800.0f, 0f, 1f);
 +    expected.put(expectedLocation, expectedLoad);
 +    checkLocatorLoad(vm0, expected);
 +    
 +    PoolFactoryImpl pf = new PoolFactoryImpl(null);
 +    pf.addServer(NetworkUtils.getServerHostName(host), serverPort);
 +    pf.setMinConnections(8);
 +    pf.setMaxConnections(8);
 +    pf.setSubscriptionEnabled(true);
 +    startBridgeClientInVM(vm2, pf.getPoolAttributes(), new String[] {REGION_NAME});
 +    
 +    //We expect 8 client to server connections. The queue requires
 +    //an additional client to server connection, but that shouldn't show up here.
 +    expectedLoad = new ServerLoad(8/800f, 1 / 800.0f, 1f, 1f);
 +    expected.put(expectedLocation, expectedLoad);
 +    
 +    
 +    checkLocatorLoad(vm0, expected);
 +    
 +    stopBridgeMemberVM(vm2);
 +    
 +    //Now we expect 0 load
 +    expectedLoad = new ServerLoad(0f, 1 / 800.0f, 0f, 1f);
 +    expected.put(expectedLocation, expectedLoad);
 +    checkLocatorLoad(vm0, expected);
 +  }
 +  
 +  /**
 +   * Test to make sure that the locator
 +   * balancing load between two servers.
++   * @throws Exception 
 +   */
-   public void testBalancing() {
++  public void testBalancing() throws Exception {
 +    final Host host = Host.getHost(0);
 +    VM vm0 = host.getVM(0);
 +    VM vm1 = host.getVM(1);
 +    VM vm2 = host.getVM(2);
 +    VM vm3 = host.getVM(3);
 +    
 +    int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
 +    startLocatorInVM(vm0, locatorPort, "");
 +    String locators = getLocatorString(host, locatorPort);
 +    
 +    startBridgeServerInVM(vm1, new String[] {"a", "b"},  locators);
 +    startBridgeServerInVM(vm2, new String[] {"a", "b"},  locators);
 +    
 +    PoolFactoryImpl pf = new PoolFactoryImpl(null);
 +    pf.addLocator(NetworkUtils.getServerHostName(host), locatorPort);
 +    pf.setMinConnections(80);
 +    pf.setMaxConnections(80);
 +    pf.setSubscriptionEnabled(false);
 +    pf.setIdleTimeout(-1);
 +    startBridgeClientInVM(vm3, pf.getPoolAttributes(), new String[] {REGION_NAME});
 +    
 +    waitForPrefilledConnections(vm3, 80);
 +    
 +    checkConnectionCount(vm1, 40);
 +    checkConnectionCount(vm2, 40);
 +  }
 +
 +  private void checkConnectionCount(VM vm, final int count) {
 +    SerializableRunnableIF checkConnectionCount = new SerializableRunnable("checkConnectionCount") {
 +      public void run() {
 +        Cache cache = (Cache) remoteObjects.get(CACHE_KEY);
 +        final CacheServerImpl server = (CacheServerImpl)
 +            cache.getCacheServers().get(0);
 +        WaitCriterion wc = new WaitCriterion() {
 +          String excuse;
 +          public boolean done() {
 +            int sz = server.getAcceptor().getStats()
 +                .getCurrentClientConnections();
 +            if (Math.abs(sz - count) <= ALLOWABLE_ERROR_IN_COUNT) {
 +              return true;
 +            }
 +            excuse = "Found " + sz + " connections, expected " + count;
 +            return false;
 +          }
 +          public String description() {
 +            return excuse;
 +          }
 +        };
 +        Wait.waitForCriterion(wc, 5 * 60 * 1000, 1000, true);
 +      }
 +    };
 +    
 +    vm.invoke(checkConnectionCount);
 +  }
 +  
-   private void waitForPrefilledConnections(VM vm, final int count) {
++  private void waitForPrefilledConnections(VM vm, final int count) throws Exception {
 +    waitForPrefilledConnections(vm, count, POOL_NAME);
 +  }
 +
-   private void waitForPrefilledConnections(VM vm, final int count, final String poolName) {
++  private void waitForPrefilledConnections(VM vm, final int count, final String poolName) throws Exception {
 +    SerializableRunnable runnable = new SerializableRunnable("waitForPrefilledConnections") {
 +      public void run() {
 +        final PoolImpl pool = (PoolImpl) PoolManager.getAll().get(poolName);
 +        WaitCriterion ev = new WaitCriterion() {
 +          public boolean done() {
 +            return pool.getConnectionCount() >= count; 
 +          }
 +          public String description() {
 +            return "connection count never reached " + count;
 +          }
 +        };
 +        Wait.waitForCriterion(ev, MAX_WAIT, 200, true);
 +      }
 +    };
 +    if(vm == null) {
 +      runnable.run();
 +    } else {
 +      vm.invoke(runnable);
 +    }
 +  }
 +  
 +  /** Test that the locator balances load between
 +   * three servers with intersecting server groups.
 +   * Server:    1       2       3
 +   * Groups:    a       a,b     b
++   * @throws Exception 
 +   */
-   public void testIntersectingServerGroups() {
++  public void testIntersectingServerGroups() throws Exception {
 +    final Host host = Host.getHost(0);
 +    VM vm0 = host.getVM(0);
 +    VM vm1 = host.getVM(1);
 +    VM vm2 = host.getVM(2);
 +    VM vm3 = host.getVM(3);
 +    
 +    int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
 +    startLocatorInVM(vm0, locatorPort, "");
 +    String locators = getLocatorString(host, locatorPort);
 +    
 +    int serverPort1 = startBridgeServerInVM(vm1, new String[] {"a"},  locators);
 +    startBridgeServerInVM(vm2, new String[] {"a", "b"},  locators);
 +    startBridgeServerInVM(vm3, new String[] {"b"},  locators);
 +    
 +    PoolFactoryImpl pf = new PoolFactoryImpl(null);
 +    pf.addLocator(NetworkUtils.getServerHostName(host), locatorPort);
 +    pf.setMinConnections(12);
 +    pf.setSubscriptionEnabled(false);
 +    pf.setServerGroup("a");
 +    pf.setIdleTimeout(-1);
 +    startBridgeClientInVM(null, pf.getPoolAttributes(), new String[] {REGION_NAME});
 +    waitForPrefilledConnections(null, 12);
 +    
 +    checkConnectionCount(vm1, 6);
 +    checkConnectionCount(vm2, 6);
 +    checkConnectionCount(vm3, 0);
 +    
 +    LogWriterUtils.getLogWriter().info("pool1 prefilled");
 +    
 +    PoolFactoryImpl pf2 = (PoolFactoryImpl) PoolManager.createFactory();
 +    pf2.init(pf.getPoolAttributes());
 +    pf2.setServerGroup("b");
 +    PoolImpl pool2= (PoolImpl) pf2.create("testPool2");
 +    waitForPrefilledConnections(null, 12, "testPool2");
 +
 +    // The load will not be perfect, because we created all of the connections
 +    //for group A first.
 +    checkConnectionCount(vm1, 6);
 +    checkConnectionCount(vm2, 9);
 +    checkConnectionCount(vm3, 9);
 +    
 +    LogWriterUtils.getLogWriter().info("pool2 prefilled");
 +    
 +    ServerLocation location1 = new ServerLocation(NetworkUtils.getServerHostName(host), serverPort1);
 +    PoolImpl pool1 = (PoolImpl) PoolManager.getAll().get(POOL_NAME);
 +    Assert.assertEquals("a", pool1.getServerGroup());
 +    
 +    //Use up all of the pooled connections on pool1, and acquire 3 more
 +    for(int i = 0; i < 15; i++) {
 +      pool1.acquireConnection();
 +    }
 +    
 +    LogWriterUtils.getLogWriter().info("aquired 15 connections in pool1");
 +    
 +    //now the load should be equal
 +    checkConnectionCount(vm1, 9);
 +    checkConnectionCount(vm2, 9);
 +    checkConnectionCount(vm3, 9);
 +    
 +    //use up all of the pooled connections on pool2
 +    for(int i = 0; i < 12; i++) {
 +      pool2.acquireConnection();
 +    }
 +    
 +    LogWriterUtils.getLogWriter().info("aquired 12 connections in pool2");
 +    
 +    //interleave creating connections in both pools
 +    for(int i = 0; i < 6; i++) {
 +      pool1.acquireConnection();
 +      pool2.acquireConnection();
 +    }
 +    
 +    LogWriterUtils.getLogWriter().info("interleaved 6 connections from pool1 with 6 connections from pool2");
 +    
 +    //The load should still be balanced
 +    checkConnectionCount(vm1, 13);
 +    checkConnectionCount(vm2, 13);
 +    checkConnectionCount(vm3, 13);
 +    
 +  }
 +  
-   public void testCustomLoadProbe() {
++  public void testCustomLoadProbe() throws Exception {
 +    final Host host = Host.getHost(0);
 +    VM vm0 = host.getVM(0);
 +    VM vm1 = host.getVM(1);
 +    VM vm2 = host.getVM(2);
 +//    VM vm3 = host.getVM(3);
 +    
 +    int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
 +    startLocatorInVM(vm0, locatorPort, "");
 +    String locators = getLocatorString(host, locatorPort);
 +    
 +    ServerLoad load1= new ServerLoad(.3f, .01f, .44f, 4564f);
 +    ServerLoad load2= new ServerLoad(23.2f, 1.1f, 22.3f, .3f);
 +    int serverPort1 = startBridgeServerInVM(vm1, null, locators, new String[] {REGION_NAME}, new MyLoadProbe(load1 ));
 +    int serverPort2 = startBridgeServerInVM(vm2, null, locators, new String[] {REGION_NAME}, new MyLoadProbe(load2 ));
 +    
 +    HashMap expected = new HashMap();
 +    ServerLocation l1 = new ServerLocation(NetworkUtils.getServerHostName(host), serverPort1);
 +    ServerLocation l2 = new ServerLocation(NetworkUtils.getServerHostName(host), serverPort2);
 +    expected.put(l1, load1);
 +    expected.put(l2, load2);
 +    checkLocatorLoad(vm0, expected);
 +    
 +    load1.setConnectionLoad(25f);
 +    changeLoad(vm1, load1);
 +    load2.setSubscriptionConnectionLoad(3.5f);
 +    changeLoad(vm2, load2);
 +    checkLocatorLoad(vm0, expected);
 +    
 +    load1 = new ServerLoad(1f, .1f, 0f, 1f);
 +    load2 = new ServerLoad(2f, 5f, 0f, 2f);
 +    expected.put(l1, load1);
 +    expected.put(l2, load2);
 +    changeLoad(vm1, load1);
 +    changeLoad(vm2, load2);
 +    checkLocatorLoad(vm0, expected);
 +    
 +    PoolFactoryImpl pf = new PoolFactoryImpl(null);
 +    pf.addLocator(NetworkUtils.getServerHostName(host), locatorPort);
 +    pf.setMinConnections(20);
 +    pf.setSubscriptionEnabled(true);
 +    pf.setIdleTimeout(-1);
 +    startBridgeClientInVM(null, pf.getPoolAttributes(), new String[] {REGION_NAME});
 +    waitForPrefilledConnections(null, 20);
 +    
 +    //The first 10 connection should to go vm1, then 1 to vm2, then another 9 to vm1
 +    //because have unequal values for loadPerConnection
 +    checkConnectionCount(vm1, 19);
 +    checkConnectionCount(vm2, 1);
 +  }
 +  
 +  public void checkLocatorLoad(VM vm, final Map expected) {
 +    vm.invoke(new SerializableRunnable() {
 +      public void run() {
 +        List locators = Locator.getLocators();
 +        Assert.assertEquals(1, locators.size());
 +        InternalLocator locator = (InternalLocator) locators.get(0);
 +        final ServerLocator sl = locator.getServerLocatorAdvisee();
 +        InternalLogWriter log = new LocalLogWriter(InternalLogWriter.FINEST_LEVEL, System.out);
 +        sl.getDistributionAdvisor().dumpProfiles("PROFILES= ");
 +        WaitCriterion ev = new WaitCriterion() {
 +          public boolean done() {
 +            return expected.equals(sl.getLoadMap());
 +          }
 +          public String description() {
 +            return "load map never became equal to " + expected;
 +          }
 +        };
 +        Wait.waitForCriterion(ev, MAX_WAIT, 200, true);
 +      }
 +    });
 +  }
 +  
 +  private void changeLoad(VM vm, final ServerLoad newLoad) {
 +    vm.invoke(new SerializableRunnable() {
 +
 +      public void run() {
 +        Cache cache = (Cache) remoteObjects.get(CACHE_KEY);
 +        CacheServer server = (CacheServer) cache.getCacheServers().get(0);
 +        MyLoadProbe probe = (MyLoadProbe) server.getLoadProbe();
 +        probe.setLoad(newLoad);
 +      }
 +      
 +    });
 +  }
 +  
 +  private static class MyLoadProbe extends ServerLoadProbeAdapter implements Serializable {
 +    private ServerLoad load;
 +    
 +    public MyLoadProbe(ServerLoad load) {
 +      this.load = load;
 +    }
 +    
 +    public ServerLoad getLoad(ServerMetrics metrics) {
 +      float connectionLoad = load.getConnectionLoad()
 +          + metrics.getConnectionCount() * load.getLoadPerConnection();
 +      float queueLoad = load.getSubscriptionConnectionLoad() + metrics.getSubscriptionConnectionCount()
 +          * load.getLoadPerSubscriptionConnection();
 +      return new ServerLoad(connectionLoad, load.getLoadPerConnection(),
 +          queueLoad, load.getLoadPerSubscriptionConnection());
 +    }
 +    
 +    public void setLoad(ServerLoad load) {
 +      this.load = load;
 +    }
 +  }
 +}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5beaaedc/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/LocatorTestBase.java
----------------------------------------------------------------------
diff --cc geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/LocatorTestBase.java
index f35e2fa,0000000..a89d648
mode 100644,000000..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
@@@ -1,365 -1,0 +1,365 @@@
 +/*
 + * Licensed to the Apache Software Foundation (ASF) under one or more
 + * contributor license agreements.  See the NOTICE file distributed with
 + * this work for additional information regarding copyright ownership.
 + * The ASF licenses this file to You under the Apache License, Version 2.0
 + * (the "License"); you may not use this file except in compliance with
 + * the License.  You may obtain a copy of the License at
 + *
 + *      http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package com.gemstone.gemfire.cache.client.internal;
 +
 +import java.io.File;
 +import java.io.IOException;
 +import java.net.InetAddress;
 +import java.net.InetSocketAddress;
 +import java.net.UnknownHostException;
 +import java.util.HashMap;
 +import java.util.HashSet;
 +import java.util.List;
 +import java.util.Properties;
 +import java.util.Set;
 +
 +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.RegionAttributes;
 +import com.gemstone.gemfire.cache.Scope;
 +import com.gemstone.gemfire.cache.client.Pool;
 +import com.gemstone.gemfire.cache.client.PoolManager;
 +import com.gemstone.gemfire.cache.server.ServerLoadProbe;
 +import com.gemstone.gemfire.cache.server.CacheServer;
 +import com.gemstone.gemfire.distributed.DistributedSystem;
 +import com.gemstone.gemfire.distributed.Locator;
 +import com.gemstone.gemfire.distributed.internal.DistributionConfig;
 +import com.gemstone.gemfire.internal.AvailablePortHelper;
 +import com.gemstone.gemfire.internal.cache.PoolFactoryImpl;
 +import com.gemstone.gemfire.test.dunit.Assert;
 +import com.gemstone.gemfire.test.dunit.DistributedTestCase;
 +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.NetworkUtils;
 +import com.gemstone.gemfire.test.dunit.SerializableCallable;
 +import com.gemstone.gemfire.test.dunit.SerializableRunnable;
 +import com.gemstone.gemfire.test.dunit.VM;
 +
 +/**
 + * @author dsmith
 + *
 + */
 +public abstract class LocatorTestBase  extends DistributedTestCase {
 +  protected static final String CACHE_KEY = "CACHE";
 +  protected static final String LOCATOR_KEY = "LOCATOR";
 +  protected static final String REGION_NAME = "A_REGION";
 +  protected static final String POOL_NAME = "daPool";
 +  protected static final Object CALLBACK_KEY = "callback";
 +  /** A map for storing temporary objects in a remote VM so that they can be used
 +   * between calls. Cleared after each test.
 +   */
 +  protected static final HashMap remoteObjects = new HashMap();
 +
 +  public LocatorTestBase(String name) {
 +    super(name);
 +  }
 +  
 +  @Override
 +  protected final void preTearDown() throws Exception {
 +    
 +    SerializableRunnable tearDown = new SerializableRunnable("tearDown") {
 +      public void run() {
 +        Locator locator = (Locator) remoteObjects.get(LOCATOR_KEY);
 +        if(locator != null) {
 +          try {
 +            locator.stop();
 +          } catch(Exception e) {
 +            //do nothing
 +          }
 +        }
 +        
 +        Cache cache = (Cache) remoteObjects.get(CACHE_KEY);
 +        if(cache != null) {
 +          try {
 +            cache.close();
 +          } catch(Exception e) {
 +            //do nothing
 +          }
 +        }
 +        remoteObjects.clear();
 +        
 +      }
 +    };
 +    //We seem to like leaving the DS open if we can for
 +    //speed, but lets at least destroy our cache and locator.
 +    Invoke.invokeInEveryVM(tearDown);
 +    tearDown.run();
 +    
 +    postTearDownLocatorTestBase();
 +  }
 +  
 +  protected void postTearDownLocatorTestBase() throws Exception {
 +  }
 +  
 +  protected void startLocatorInVM(final VM vm, final int locatorPort, final String otherLocators) {
 +    vm.invoke(new SerializableRunnable("Create Locator") {
 +
 +      final String testName= getUniqueName();
 +      public void run() {
 +        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");
 +        try {
 +          File logFile = new File(testName + "-locator" + locatorPort
 +              + ".log");
 +          InetAddress bindAddr = null;
 +          try {
 +            bindAddr = InetAddress.getByName(NetworkUtils.getServerHostName(vm.getHost()));
 +          } catch (UnknownHostException uhe) {
 +            Assert.fail("While resolving bind address ", uhe);
 +          }
 +          Locator locator = Locator.startLocatorAndDS(locatorPort, logFile, bindAddr, props);
 +          remoteObjects.put(LOCATOR_KEY, locator);
 +        } catch (IOException ex) {
 +          Assert.fail("While starting locator on port " + locatorPort, ex);
 +        }
 +      }
 +    });
 +  }
 +  
 +  
 +  
 +  protected void stopLocatorInVM(VM vm) {
 +    vm.invoke(new SerializableRunnable("Stop Locator") {
 +      public void run() {
 +        Locator locator = (Locator) remoteObjects.remove(LOCATOR_KEY);
 +        locator.stop();
 +      }
 +    });
 +  }
 +  
 +  protected int startBridgeServerInVM(VM vm, String[] groups, String locators) {
 +    return startBridgeServerInVM(vm, groups, locators, new String[] {REGION_NAME});
 +  }
 +  
 +  protected int addCacheServerInVM(VM vm, final String[] groups) {
 +    SerializableCallable connect =
 +      new SerializableCallable("Add Bridge server") {
 +
 +      public Object call() throws Exception {
 +        Cache cache = (Cache) remoteObjects.get(CACHE_KEY);
 +        CacheServer server = cache.addCacheServer();
 +        final int serverPort = AvailablePortHelper.getRandomAvailableTCPPort();
 +        server.setPort(serverPort);
 +        server.setGroups(groups);
 +        server.start();
 +        return new Integer(serverPort);
 +      }
 +    };
 +    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  {
 +            Properties props = new Properties();
 +            props.setProperty(DistributionConfig.MCAST_PORT_NAME, String.valueOf(0));
 +            props.setProperty(DistributionConfig.LOCATORS_NAME, locators);
 +            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 attrs = factory.create();
 +            for(int i = 0; i < regions.length; i++) {
 +              cache.createRegion(regions[i], attrs);
 +            }
 +            CacheServer server = cache.addCacheServer();
 +            final int serverPort = AvailablePortHelper.getRandomAvailableTCPPort();
 +            server.setPort(serverPort);
 +            server.setGroups(groups);
 +            server.setLoadProbe(probe);
 +            server.start();
 +            
 +            remoteObjects.put(CACHE_KEY, cache);
 +            
 +            return new Integer(serverPort);
 +          }
 +        };
 +    Integer port = (Integer) vm.invoke(connect);
 +    return port.intValue();
 +  }
 +  
 +  protected int startBridgeServerWithEmbeddedLocator(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  {
 +            Properties props = new Properties();
 +            props.setProperty(DistributionConfig.MCAST_PORT_NAME, String.valueOf(0));
 +            props.setProperty(DistributionConfig.START_LOCATOR_NAME, locators);
 +            props.setProperty(DistributionConfig.LOCATORS_NAME, locators);
 +            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 attrs = factory.create();
 +            for(int i = 0; i < regions.length; i++) {
 +              cache.createRegion(regions[i], attrs);
 +            }
 +            CacheServer server = cache.addCacheServer();
 +            server.setGroups(groups);
 +            server.setLoadProbe(probe);
 +            final int serverPort = AvailablePortHelper.getRandomAvailableTCPPort();
 +            server.setPort(serverPort);
 +            server.start();
 +            
 +            remoteObjects.put(CACHE_KEY, cache);
 +            
 +            return new Integer(serverPort);
 +          }
 +        };
 +    Integer port = (Integer) vm.invoke(connect);
 +    return port.intValue();
 +  }
 +  
-   protected void  startBridgeClientInVM(VM vm, final String group, final String host, final int port) {
++  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) {
++  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) {
++  protected void  startBridgeClientInVM(VM vm, final Pool pool, final String[] regions) throws Exception {
 +    SerializableRunnable connect =
 +      new SerializableRunnable("Start bridge client") {
 +          public void run() {
 +            Properties props = new Properties();
 +            props.setProperty(DistributionConfig.MCAST_PORT_NAME, String.valueOf(0));
 +            props.setProperty(DistributionConfig.LOCATORS_NAME, "");
 +            DistributedSystem ds = getSystem(props);
 +            Cache cache = CacheFactory.create(ds);
 +            AttributesFactory factory = new AttributesFactory();
 +            factory.setScope(Scope.LOCAL);
 +//            factory.setEnableBridgeConflation(true);
 +//            factory.setDataPolicy(DataPolicy.NORMAL);
 +            factory.setPoolName(POOL_NAME);
 +            PoolFactoryImpl pf= (PoolFactoryImpl) PoolManager.createFactory();
 +            pf.init(pool);
 +            LocatorDiscoveryCallback locatorCallback = new MyLocatorCallback();
 +            remoteObjects.put(CALLBACK_KEY, locatorCallback);
 +            pf.setLocatorDiscoveryCallback(locatorCallback);
 +            pf.create(POOL_NAME);
 +
 +
 +            RegionAttributes attrs = factory.create();
 +            for(int i = 0; i < regions.length; i++) {
 +              cache.createRegion(regions[i], attrs);
 +            }
 +            
 +            remoteObjects.put(CACHE_KEY, cache);
 +          }
 +    };
 +    
 +    if(vm == null) {
 +      connect.run();
 +    } else {
 +      vm.invoke(connect);
 +    }
 +  }
 +  
 +  protected void stopBridgeMemberVM(VM vm) {
 +   vm.invoke(new SerializableRunnable("Stop bridge member") {
 +    public void run() {
 +      Cache cache = (Cache) remoteObjects.remove(CACHE_KEY);
 +      cache.close();
 +      disconnectFromDS();
 +    }
 +   });
 +  }
 +  
 +  public String getLocatorString(Host host, int locatorPort) {
 +    return getLocatorString(host, new int[] {locatorPort});
 +  }
 +  
 +  public String getLocatorString(Host host, int[] locatorPorts) {
 +    StringBuffer str = new StringBuffer();
 +    for(int i = 0; i < locatorPorts.length; i++) {
 +      str.append(NetworkUtils.getServerHostName(host))
 +          .append("[")
 +          .append(locatorPorts[i])
 +          .append("]");
 +      if(i < locatorPorts.length - 1) {
 +        str.append(",");
 +      }
 +    }
 +    
 +    return str.toString();
 +  }
 +  
 +  protected static class MyLocatorCallback extends LocatorDiscoveryCallbackAdapter {
 +
 +    private final Set discoveredLocators = new HashSet();
 +    private final Set removedLocators = new HashSet();
 +    
 +    public synchronized void locatorsDiscovered(List locators) {
 +      discoveredLocators.addAll(locators);
 +      notifyAll();
 +    }
 +
 +    public synchronized void locatorsRemoved(List locators) {
 +      removedLocators.addAll(locators);
 +      notifyAll();
 +    }
 +    
 +    public boolean waitForDiscovery(InetSocketAddress locator, long time) throws InterruptedException {
 +      return waitFor(discoveredLocators, locator, time);
 +    }
 +    
 +    public boolean waitForRemove(InetSocketAddress locator, long time) throws InterruptedException {
 +      return waitFor(removedLocators, locator, time);
 +    }
 +    
 +    private synchronized boolean waitFor(Set set, InetSocketAddress locator, long time) throws InterruptedException {
 +      long remaining = time;
 +      long endTime = System.currentTimeMillis() + time;
 +      while(!set.contains(locator) && remaining >= 0) {
 +        wait(remaining);
 +        remaining = endTime - System.currentTimeMillis(); 
 +      }
 +      return set.contains(locator);
 +    }
 +    
 +    public synchronized Set getDiscovered() {
 +      return new HashSet(discoveredLocators);
 +    }
 +    
 +  }
 +
 +}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5beaaedc/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/SSLNoClientAuthDUnitTest.java
----------------------------------------------------------------------
diff --cc geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/SSLNoClientAuthDUnitTest.java
index bb1cc09,0000000..e23fb76
mode 100644,000000..100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/SSLNoClientAuthDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/cache/client/internal/SSLNoClientAuthDUnitTest.java
@@@ -1,277 -1,0 +1,277 @@@
 +/*
 + * Licensed to the Apache Software Foundation (ASF) under one or more
 + * contributor license agreements.  See the NOTICE file distributed with
 + * this work for additional information regarding copyright ownership.
 + * The ASF licenses this file to You under the Apache License, Version 2.0
 + * (the "License"); you may not use this file except in compliance with
 + * the License.  You may obtain a copy of the License at
 + *
 + *      http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package com.gemstone.gemfire.cache.client.internal;
 +
 +import java.io.IOException;
 +import java.io.PrintWriter;
 +import java.io.StringWriter;
 +import java.util.Properties;
 +import com.gemstone.gemfire.cache.Cache;
 +import com.gemstone.gemfire.cache.CacheFactory;
 +import com.gemstone.gemfire.cache.Region;
 +import com.gemstone.gemfire.cache.RegionFactory;
 +import com.gemstone.gemfire.cache.RegionShortcut;
 +import com.gemstone.gemfire.cache.client.ClientCache;
 +import com.gemstone.gemfire.cache.client.ClientCacheFactory;
 +import com.gemstone.gemfire.cache.client.ClientRegionFactory;
 +import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
 +import com.gemstone.gemfire.cache.server.CacheServer;
 +import com.gemstone.gemfire.distributed.internal.DistributionConfig;
 +import com.gemstone.gemfire.internal.AvailablePortHelper;
 +import com.gemstone.gemfire.security.AuthenticationRequiredException;
 +import com.gemstone.gemfire.test.dunit.DistributedTestCase;
 +import com.gemstone.gemfire.test.dunit.Host;
 +import com.gemstone.gemfire.test.dunit.VM;
 +import com.gemstone.gemfire.util.test.TestUtil;
 +
 +/**
 + * Test for GEODE-396
 + */
 +public class SSLNoClientAuthDUnitTest extends DistributedTestCase {
 +  
 +  private static final long serialVersionUID = 1L;
 +  private Cache cache;
 +  private CacheServer cacheServer;
 +  private ClientCache clientCache;
 +  private int cacheServerPort;
 +  private String hostName;
 +  
 +  private static final String DEFAULT_STORE = "default.keystore";
 +  
 +  private static SSLNoClientAuthDUnitTest instance = new SSLNoClientAuthDUnitTest("SSLNoClientAuthDUnitTest");
 +  
 +  
 +  public void setUp() throws Exception {
 +    disconnectAllFromDS();
 +    super.setUp();
 +  }
 +
 +  public SSLNoClientAuthDUnitTest(String name) {
 +    super(name);
 +  }  
 +
 +  public Cache createCache(Properties props) throws Exception
 +  {
 +    props.setProperty("mcast-port", "0");
 +    props.setProperty("locators", "");
 +    cache = new CacheFactory(props).create();
 +    if (cache == null) {
 +      throw new Exception("CacheFactory.create() returned null ");
 +    }
 +    return cache;
 +  }
 +  
 +  private void createServer() throws IOException{
 +    cacheServerPort = AvailablePortHelper.getRandomAvailableTCPPort();
 +    cacheServer = cache.addCacheServer();
 +    cacheServer.setPort(cacheServerPort);
 +    cacheServer.start();
 +    hostName = cacheServer.getHostnameForClients();
 +  }
 +  
 +  public int getCacheServerPort(){
 +    return cacheServerPort;
 +  }
 +  
 +  public String getCacheServerHost(){
 +    return hostName;
 +  }
 +  
 +  public void stopCacheServer(){
 +    this.cacheServer.stop();
 +  }
 +  
 +  
 +  @SuppressWarnings("rawtypes")
 +  public void setUpServerVM(boolean cacheServerSslenabled) throws Exception {
 +    Properties gemFireProps = new Properties();
 +
 +    String cacheServerSslprotocols = "any";
 +    String cacheServerSslciphers = "any";
 +    boolean cacheServerSslRequireAuth = false;
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_ENABLED_NAME,
 +        String.valueOf(cacheServerSslenabled));
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_PROTOCOLS_NAME,
 +        cacheServerSslprotocols);
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_CIPHERS_NAME,
 +        cacheServerSslciphers);
 +    gemFireProps.put(
 +        DistributionConfig.SERVER_SSL_REQUIRE_AUTHENTICATION_NAME,
 +        String.valueOf(cacheServerSslRequireAuth));
 +
 +    String keyStore = TestUtil.getResourcePath(SSLNoClientAuthDUnitTest.class, DEFAULT_STORE);
 +    String trustStore = TestUtil.getResourcePath(SSLNoClientAuthDUnitTest.class, DEFAULT_STORE);
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_TYPE_NAME, "jks");
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_NAME, keyStore);
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_PASSWORD_NAME, "password");
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_NAME, trustStore);
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_PASSWORD_NAME, "password");
 +    
 +    StringWriter sw = new StringWriter();
 +    PrintWriter writer = new PrintWriter(sw);
 +    gemFireProps.list(writer);
 +    System.out.println("Starting cacheserver ds with following properties \n" + sw);
 +    createCache(gemFireProps);
 +    
 +    RegionFactory factory = cache.createRegionFactory(RegionShortcut.REPLICATE);
 +    Region r = factory.create("serverRegion");
 +    r.put("serverkey", "servervalue");
 +  }
 +  
 +  public void setUpClientVM(String host, int port,
 +      boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth,
 +      String keyStore, String trustStore) {
 +
 +    Properties gemFireProps = new Properties();
 +
 +    String cacheServerSslprotocols = "any";
 +    String cacheServerSslciphers = "any";
 +
 +    String keyStorePath = TestUtil.getResourcePath(SSLNoClientAuthDUnitTest.class, keyStore);
 +    String trustStorePath = TestUtil.getResourcePath(SSLNoClientAuthDUnitTest.class, trustStore);
 +    //using new server-ssl-* properties
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_ENABLED_NAME,
 +        String.valueOf(cacheServerSslenabled));
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_PROTOCOLS_NAME,
 +        cacheServerSslprotocols);
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_CIPHERS_NAME,
 +        cacheServerSslciphers);
 +    gemFireProps.put(
 +        DistributionConfig.SERVER_SSL_REQUIRE_AUTHENTICATION_NAME,
 +        String.valueOf(cacheServerSslRequireAuth));
 +
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_TYPE_NAME, "jks");
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_NAME, keyStorePath);
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_KEYSTORE_PASSWORD_NAME, "password");
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_NAME, trustStorePath);
 +    gemFireProps.put(DistributionConfig.SERVER_SSL_TRUSTSTORE_PASSWORD_NAME, "password");
 +
 +    StringWriter sw = new StringWriter();
 +    PrintWriter writer = new PrintWriter(sw);
 +    gemFireProps.list(writer);
 +    System.out.println("Starting client ds with following properties \n" + sw.getBuffer());
 +    
 +    ClientCacheFactory clientCacheFactory = new ClientCacheFactory(gemFireProps);
 +    clientCacheFactory.addPoolServer(host, port);
 +    clientCache = clientCacheFactory.create();
 +    
 +    ClientRegionFactory<String,String> regionFactory = clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY);
 +    Region<String, String> region = regionFactory.create("serverRegion");  
 +    assertNotNull(region);
 +  }
 +  
 +  public void doClientRegionTest(){
 +    Region<String, String> region = clientCache.getRegion("serverRegion");
 +    assertEquals("servervalue",region.get("serverkey"));
 +    region.put("clientkey", "clientvalue");
 +    assertEquals("clientvalue",region.get("clientkey"));
 +  }
 +  
 +  public void doServerRegionTest(){
 +    Region<String, String> region = cache.getRegion("serverRegion");
 +    assertEquals("servervalue",region.get("serverkey"));    
 +    assertEquals("clientvalue",region.get("clientkey"));
 +  }
 +  
 +  
 +  public static void setUpServerVMTask(boolean cacheServerSslenabled) throws Exception{
 +    instance.setUpServerVM(cacheServerSslenabled);
 +  }
 +  
 +  public static void createServerTask() throws Exception {
 +    instance.createServer();
 +  }
 +  
 +  public static void setUpClientVMTask(String host, int port,
 +      boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth, String keyStore, String trustStore)
 +      throws Exception {
 +    instance.setUpClientVM(host, port, cacheServerSslenabled, cacheServerSslRequireAuth, keyStore, trustStore);
 +  }
 +  
 +  public static void doClientRegionTestTask() {
 +    instance.doClientRegionTest();
 +  }
 +  
 +  public static void doServerRegionTestTask() {
 +    instance.doServerRegionTest();
 +  }
 +  
 +  public static Object[] getCacheServerEndPointTask() {
 +    Object[] array = new Object[2];
 +    array[0] = instance.getCacheServerHost();
 +    array[1] = instance.getCacheServerPort();
 +    return array;
 +  }
 +  
 +  public static void closeCacheTask(){
 +    if (instance != null && instance.cache != null) {
 +      instance.cache.close();
 +    }
 +  }
 +  
 +  public static void closeClientCacheTask(){
 +    if (instance != null && instance.clientCache != null) {
 +      instance.clientCache.close();
 +    }
 +  }
 +  
 +  /**
 +   * Test for GEODE-396
 +   */
 +  public void testSSLServerWithNoAuth() throws Exception {
 +    final Host host = Host.getHost(0);
 +    VM serverVM = host.getVM(1);
 +    VM clientVM = host.getVM(2);
 +
 +    boolean cacheServerSslenabled = true;
 +    boolean cacheClientSslenabled = true;
 +    boolean cacheClientSslRequireAuth = true;
 +
-     serverVM.invoke(SSLNoClientAuthDUnitTest.class, "setUpServerVMTask", new Object[]{cacheServerSslenabled});
-     serverVM.invoke(SSLNoClientAuthDUnitTest.class, "createServerTask");
++    serverVM.invoke(() -> SSLNoClientAuthDUnitTest.setUpServerVMTask(cacheServerSslenabled));
++    serverVM.invoke(() -> SSLNoClientAuthDUnitTest.createServerTask());
 +
-     Object array[] = (Object[])serverVM.invoke(SSLNoClientAuthDUnitTest.class, "getCacheServerEndPointTask"); 
++    Object array[] = (Object[])serverVM.invoke(() -> SSLNoClientAuthDUnitTest.getCacheServerEndPointTask()); 
 +    String hostName = (String)array[0];
 +    int port = (Integer) array[1];
 +    Object params[] = new Object[6];
 +    params[0] = hostName;
 +    params[1] = port;
 +    params[2] = cacheClientSslenabled;
 +    params[3] = cacheClientSslRequireAuth;
 +    params[4] = DEFAULT_STORE;
 +    params[5] = DEFAULT_STORE;
 +    //getLogWriter().info("Starting client with server endpoint " + hostName + ":" + port);
 +    try {
 +      clientVM.invoke(SSLNoClientAuthDUnitTest.class, "setUpClientVMTask", params);
-       clientVM.invoke(SSLNoClientAuthDUnitTest.class, "doClientRegionTestTask");
-       serverVM.invoke(SSLNoClientAuthDUnitTest.class, "doServerRegionTestTask");
++      clientVM.invoke(() -> SSLNoClientAuthDUnitTest.doClientRegionTestTask());
++      serverVM.invoke(() -> SSLNoClientAuthDUnitTest.doServerRegionTestTask());
 +    } catch (Exception rmiException) {
 +      Throwable e = rmiException.getCause();
 +      //getLogWriter().info("ExceptionCause at clientVM " + e);
 +      fail("Unexpected Exception " + e);
 +    }
 +  }
 +  
 +  @Override
 +  protected final void preTearDown() throws Exception {
 +    final Host host = Host.getHost(0);
 +    VM serverVM = host.getVM(1);
 +    VM clientVM = host.getVM(2);
-     clientVM.invoke(SSLNoClientAuthDUnitTest.class, "closeClientCacheTask");
-     serverVM.invoke(SSLNoClientAuthDUnitTest.class, "closeCacheTask");
++    clientVM.invoke(() -> SSLNoClientAuthDUnitTest.closeClientCacheTask());
++    serverVM.invoke(() -> SSLNoClientAuthDUnitTest.closeCacheTask());
 +  }
 +}


Mime
View raw message