mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

abobrov
24.25.2007 ce9a47597a234d664049ac75fa9cc6ab0911c85a
- add assertions covering cache maps out of sync.
- replace atomic init followed by clear in favor of before/after group to improve concurrency.
- fix FIFO rotation test bug to assert for all rotated entries.

4 files modified
155 ■■■■ changed files
opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/CommonEntryCacheTestCase.java 62 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/FIFOEntryCacheTestCase.java 29 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/FileSystemEntryCacheTestCase.java 38 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/SoftReferenceEntryCacheTestCase.java 26 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/CommonEntryCacheTestCase.java
@@ -30,7 +30,6 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;
import org.opends.server.TestCaseUtils;
@@ -100,14 +99,6 @@
  /**
   * Indicates whether a concurrent test thread should assert
   * that the cache is empty before executing the actual test.
   */
  private AtomicBoolean cacheEmptyAssert = new AtomicBoolean();
  /**
   * Reflection of the toVerboseString implementation method.
   */
  protected String toVerboseString()
@@ -307,6 +298,7 @@
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @SuppressWarnings("unchecked")
  public void testPutEntry()
         throws Exception
  {
@@ -324,6 +316,11 @@
      " in the cache.  Cache contents:" + ServerConstants.EOL +
      toVerboseString());
    assertNotNull(cache.getEntry(b, 1, LockType.NONE, new ArrayList<Lock>()),
      "Expected to find entry id " + Integer.toString(-1) +
      " in the cache.  Cache contents:" + ServerConstants.EOL +
      toVerboseString());
    // Clear the cache so that other tests can start from scratch.
    cache.clear();
  }
@@ -335,6 +332,7 @@
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @SuppressWarnings("unchecked")
  public void testPutEntryIfAbsent()
         throws Exception
  {
@@ -355,6 +353,16 @@
      " in the cache.  Cache contents:" + ServerConstants.EOL +
      toVerboseString());
    assertNotNull(cache.getEntry(testEntriesList.get(0).getDN()),
      "Expected to find " + testEntriesList.get(0).getDN().toString() +
      " in the cache.  Cache contents:" + ServerConstants.EOL +
      toVerboseString());
    assertNotNull(cache.getEntry(b, 1, LockType.NONE, new ArrayList<Lock>()),
      "Expected to find entry id " + Integer.toString(-1) +
      " in the cache.  Cache contents:" + ServerConstants.EOL +
      toVerboseString());
    // Clear the cache so that other tests can start from scratch.
    cache.clear();
  }
@@ -366,6 +374,7 @@
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @SuppressWarnings("unchecked")
  public void testRemoveEntry()
         throws Exception
  {
@@ -385,6 +394,11 @@
      " in the cache.  Cache contents:" + ServerConstants.EOL +
      toVerboseString());
    assertNull(cache.getEntry(b, 1, LockType.NONE, new ArrayList<Lock>()),
      "Not expected to find entry id " + Integer.toString(-1) +
      " in the cache.  Cache contents:" + ServerConstants.EOL +
      toVerboseString());
    // Clear the cache so that other tests can start from scratch.
    cache.clear();
  }
@@ -396,6 +410,7 @@
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @SuppressWarnings("unchecked")
  public void testClear()
         throws Exception
  {
@@ -415,6 +430,11 @@
      " in the cache.  Cache contents:" + ServerConstants.EOL +
      toVerboseString());
    assertNull(cache.getEntry(b, 1, LockType.NONE, new ArrayList<Lock>()),
      "Not expected to find entry id " + Integer.toString(-1) +
      " in the cache.  Cache contents:" + ServerConstants.EOL +
      toVerboseString());
    // Clear the cache so that other tests can start from scratch.
    cache.clear();
  }
