geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [3/3] geode git commit: GEODE-3404: add FlakyTest category to entire test class
Date Tue, 29 Aug 2017 21:33:04 GMT
GEODE-3404: add FlakyTest category to entire test class


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

Branch: refs/heads/develop
Commit: c287d987e153c86b8e2f7ed63138957e89c3fdf7
Parents: 00a0490
Author: Kirk Lund <klund@apache.org>
Authored: Mon Aug 28 14:51:30 2017 -0700
Committer: Kirk Lund <klund@apache.org>
Committed: Tue Aug 29 14:32:53 2017 -0700

----------------------------------------------------------------------
 .../DurableClientCommandsDUnitTest.java         | 279 ++++++++++---------
 1 file changed, 147 insertions(+), 132 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/c287d987/geode-cq/src/test/java/org/apache/geode/management/internal/cli/commands/DurableClientCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-cq/src/test/java/org/apache/geode/management/internal/cli/commands/DurableClientCommandsDUnitTest.java
b/geode-cq/src/test/java/org/apache/geode/management/internal/cli/commands/DurableClientCommandsDUnitTest.java
index e15d2cc..ef3b4a7 100644
--- a/geode-cq/src/test/java/org/apache/geode/management/internal/cli/commands/DurableClientCommandsDUnitTest.java
+++ b/geode-cq/src/test/java/org/apache/geode/management/internal/cli/commands/DurableClientCommandsDUnitTest.java
@@ -14,15 +14,38 @@
  */
 package org.apache.geode.management.internal.cli.commands;
 
-import org.apache.geode.cache.*;
+import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_ID;
+import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_TIMEOUT;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.test.dunit.Assert.assertTrue;
+import static org.apache.geode.test.dunit.DistributedTestUtils.getDUnitLocatorPort;
+import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
+import static org.apache.geode.test.dunit.NetworkUtils.getServerHostName;
+
+import java.util.Properties;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.AttributesFactory;
+import org.apache.geode.cache.CacheException;
+import org.apache.geode.cache.DataPolicy;
+import org.apache.geode.cache.PartitionAttributesFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.Scope;
 import org.apache.geode.cache.client.ClientCache;
 import org.apache.geode.cache.client.ClientCacheFactory;
-import org.apache.geode.cache.query.*;
+import org.apache.geode.cache.query.CqAttributesFactory;
+import org.apache.geode.cache.query.CqException;
+import org.apache.geode.cache.query.CqExistsException;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.RegionNotFoundException;
 import org.apache.geode.cache.query.data.Portfolio;
 import org.apache.geode.cache.server.CacheServer;
 import org.apache.geode.cache30.CacheSerializableRunnable;
 import org.apache.geode.internal.cache.DistributedRegion;
-import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.internal.cache.PartitionedRegion;
 import org.apache.geode.internal.cache.tier.sockets.CacheServerTestUtil;
 import org.apache.geode.management.cli.Result.Status;
@@ -31,29 +54,26 @@ import org.apache.geode.management.internal.cli.result.CommandResult;
 import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
 import org.apache.geode.test.dunit.Host;
 import org.apache.geode.test.dunit.SerializableCallable;
