You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2016/03/18 00:25:51 UTC

incubator-geode git commit: Extend the JUnit3 versions of CacheTestCase and DistributedTestCase

Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-1050 893dc86b9 -> d41e74d08


Extend the JUnit3 versions of CacheTestCase and DistributedTestCase


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

Branch: refs/heads/feature/GEODE-1050
Commit: d41e74d08a5b7850dfe395032bfb904e58572a7e
Parents: 893dc86
Author: Kirk Lund <kl...@apache.org>
Authored: Thu Mar 17 16:25:15 2016 -0700
Committer: Kirk Lund <kl...@apache.org>
Committed: Thu Mar 17 16:25:15 2016 -0700

----------------------------------------------------------------------
 .../gemstone/gemfire/cache30/CacheTestCase.java | 530 +------------------
 .../gemfire/test/dunit/DistributedTestCase.java |  47 +-
 2 files changed, 4 insertions(+), 573 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d41e74d0/geode-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java
index 71bc7b8..b326c58 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java
@@ -16,46 +16,8 @@
  */
 package com.gemstone.gemfire.cache30;
 
-import java.io.File;
-import java.io.FileWriter;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Map;
-import java.util.Properties;
-
-import com.gemstone.gemfire.cache.AttributesFactory;
 import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.CacheException;
-import com.gemstone.gemfire.cache.CacheExistsException;
-import com.gemstone.gemfire.cache.CacheFactory;
-import com.gemstone.gemfire.cache.CacheTransactionManager;
-import com.gemstone.gemfire.cache.ExpirationAttributes;
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.RegionAttributes;
-import com.gemstone.gemfire.cache.RegionExistsException;
-import com.gemstone.gemfire.cache.TimeoutException;
-import com.gemstone.gemfire.cache.client.ClientCache;
-import com.gemstone.gemfire.cache.client.ClientCacheFactory;
-import com.gemstone.gemfire.cache.client.PoolManager;
-import com.gemstone.gemfire.distributed.internal.DistributionMessageObserver;
-import com.gemstone.gemfire.internal.FileUtil;
-import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
-import com.gemstone.gemfire.internal.cache.InternalRegionArguments;
-import com.gemstone.gemfire.internal.cache.LocalRegion;
-import com.gemstone.gemfire.internal.cache.xmlcache.CacheCreation;
-import com.gemstone.gemfire.internal.cache.xmlcache.CacheXmlGenerator;
-import com.gemstone.gemfire.internal.logging.LogService;
-import com.gemstone.gemfire.test.dunit.Assert;
-import com.gemstone.gemfire.test.dunit.IgnoredException;
-import com.gemstone.gemfire.test.dunit.Invoke;
-import com.gemstone.gemfire.test.dunit.LogWriterUtils;
-import com.gemstone.gemfire.test.dunit.VM;
-import com.gemstone.gemfire.test.dunit.Wait;
-import com.gemstone.gemfire.test.dunit.WaitCriterion;
-import com.gemstone.gemfire.test.dunit.cache.internal.CacheTestFixture;
-import com.gemstone.gemfire.test.dunit.internal.JUnit3DistributedTestCase;
-import org.apache.logging.log4j.Logger;
+import com.gemstone.gemfire.test.dunit.cache.internal.JUnit3CacheTestCase;
 
 /**
  * The abstract superclass of tests that require the creation of a
@@ -64,497 +26,9 @@ import org.apache.logging.log4j.Logger;
  * @author David Whitlock
  * @since 3.0
  */