@@ -448,6 +468,11 @@
      b.getBackendID() + " in the cache.  Cache contents:" +
      ServerConstants.EOL + toVerboseString());
    assertNull(cache.getEntry(testEntriesList.get(0).getDN()),
      "Not expected to find " + testEntriesList.get(0).getDN().toString() +
      " in the cache.  Cache contents:" + ServerConstants.EOL +
      toVerboseString());
    assertNotNull(cache.getEntry(c, 1, LockType.NONE, new ArrayList<Lock>()),
      "Expected to find entry id " + Integer.toString(1) + " on backend " +
      c.getBackendID() + " in the cache.  Cache contents:" +
@@ -464,6 +489,7 @@
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @SuppressWarnings("unchecked")
  public void testClearSubtree()
         throws Exception
  {
@@ -487,6 +513,11 @@
      " in the cache.  Cache contents:" + ServerConstants.EOL +
      toVerboseString());
    assertNull(cache.getEntry(b, 1, LockType.NONE, new ArrayList<Lock>()),
      "Not expected to find entry id " + Integer.toString(-1) +
      " in the cache.  Cache contents:" + ServerConstants.EOL +
      toVerboseString());
    assertNotNull(cache.getEntry(testEntry.getDN()),
      "Expected to find " + testEntry.getDN().toString() +
      " in the cache.  Cache contents:" + ServerConstants.EOL +
@@ -524,25 +555,20 @@
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @SuppressWarnings("unchecked")
  public void testCacheConcurrency()
         throws Exception
  {
    if(cacheEmptyAssert.compareAndSet(false, true)) {
      assertNull(toVerboseString(),
        "Expected empty cache.  " + "Cache contents:" + ServerConstants.EOL +
        toVerboseString());
    }
    Backend b = DirectoryServer.getBackend(DN.decode("o=test"));
    for(int loops = 0; loops < CONCURRENCYLOOPS; loops++) {
      for(int i = 0; i < NUMTESTENTRIES; i++) {
        cache.putEntry(testEntriesList.get(i), b, i);
        cache.getEntry(testEntriesList.get(i).getDN());
        cache.removeEntry(testEntriesList.get(i).getDN());
        cache.putEntryIfAbsent(testEntriesList.get(i), b, i);
        cache.getEntry(b, i, LockType.NONE, new ArrayList<Lock>());
      }
    }
    // Clear the cache so that other tests can start from scratch.
    cache.clear();
  }
}
opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/FIFOEntryCacheTestCase.java
@@ -39,6 +39,8 @@
import org.opends.server.types.Entry;
import org.opends.server.util.ServerConstants;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
@@ -314,10 +316,31 @@
  @BeforeGroups(groups = "testFIFOCacheConcurrency")
  public void cacheConcurrencySetup()
         throws Exception
  {
    assertNull(super.toVerboseString(),
      "Expected empty cache.  " + "Cache contents:" + ServerConstants.EOL +
      super.toVerboseString());
  }
  @AfterGroups(groups = "testFIFOCacheConcurrency")
  public void cacheConcurrencyCleanup()
         throws Exception
  {
    // Clear the cache so that other tests can start from scratch.
    super.cache.clear();
  }
  /**
   * {@inheritDoc}
   */
  @Test(groups="slow",
  @Test(groups = { "slow", "testFIFOCacheConcurrency" },
        threadPoolSize = 10,
        invocationCount = 10,
        timeOut = 60000)
@@ -347,8 +370,8 @@
      super.cache.putEntry(super.testEntriesList.get(i), b, i);
    }
    // Make sure first MAXENTRIES out of NUMTESTENTRIES rotated.
    for(int i = 0; i < super.MAXENTRIES; i++ ) {
    // Make sure first NUMTESTENTRIES - MAXENTRIES got rotated.
    for(int i = 0; i < (super.NUMTESTENTRIES - super.MAXENTRIES); i++ ) {
      assertFalse(super.cache.containsEntry(
        super.testEntriesList.get(i).getDN()), "Not expected to find " +
        super.testEntriesList.get(i).getDN().toString() + " in the " +
opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/FileSystemEntryCacheTestCase.java
@@ -87,6 +87,11 @@
    // Initialize the cache.
    super.cache = new FileSystemEntryCache();
    super.cache.initializeEntryCache(configuration);
    // Make sure the cache is empty.
    assertNull(super.toVerboseString(),
      "Expected empty cache.  " + "Cache contents:" + ServerConstants.EOL +
      super.toVerboseString());
  }
@@ -428,10 +433,31 @@
  @BeforeGroups(groups = "testFSFIFOCacheConcurrency")
  public void cacheConcurrencySetup()
         throws Exception
  {
    assertNull(super.toVerboseString(),
      "Expected empty cache.  " + "Cache contents:" + ServerConstants.EOL +
      super.toVerboseString());
  }
  @AfterGroups(groups = "testFSFIFOCacheConcurrency")
  public void cacheConcurrencyCleanup()
         throws Exception
  {
    // Clear the cache so that other tests can start from scratch.
    super.cache.clear();
  }
  /**
   * {@inheritDoc}
   */
  @Test(groups="slow",
  @Test(groups = { "slow", "testFSFIFOCacheConcurrency" },
        threadPoolSize = 10,
        invocationCount = 10,
        // In case of disk based FS.
@@ -445,7 +471,7 @@
  @BeforeGroups(groups = "testLRUCacheConcurrency")
  @BeforeGroups(groups = "testFSLRUCacheConcurrency")
  public void LRUCacheConcurrencySetup()
         throws Exception
  {
@@ -455,7 +481,7 @@
  @AfterGroups(groups = "testLRUCacheConcurrency")
  @AfterGroups(groups = "testFSLRUCacheConcurrency")
  public void LRUCacheConcurrencyCleanup()
         throws Exception
  {
@@ -472,7 +498,7 @@
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(groups = { "slow", "testLRUCacheConcurrency" },
  @Test(groups = { "slow", "testFSLRUCacheConcurrency" },
        threadPoolSize = 10,
        invocationCount = 10,
        // In case of disk based FS.
@@ -502,8 +528,8 @@
      super.cache.putEntry(super.testEntriesList.get(i), b, i);
    }
    // Make sure first MAXENTRIES out of NUMTESTENTRIES rotated.
    for(int i = 0; i < super.MAXENTRIES; i++ ) {
    // Make sure first NUMTESTENTRIES - MAXENTRIES got rotated.
    for(int i = 0; i < (super.NUMTESTENTRIES - super.MAXENTRIES); i++ ) {
      assertFalse(super.cache.containsEntry(
        super.testEntriesList.get(i).getDN()), "Not expected to find " +
        super.testEntriesList.get(i).getDN().toString() + " in the " +
opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/SoftReferenceEntryCacheTestCase.java
@@ -34,7 +34,10 @@
import org.testng.annotations.BeforeClass;
import org.opends.server.admin.std.meta.*;
import org.opends.server.types.Entry;
import org.opends.server.util.ServerConstants;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
@@ -287,10 +290,31 @@
  @BeforeGroups(groups = "testSoftRefCacheConcurrency")
  public void cacheConcurrencySetup()
         throws Exception
  {
    assertNull(super.toVerboseString(),
      "Expected empty cache.  " + "Cache contents:" + ServerConstants.EOL +
      super.toVerboseString());
  }
  @AfterGroups(groups = "testSoftRefCacheConcurrency")
  public void cacheConcurrencyCleanup()
         throws Exception
  {
    // Clear the cache so that other tests can start from scratch.
    super.cache.clear();
  }
  /**
   * {@inheritDoc}
   */
  @Test(groups="slow",
  @Test(groups = { "slow", "testSoftRefCacheConcurrency" },
        threadPoolSize = 10,
        invocationCount = 10,
        timeOut = 60000)