+import org.apache.geode.test.dunit.SerializableRunnable;
 import org.apache.geode.test.dunit.VM;
 import org.apache.geode.test.junit.categories.DistributedTest;
 import org.apache.geode.test.junit.categories.FlakyTest;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.util.Properties;
 
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.apache.geode.test.dunit.Assert.assertTrue;
-import static org.apache.geode.test.dunit.DistributedTestUtils.getDUnitLocatorPort;
-import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
-import static org.apache.geode.test.dunit.NetworkUtils.getServerHostName;
-
-@Category(DistributedTest.class)
+@Category({DistributedTest.class, FlakyTest.class}) // GEODE-1705, GEODE-3404, GEODE-3359
 public class DurableClientCommandsDUnitTest extends CliCommandTestBase {
 
-  private static final long serialVersionUID = 1L;
-  final String regionName = "stocks";
-  final String cq1 = "cq1";
-  final String cq2 = "cq2";
-  final String cq3 = "cq3";
-  final String clientName = "dc1";
+  private static final String REGION_NAME = "stocks";
+  private static final String CQ1 = "cq1";
+  private static final String CQ2 = "cq2";
+  private static final String CQ3 = "cq3";
+  private static final String CLIENT_NAME = "dc1";
+
+  @Override
+  public final void postTearDownCacheTestCase() throws Exception {
+    Host.getHost(0).getVM(0).invoke(() -> CacheServerTestUtil.closeCache());
+    Host.getHost(0).getVM(1).invoke(() -> CacheServerTestUtil.closeCache());
+    Host.getHost(0).getVM(2).invoke(() -> CacheServerTestUtil.closeCache());
+  }
 
   @Test
   public void testListDurableClientCqs() throws Exception {
@@ -61,23 +81,23 @@ public class DurableClientCommandsDUnitTest extends CliCommandTestBase
{
     setupCqs();
 
     CommandStringBuilder csb = new CommandStringBuilder(CliStrings.LIST_DURABLE_CQS);
-    csb.addOption(CliStrings.LIST_DURABLE_CQS__DURABLECLIENTID, clientName);
+    csb.addOption(CliStrings.LIST_DURABLE_CQS__DURABLECLIENTID, CLIENT_NAME);
     String commandString = csb.toString();
     writeToLog("Command String :\n ", commandString);
     CommandResult commandResult = executeCommand(commandString);
     String resultAsString = commandResultToString(commandResult);
     writeToLog("Command Result :\n", resultAsString);
     assertTrue(Status.OK.equals(commandResult.getStatus()));
-    assertTrue(resultAsString.contains(cq1));
-    assertTrue(resultAsString.contains(cq2));
-    assertTrue(resultAsString.contains(cq3));
+    assertTrue(resultAsString.contains(CQ1));
+    assertTrue(resultAsString.contains(CQ2));
+    assertTrue(resultAsString.contains(CQ3));
 
-    closeCq(cq1);
-    closeCq(cq2);
-    closeCq(cq3);
+    closeCq(CQ1);
+    closeCq(CQ2);
+    closeCq(CQ3);
 
     csb = new CommandStringBuilder(CliStrings.LIST_DURABLE_CQS);
-    csb.addOption(CliStrings.LIST_DURABLE_CQS__DURABLECLIENTID, clientName);
+    csb.addOption(CliStrings.LIST_DURABLE_CQS__DURABLECLIENTID, CLIENT_NAME);
     commandString = csb.toString();
     writeToLog("Command String :\n ", commandString);
     commandResult = executeCommand(commandString);
@@ -85,7 +105,7 @@ public class DurableClientCommandsDUnitTest extends CliCommandTestBase
{
     writeToLog("Command Result :\n", resultAsString);
     assertTrue(Status.ERROR.equals(commandResult.getStatus()));
     String errorMessage =
-        CliStrings.format(CliStrings.LIST_DURABLE_CQS__NO__CQS__FOR__CLIENT, clientName);
+        CliStrings.format(CliStrings.LIST_DURABLE_CQS__NO__CQS__FOR__CLIENT, CLIENT_NAME);
     assertTrue(resultAsString.contains(errorMessage));
   }
 
@@ -96,17 +116,20 @@ public class DurableClientCommandsDUnitTest extends CliCommandTestBase
{
     closeDurableClient();
 
     CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CLOSE_DURABLE_CLIENTS);
-    csb.addOption(CliStrings.CLOSE_DURABLE_CLIENTS__CLIENT__ID, clientName);
+    csb.addOption(CliStrings.CLOSE_DURABLE_CLIENTS__CLIENT__ID, CLIENT_NAME);
     String commandString = csb.toString();
+
     long giveUpTime = System.currentTimeMillis() + 20000;
     CommandResult commandResult = null;
     String resultAsString = null;
+
     do {
       writeToLog("Command String : ", commandString);
       commandResult = executeCommand(commandString);
       resultAsString = commandResultToString(commandResult);
     } while (resultAsString.contains("Cannot close a running durable client")
         && giveUpTime > System.currentTimeMillis());
+
     writeToLog("Command Result :\n", resultAsString);
     assertTrue(Status.OK.equals(commandResult.getStatus()));
 
@@ -116,11 +139,10 @@ public class DurableClientCommandsDUnitTest extends CliCommandTestBase
{
     resultAsString = commandResultToString(commandResult);
     writeToLog("Command Result :\n", resultAsString);
     assertTrue(Status.ERROR.equals(commandResult.getStatus()));
-    String errorMessage = CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, clientName);
+    String errorMessage = CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, CLIENT_NAME);
     assertTrue(resultAsString.contains(errorMessage));
   }
 
-  @Category(FlakyTest.class) // GEODE-1705
   @Test
   public void testCloseDurableCQ() throws Exception {
     setupSystem();
@@ -129,8 +151,8 @@ public class DurableClientCommandsDUnitTest extends CliCommandTestBase
{
     closeDurableClient();
 
     CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CLOSE_DURABLE_CQS);
-    csb.addOption(CliStrings.CLOSE_DURABLE_CQS__DURABLE__CLIENT__ID, clientName);
-    csb.addOption(CliStrings.CLOSE_DURABLE_CQS__NAME, cq1);
+    csb.addOption(CliStrings.CLOSE_DURABLE_CQS__DURABLE__CLIENT__ID, CLIENT_NAME);
+    csb.addOption(CliStrings.CLOSE_DURABLE_CQS__NAME, CQ1);
     String commandString = csb.toString();
     writeToLog("Command String : ", commandString);
     CommandResult commandResult = executeCommand(commandString);
@@ -139,8 +161,8 @@ public class DurableClientCommandsDUnitTest extends CliCommandTestBase
{
     assertTrue(Status.OK.equals(commandResult.getStatus()));
 
     csb = new CommandStringBuilder(CliStrings.CLOSE_DURABLE_CQS);
-    csb.addOption(CliStrings.CLOSE_DURABLE_CQS__DURABLE__CLIENT__ID, clientName);
-    csb.addOption(CliStrings.CLOSE_DURABLE_CQS__NAME, cq1);
+    csb.addOption(CliStrings.CLOSE_DURABLE_CQS__DURABLE__CLIENT__ID, CLIENT_NAME);
+    csb.addOption(CliStrings.CLOSE_DURABLE_CQS__NAME, CQ1);
     commandString = csb.toString();
     writeToLog("Command String : ", commandString);
     commandResult = executeCommand(commandString);
@@ -154,10 +176,10 @@ public class DurableClientCommandsDUnitTest extends CliCommandTestBase
{
   public void testCountSubscriptionQueueSize() throws Exception {
     setupSystem();
     setupCqs();
-    doPuts(regionName, Host.getHost(0).getVM(1));
+    doPuts(REGION_NAME, Host.getHost(0).getVM(1));
 
     CommandStringBuilder csb = new CommandStringBuilder(CliStrings.COUNT_DURABLE_CQ_EVENTS);
-    csb.addOption(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CLIENT__ID, clientName);
+    csb.addOption(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CLIENT__ID, CLIENT_NAME);
     String commandString = csb.toString();
     writeToLog("Command String : ", commandString);
     CommandResult commandResult = executeCommand(commandString);
@@ -167,8 +189,8 @@ public class DurableClientCommandsDUnitTest extends CliCommandTestBase
{
     assertTrue(resultAsString.contains("4"));
 
     csb = new CommandStringBuilder(CliStrings.COUNT_DURABLE_CQ_EVENTS);
-    csb.addOption(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CLIENT__ID, clientName);
-    csb.addOption(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CQ__NAME, cq3);
+    csb.addOption(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CLIENT__ID, CLIENT_NAME);
+    csb.addOption(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CQ__NAME, CQ3);
     commandString = csb.toString();
     writeToLog("Command String : ", commandString);
     commandResult = executeCommand(commandString);
@@ -177,14 +199,14 @@ public class DurableClientCommandsDUnitTest extends CliCommandTestBase
{
     assertTrue(Status.OK.equals(commandResult.getStatus()));
 
     // CLOSE all the cqs
-    closeCq(cq1);
-    closeCq(cq2);
-    closeCq(cq3);
+    closeCq(CQ1);
+    closeCq(CQ2);
+    closeCq(CQ3);
 
     // Run the commands again
     csb = new CommandStringBuilder(CliStrings.COUNT_DURABLE_CQ_EVENTS);
-    csb.addOption(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CLIENT__ID, clientName);
-    csb.addOption(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CQ__NAME, cq1);
+    csb.addOption(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CLIENT__ID, CLIENT_NAME);
+    csb.addOption(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CQ__NAME, CQ1);
     commandString = csb.toString();
     writeToLog("Command String : ", commandString);
     commandResult = executeCommand(commandString);
@@ -192,11 +214,11 @@ public class DurableClientCommandsDUnitTest extends CliCommandTestBase
{
     writeToLog("Command Result :\n", resultAsString);
     assertTrue(Status.ERROR.equals(commandResult.getStatus()));
     String errorMessage = CliStrings
-        .format(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE_CQ_NOT_FOUND, clientName, cq1);
+        .format(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE_CQ_NOT_FOUND, CLIENT_NAME, CQ1);
     assertTrue(resultAsString.contains(errorMessage));
 
     csb = new CommandStringBuilder(CliStrings.COUNT_DURABLE_CQ_EVENTS);
-    csb.addOption(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CLIENT__ID, clientName);
+    csb.addOption(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CLIENT__ID, CLIENT_NAME);
     commandString = csb.toString();
     writeToLog("Command String : ", commandString);
     commandResult = executeCommand(commandString);
@@ -209,8 +231,9 @@ public class DurableClientCommandsDUnitTest extends CliCommandTestBase
{
 
     // Close the client
     csb = new CommandStringBuilder(CliStrings.CLOSE_DURABLE_CLIENTS);
-    csb.addOption(CliStrings.CLOSE_DURABLE_CLIENTS__CLIENT__ID, clientName);
+    csb.addOption(CliStrings.CLOSE_DURABLE_CLIENTS__CLIENT__ID, CLIENT_NAME);
     commandString = csb.toString();
+
     // since it can take the server a bit to know that the client has disconnected
     // we loop here
     long giveUpTime = System.currentTimeMillis() + 20000;
@@ -220,12 +243,13 @@ public class DurableClientCommandsDUnitTest extends CliCommandTestBase
{
       resultAsString = commandResultToString(commandResult);
     } while (resultAsString.contains("Cannot close a running durable client")
         && giveUpTime > System.currentTimeMillis());
+
     writeToLog("Command Result :\n", resultAsString);
     assertTrue("failed executing" + commandString + "; result = " + resultAsString,
         Status.OK.equals(commandResult.getStatus()));
 
     csb = new CommandStringBuilder(CliStrings.COUNT_DURABLE_CQ_EVENTS);
-    csb.addOption(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CLIENT__ID, clientName);
+    csb.addOption(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CLIENT__ID, CLIENT_NAME);
     commandString = csb.toString();
     writeToLog("Command String : ", commandString);
     commandResult = executeCommand(commandString);
@@ -233,7 +257,7 @@ public class DurableClientCommandsDUnitTest extends CliCommandTestBase
{
     writeToLog("Command Result :\n", resultAsString);
     assertTrue(Status.ERROR.equals(commandResult.getStatus()));
     assertTrue(resultAsString
-        .contains(CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, clientName)));
+        .contains(CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, CLIENT_NAME)));
   }
 
   private void writeToLog(String text, String resultAsString) {
@@ -244,12 +268,12 @@ public class DurableClientCommandsDUnitTest extends CliCommandTestBase
{
     disconnectAllFromDS();
     setUpJmxManagerOnVm0ThenConnect(getServerProperties());
 
-    final VM manager = Host.getHost(0).getVM(0);
-    final VM server1 = Host.getHost(0).getVM(1);
-    final VM client1 = Host.getHost(0).getVM(2);
+    VM manager = Host.getHost(0).getVM(0);
+    VM server1 = Host.getHost(0).getVM(1);
+    VM client1 = Host.getHost(0).getVM(2);
 
-    int listeningPort = startCacheServer(server1, 0, false, regionName);
-    startDurableClient(client1, server1, listeningPort, clientName, "300");
+    int listeningPort = startCacheServer(server1, 0, false, REGION_NAME);
+    startDurableClient(client1, server1, listeningPort, CLIENT_NAME, "300");
   }
 
   /**
@@ -258,99 +282,94 @@ public class DurableClientCommandsDUnitTest extends CliCommandTestBase
{
    * @param cqName , Name of the cq which is to be close.
    */
   private void closeCq(final String cqName) {
-    final VM vm2 = Host.getHost(0).getVM(2);
+    VM vm2 = Host.getHost(0).getVM(2);
     vm2.invoke(new SerializableCallable() {
+      @Override
       public Object call() {
         QueryService qs = getCache().getQueryService();
         CqAttributesFactory cqAf = new CqAttributesFactory();
+
         try {
           qs.getCq(cqName).close();
-
         } catch (CqException e) {
-          e.printStackTrace();
-          return false;
+          throw new RuntimeException(e);
         }
+
         return true;
       }
     });
   }
 
   private void setupCqs() {
-    final VM vm2 = Host.getHost(0).getVM(2);
+    VM vm2 = Host.getHost(0).getVM(2);
+
     vm2.invoke(new SerializableCallable() {
+      @Override
       public Object call() {
         QueryService qs = getCache().getQueryService();
         CqAttributesFactory cqAf = new CqAttributesFactory();
+
         try {
-          qs.newCq(cq1, "select * from /" + regionName, cqAf.create(), true).execute();
-          qs.newCq(cq2, "select * from /" + regionName + " where id = 1", cqAf.create(),
true)
+          qs.newCq(CQ1, "select * from /" + REGION_NAME, cqAf.create(), true).execute();
+          qs.newCq(CQ2, "select * from /" + REGION_NAME + " where id = 1", cqAf.create(),
true)
               .execute();
-          qs.newCq(cq3, "select * from /" + regionName + " where id > 2", cqAf.create(),
true)
+          qs.newCq(CQ3, "select * from /" + REGION_NAME + " where id > 2", cqAf.create(),
true)
               .execute();
-        } catch (CqException e) {
-          e.printStackTrace();
-          return false;
-        } catch (CqExistsException e) {
-          e.printStackTrace();
-
-          return false;
-        } catch (RegionNotFoundException e) {
-          e.printStackTrace();
-
-          return false;
+        } catch (CqException | CqExistsException | RegionNotFoundException e) {
+          throw new RuntimeException(e);
         }
+
         return true;
       }
     });
   }
 
-  private int startCacheServer(VM server, final int port, final boolean createPR,
-      final String regionName) throws Exception {
-
-    Integer listeningPort = (Integer) server.invoke(new SerializableCallable() {
-      public Object call() throws Exception {
-        getSystem(getServerProperties());
-
-        GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
-        AttributesFactory factory = new AttributesFactory();
-        if (createPR) {
-          PartitionAttributesFactory paf = new PartitionAttributesFactory();
-          paf.setRedundantCopies(1);
-          paf.setTotalNumBuckets(11);
-          factory.setPartitionAttributes(paf.create());
-        } else {
-          factory.setScope(Scope.DISTRIBUTED_ACK);
-          factory.setDataPolicy(DataPolicy.REPLICATE);
-        }
-        Region region = createRootRegion(regionName, factory.create());
-        if (createPR) {
-          assertTrue(region instanceof PartitionedRegion);
-        } else {
-          assertTrue(region instanceof DistributedRegion);
-        }
-        CacheServer cacheServer = getCache().addCacheServer();
-        cacheServer.setPort(port);
-        cacheServer.start();
+  private int startCacheServer(final VM serverVM, final int port, final boolean createPR,
+      final String regionName) {
+    return serverVM.invoke(() -> {
+      getSystem(getServerProperties());
+
+      InternalCache cache = getCache();
+      AttributesFactory factory = new AttributesFactory();
+
+      if (createPR) {
+        PartitionAttributesFactory paf = new PartitionAttributesFactory();
+        paf.setRedundantCopies(1);
+        paf.setTotalNumBuckets(11);
+        factory.setPartitionAttributes(paf.create());
+      } else {
+        factory.setScope(Scope.DISTRIBUTED_ACK);
+        factory.setDataPolicy(DataPolicy.REPLICATE);
+      }
 
-        return cacheServer.getPort();
+      Region region = createRootRegion(regionName, factory.create());
+      if (createPR) {
+        assertTrue(region instanceof PartitionedRegion);
+      } else {
+        assertTrue(region instanceof DistributedRegion);
       }
-    });
 
-    return listeningPort.intValue();
+      CacheServer cacheServer = getCache().addCacheServer();
+      cacheServer.setPort(port);
+      cacheServer.start();
+
+      return cacheServer.getPort();
+    });
   }
 
-  private void startDurableClient(VM client, final VM server, final int port,
+  private void startDurableClient(final VM clientVM, final VM serverVM, final int port,
       final String durableClientId, final String durableClientTimeout) {
-    client.invoke(new CacheSerializableRunnable("Start client") {
+    clientVM.invoke(new CacheSerializableRunnable("Start client") {
+      @Override
       public void run2() throws CacheException {
         Properties props = getClientProps(durableClientId, durableClientTimeout);
         getSystem(props);
 
-        final ClientCacheFactory ccf = new ClientCacheFactory(props);
-        ccf.addPoolServer(getServerHostName(server.getHost()), port);
+        ClientCacheFactory ccf = new ClientCacheFactory(props);
+        ccf.addPoolServer(getServerHostName(serverVM.getHost()), port);
         ccf.setPoolSubscriptionEnabled(true);
 
-        ClientCache cache = (ClientCache) getClientCache(ccf);
+        ClientCache cache = getClientCache(ccf);
       }
     });
   }
@@ -358,11 +377,13 @@ public class DurableClientCommandsDUnitTest extends CliCommandTestBase
{
   /**
    * Does few puts on the region on the server
    */
-  private void doPuts(final String regionName, VM server) {
-    server.invoke(new SerializableCallable() {
-      public Object call() throws Exception {
-        GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
+  private void doPuts(final String regionName, final VM serverVM) {
+    serverVM.invoke(new SerializableRunnable() {
+      @Override
+      public void run() {
+        InternalCache cache = getCache();
         Region region = cache.getRegion(regionName);
+
         Portfolio p1 = new Portfolio();
         p1.ID = 1;
         p1.names = new String[] {"AAPL", "VMW"};
@@ -383,15 +404,16 @@ public class DurableClientCommandsDUnitTest extends CliCommandTestBase
{
         region.put("p2", p2);
         region.put("p3", p3);
         region.put("p4", p4);
-        return null;
       }
     });
   }
 
   // Closes the durable-client from the client side.
   private void closeDurableClient() {
-    final VM client = Host.getHost(0).getVM(2);
-    client.invoke(new CacheSerializableRunnable("Stop client") {
+    VM clientVM = Host.getHost(0).getVM(2);
+
+    clientVM.invoke(new CacheSerializableRunnable("Stop client") {
+      @Override
       public void run2() throws CacheException {
         ClientCacheFactory.getAnyInstance().close(true);
       }
@@ -399,24 +421,17 @@ public class DurableClientCommandsDUnitTest extends CliCommandTestBase
{
   }
 
   protected Properties getClientProps(String durableClientId, String durableClientTimeout)
{
-    Properties p = new Properties();
-    p.setProperty(MCAST_PORT, "0");
-    p.setProperty(LOCATORS, "");
-    p.setProperty(DURABLE_CLIENT_ID, durableClientId);
-    p.setProperty(DURABLE_CLIENT_TIMEOUT, String.valueOf(durableClientTimeout));
-    return p;
+    Properties config = new Properties();
+    config.setProperty(MCAST_PORT, "0");
+    config.setProperty(LOCATORS, "");
+    config.setProperty(DURABLE_CLIENT_ID, durableClientId);
+    config.setProperty(DURABLE_CLIENT_TIMEOUT, String.valueOf(durableClientTimeout));
+    return config;
   }
 
   protected Properties getServerProperties() {
-    Properties p = new Properties();
-    p.setProperty(LOCATORS, "localhost[" + getDUnitLocatorPort() + "]");
-    return p;
-  }
-
-  @Override
-  public final void postTearDownCacheTestCase() throws Exception {
-    Host.getHost(0).getVM(0).invoke(() -> CacheServerTestUtil.closeCache());
-    Host.getHost(0).getVM(1).invoke(() -> CacheServerTestUtil.closeCache());
-    Host.getHost(0).getVM(2).invoke(() -> CacheServerTestUtil.closeCache());
+    Properties config = new Properties();
+    config.setProperty(LOCATORS, "localhost[" + getDUnitLocatorPort() + "]");
+    return config;
   }
 }


Mime
View raw message