-public abstract class CacheTestCase extends JUnit3DistributedTestCase implements CacheTestFixture {
-  private static final Logger logger = LogService.getLogger();
+public abstract class CacheTestCase extends JUnit3CacheTestCase {
 
-  /**
-   * The Cache from which regions are obtained.
-   *
-   * <p>All references synchronized via {@code JUnit4CacheTestCase.class}.
-   *
-   * <p>Field is static so it doesn't get serialized with SerializableRunnable inner classes.
-   */
-  private static Cache cache;
-  
   public CacheTestCase(String name) {
     super(name);
   }
-
-  /**
-   * Creates the <code>Cache</code> for this test
-   */
-  private final void createCache() {
-    createCache(false);
-  }
-  
-  private final void createCache(boolean client) {
-    createCache(client, null);
-  }
-  
-  private final void createCache(boolean client, CacheFactory cf) {
-    synchronized(CacheTestCase.class) {
-      try {
-        System.setProperty("gemfire.DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE", "true");
-        Cache c;
-        if (client) {
-          c = (Cache)new ClientCacheFactory(getSystem().getProperties()).create();
-        } else {
-          if(cf == null) {
-            c = CacheFactory.create(getSystem());
-          } else {
-            Properties props = getSystem().getProperties();
-            for(Map.Entry entry : props.entrySet()) {
-              cf.set((String) entry.getKey(), (String)entry.getValue());
-            }
-            c = cf.create();
-          }
-        }
-        cache = c;
-      } catch (CacheExistsException e) {
-        Assert.fail("the cache already exists", e);
-
-      } catch (RuntimeException ex) {
-        throw ex;
-
-      } catch (Exception ex) {
-        Assert.fail("Checked exception while initializing cache??", ex);
-      } finally {
-        System.clearProperty("gemfire.DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE");
-      }
-    }
-  }
-
-  /**
-   * Creates the <code>Cache</code> for this test that is not connected
-   * to other members
-   */
-  public final Cache createLonerCache() {
-    synchronized(CacheTestCase.class) {
-      try {
-        System.setProperty("gemfire.DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE", "true");
-        Cache c = CacheFactory.create(getLonerSystem()); 
-        cache = c;
-      } catch (CacheExistsException e) {
-        Assert.fail("the cache already exists", e);
-
-      } catch (RuntimeException ex) {
-        throw ex;
-
-      } catch (Exception ex) {
-        Assert.fail("Checked exception while initializing cache??", ex);
-      } finally {
-        System.clearProperty("gemfire.DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE");
-      }
-      return cache;
-    }
-  }
-
-  /**
-   * Sets this test up with a CacheCreation as its cache.
-   * Any existing cache is closed. Whoever calls this must also call finishCacheXml
-   */
-  public static final synchronized void beginCacheXml() {
-    closeCache();
-    cache = new TestCacheCreation();
-  }
-
-  /**
-   * Finish what beginCacheXml started. It does this be generating a cache.xml
-   * file and then creating a real cache using that cache.xml.
-   */
-  public final void finishCacheXml(String name) {
-    synchronized(CacheTestCase.class) {
-      File file = new File(name + "-cache.xml");
-      try {
-        PrintWriter pw = new PrintWriter(new FileWriter(file), true);
-        CacheXmlGenerator.generate(cache, pw);
-        pw.close();
-      } catch (IOException ex) {
-        Assert.fail("IOException during cache.xml generation to " + file, ex);
-      }
-      cache = null;
-      GemFireCacheImpl.testCacheXml = file;
-      try {
-        createCache();
-      } finally {
-        GemFireCacheImpl.testCacheXml = null;
-      }
-    }
-  }
-  
-  /**
-   * Finish what beginCacheXml started. It does this be generating a cache.xml
-   * file and then creating a real cache using that cache.xml.
-   */
-  public final void finishCacheXml(String name, boolean useSchema, String xmlVersion) {
-    synchronized(CacheTestCase.class) {
-      File dir = new File("XML_" + xmlVersion);
-      dir.mkdirs();
-      File file = new File(dir, name + ".xml");
-      try {
-        PrintWriter pw = new PrintWriter(new FileWriter(file), true);
-        CacheXmlGenerator.generate(cache, pw, useSchema, xmlVersion);
-        pw.close();
-      } catch (IOException ex) {
-        Assert.fail("IOException during cache.xml generation to " + file, ex);
-      }
-      cache = null;
-      GemFireCacheImpl.testCacheXml = file;
-      try {
-        createCache();
-      } finally {
-        GemFireCacheImpl.testCacheXml = null;
-      }
-    }
-  }
-
-  /**
-   * Return a cache for obtaining regions, created lazily.
-   */
-  public final Cache getCache() {
-    return getCache(false);
-  }
-  
-  public final Cache getCache(CacheFactory cf) {
-    return getCache(false, cf);
-  }
-  
-  public final Cache getCache(boolean client) {
-    return getCache(client, null);
-  }
-
-  public final Cache getCache(boolean client, CacheFactory cf) {
-    synchronized (CacheTestCase.class) {
-      final GemFireCacheImpl gfCache = GemFireCacheImpl.getInstance();
-      if (gfCache != null && !gfCache.isClosed()
-          && gfCache.getCancelCriterion().cancelInProgress() != null) {
-        Wait.waitForCriterion(new WaitCriterion() {
-
-          public boolean done() {
-            return gfCache.isClosed();
-          }
-
-          public String description() {
-            return "waiting for cache to close";
-          }
-        }, 30 * 1000, 300, true);
-      }
-      if (cache == null || cache.isClosed()) {
-        cache = null;
-        createCache(client, cf);
-      }
-      if (client && cache != null) {
-        IgnoredException.addIgnoredException("java.net.ConnectException");
-      }
-      return cache;
-    }
-  }
-
-  /**
-   * creates a client cache from the factory if one does not already exist
-   * @since 6.5
-   * @param factory
-   * @return the client cache
-   */
-  public final ClientCache getClientCache(ClientCacheFactory factory) {
-    synchronized (CacheTestCase.class) {
-      final GemFireCacheImpl gfCache = GemFireCacheImpl.getInstance();
-      if (gfCache != null && !gfCache.isClosed()
-          && gfCache.getCancelCriterion().cancelInProgress() != null) {
-        Wait.waitForCriterion(new WaitCriterion() {
-          @Override
-          public boolean done() {
-            return gfCache.isClosed();
-          }
-          @Override
-          public String description() {
-            return "waiting for cache to close";
-          }
-        }, 30 * 1000, 300, true);
-      }
-      if (cache == null || cache.isClosed()) {
-        cache = null;
-        disconnectFromDS();
-        cache = (Cache)factory.create();
-      }
-      if (cache != null) {
-        IgnoredException.addIgnoredException("java.net.ConnectException");
-      }
-      return (ClientCache)cache;
-    }
-  }
-
-  /**
-   * same as {@link #getCache()} but with casting
-   */
-  public final GemFireCacheImpl getGemfireCache() {
-    return (GemFireCacheImpl)getCache();
-  }
-
-  public static synchronized final boolean hasCache() {
-    return cache != null;
-  }
-
-  /**
-   * Return current cache without creating one.
-   */
-  public static synchronized final Cache basicGetCache() {
-    return cache;
-  }
-
-  /** Close the cache */
-  public static synchronized final void closeCache() {
-    //Workaround for that fact that some classes are now extending
-    //CacheTestCase but not using it properly.
-    if(cache == null) {
-      cache = GemFireCacheImpl.getInstance();
-    }
-    try {
-    if (cache != null) {
-      try {
-        if (!cache.isClosed()) {
-          if (cache instanceof GemFireCacheImpl) {
-            CacheTransactionManager txMgr = ((GemFireCacheImpl)cache).getTxManager();
-            if (txMgr != null) {
-              if (txMgr.exists()) {
-                try {
-                  // make sure we cleanup this threads txid stored in a thread local
-                  txMgr.rollback();
-                }catch(Exception ignore) {
-                  
-                }
-              }
-            }
-          }
-          cache.close();
-        }
-      }
-      finally {
-        cache = null;
-      }
-    } // cache != null
-    } finally {
-      //Make sure all pools are closed, even if we never
-      //created a cache
-      PoolManager.close(false);
-    }
-  }
-
-  /** Closed the cache in all VMs. */
-  protected final void closeAllCache() {
-    closeCache();
-    Invoke.invokeInEveryVM(()->closeCache());
-  }
-
-  @Override
-  public final void preTearDown() throws Exception {
-    preTearDownCacheTestCase();
-    tearDownCacheTestCase();
-    postTearDownCacheTestCase();
-  }
-
-  private final void tearDownCacheTestCase() throws Exception {
-    // locally destroy all root regions and close the cache
-    remoteTearDown();
-    Invoke.invokeInEveryVM(()->remoteTearDown());
-  }
-  
-  public void preTearDownCacheTestCase() throws Exception {
-  }
-
-  public void postTearDownCacheTestCase() throws Exception {
-  }
-
-  /**
-   * Local destroy all root regions and close the cache.  
-   */
-  protected final synchronized static void remoteTearDown() {
-    try {
-      DistributionMessageObserver.setInstance(null);
-      destroyRegions(cache);
-    }
-    finally {
-      try {
-        closeCache();
-      }
-      finally {
-        try {
-          cleanDiskDirs();
-        } catch(Exception e) {
-          LogWriterUtils.getLogWriter().error("Error cleaning disk dirs", e);
-        }
-      }
-    }
-  }
-
-  /**
-   * Returns a region with the given name and attributes
-   */
-  public final Region createRegion(String name,
-                                      RegionAttributes attrs)
-    throws CacheException {
-    return createRegion(name, "root", attrs);
-  }
-  
-  /**
-   * Provide any internal region arguments, typically required when 
-   * internal use (aka meta-data) regions are needed.
-   * @return internal arguements, which may be null.  If null, then default 
-   * InternalRegionArguments are used to construct the Region
-   */
-  private final InternalRegionArguments getInternalRegionArguments()
-  {
-    return null;
-  }
-
-  final public Region createRegion(String name, String rootName,
-                                      RegionAttributes attrs)
-    throws CacheException {
-    Region root = getRootRegion(rootName);
-    if (root == null) {
-      // don't put listeners on root region
-      RegionAttributes rootAttrs = attrs;
-      AttributesFactory fac = new AttributesFactory(attrs);
-      ExpirationAttributes expiration = ExpirationAttributes.DEFAULT;
-
-      // fac.setCacheListener(null);
-      fac.setCacheLoader(null);
-      fac.setCacheWriter(null);
-      fac.setPoolName(null);
-      fac.setPartitionAttributes(null);
-      fac.setRegionTimeToLive(expiration);
-      fac.setEntryTimeToLive(expiration);
-      fac.setRegionIdleTimeout(expiration);
-      fac.setEntryIdleTimeout(expiration);
-      rootAttrs = fac.create();
-      root = createRootRegion(rootName, rootAttrs);
-    }
-
-    InternalRegionArguments internalArgs = getInternalRegionArguments();
-    if (internalArgs == null) {
-      return root.createSubregion(name, attrs);
-    } else {
-      try {
-        LocalRegion lr = (LocalRegion) root;
-        return lr.createSubregion(name, attrs, internalArgs);
-      } catch (IOException ioe) {
-        AssertionError assErr = new AssertionError("unexpected exception");
-        assErr.initCause(ioe);
-        throw assErr;
-      } catch (ClassNotFoundException cnfe) {
-        AssertionError assErr = new AssertionError("unexpected exception");
-        assErr.initCause(cnfe);
-        throw assErr;
-      } 
-    }
-  }
-  
-  public final Region getRootRegion() {
-    return getRootRegion("root");
-  }
-  
-  public final Region getRootRegion(String rootName) {
-    return getCache().getRegion(rootName);
-  }
-
-  protected final Region createRootRegion(RegionAttributes attrs)
-  throws RegionExistsException, TimeoutException {
-    return createRootRegion("root", attrs);
-  }
-
-  public final Region createRootRegion(String rootName, RegionAttributes attrs)
-  throws RegionExistsException, TimeoutException {
-    return getCache().createRegion(rootName, attrs);
-  }
-
-  public final Region createExpiryRootRegion(String rootName, RegionAttributes attrs)
-  throws RegionExistsException, TimeoutException {
-    System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
-    try {
-      return createRootRegion(rootName, attrs);
-    } finally {
-      System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
-    }
-  }
-
-  /**
-   * @deprecated Use DistributedTestCase.addExpectedException
-   */
-  @Deprecated
-  protected final CacheSerializableRunnable addExceptionTag1(final String expectedException) {
-    CacheSerializableRunnable addExceptionTag = new CacheSerializableRunnable(
-    "addExceptionTag") {
-      public void run2()
-      {
-        getCache().getLogger().info(
-            "<ExpectedException action=add>" + expectedException
-            + "</ExpectedException>");
-      }
-    };
-    
-    return addExceptionTag;
-  }
-
-  /**
-   * @deprecated Use DistributedTestCase.addExpectedException
-   */
-  @Deprecated
-  protected final CacheSerializableRunnable removeExceptionTag1(final String expectedException) {
-    CacheSerializableRunnable removeExceptionTag = new CacheSerializableRunnable(
-    "removeExceptionTag") {
-      public void run2() throws CacheException {
-        getCache().getLogger().info(
-            "<ExpectedException action=remove>" + expectedException
-            + "</ExpectedException>");
-      }
-    };
-    return removeExceptionTag;
-  }
-
-  /**
-   * Used to generate a cache.xml. Basically just a CacheCreation
-   * with a few more methods implemented.
-   */
-  private static final class TestCacheCreation extends CacheCreation {
-    private boolean closed = false;
-    @Override
-    public void close() {
-      this.closed = true;
-    }
-    @Override
-    public boolean isClosed() {
-      return this.closed;
-    }
-  }
-  
-  public static final File getDiskDir() {
-    int vmNum = VM.getCurrentVMNum();
-    File dir = new File("diskDir", "disk" + String.valueOf(vmNum)).getAbsoluteFile();
-    dir.mkdirs();
-    return dir;
-  }
-  
-  /**
-   * Return a set of disk directories
-   * for persistence tests. These directories
-   * will be automatically cleaned up 
-   * on test case closure.
-   */
-  public static final File[] getDiskDirs() {
-    return new File[] {getDiskDir()};
-  }
-  
-  public static final void cleanDiskDirs() throws IOException {
-    FileUtil.delete(getDiskDir());
-    File[] defaultStoreFiles = new File(".").listFiles(new FilenameFilter() {
-      
-      public boolean accept(File dir, String name) {
-        return name.startsWith("BACKUPDiskStore-" + System.getProperty("vmid"));
-      }
-    });
-    
-    for(File file: defaultStoreFiles) {
-      FileUtil.delete(file);
-    }
-  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d41e74d0/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java
index 65f403b..6a6227c 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java
@@ -16,53 +16,10 @@
  */
 package com.gemstone.gemfire.test.dunit;
 
-import java.io.Serializable;
-import java.text.DecimalFormat;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import com.gemstone.gemfire.test.dunit.internal.DistributedTestFixture;
 import com.gemstone.gemfire.test.dunit.internal.JUnit3DistributedTestCase;
-import org.apache.logging.log4j.Logger;
-import org.junit.experimental.categories.Category;
-
-import com.gemstone.gemfire.SystemFailure;
-import com.gemstone.gemfire.admin.internal.AdminDistributedSystemImpl;
-import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.hdfs.internal.hoplog.HoplogConfig;
-import com.gemstone.gemfire.cache.query.QueryTestUtils;
-import com.gemstone.gemfire.cache.query.internal.QueryObserverHolder;
-import com.gemstone.gemfire.cache30.ClientServerTestCase;
-import com.gemstone.gemfire.cache30.GlobalLockingDUnitTest;
-import com.gemstone.gemfire.cache30.MultiVMRegionTestCase;
-import com.gemstone.gemfire.cache30.RegionTestCase;
-import com.gemstone.gemfire.distributed.DistributedSystem;
-import com.gemstone.gemfire.distributed.internal.DistributionConfig;
-import com.gemstone.gemfire.distributed.internal.DistributionMessageObserver;
-import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
-import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem.CreationStackGenerator;
-import com.gemstone.gemfire.distributed.internal.tcpserver.TcpClient;
-import com.gemstone.gemfire.internal.SocketCreator;
-import com.gemstone.gemfire.internal.admin.ClientStatsManager;
-import com.gemstone.gemfire.internal.cache.DiskStoreObserver;
-import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
-import com.gemstone.gemfire.internal.cache.HARegion;
-import com.gemstone.gemfire.internal.cache.InitialImageOperation;
-import com.gemstone.gemfire.internal.cache.PartitionedRegion;
-import com.gemstone.gemfire.internal.cache.tier.InternalClientMembership;
-import com.gemstone.gemfire.internal.cache.tier.sockets.CacheServerTestUtil;
-import com.gemstone.gemfire.internal.cache.tier.sockets.ClientProxyMembershipID;
-import com.gemstone.gemfire.internal.cache.xmlcache.CacheCreation;
-import com.gemstone.gemfire.internal.logging.LogService;
-import com.gemstone.gemfire.management.internal.cli.LogWrapper;
 import com.gemstone.gemfire.test.dunit.standalone.DUnitLauncher;
 import com.gemstone.gemfire.test.junit.categories.DistributedTest;
-
-import junit.framework.TestCase;
+import org.junit.experimental.categories.Category;
 
 /**
  * This class is the superclass of all distributed unit tests.
@@ -71,7 +28,7 @@ import junit.framework.TestCase;
  */
 @Category(DistributedTest.class)
 @SuppressWarnings("serial")
-public abstract class DistributedTestCase extends JUnit3DistributedTestCase implements DistributedTestFixture, Serializable {
+public abstract class DistributedTestCase extends JUnit3DistributedTestCase {
   
   /**
    * Creates a new <code>DistributedTestCase</code> test with the given name.