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

neil_a_wilson
28.43.2007 73dd9bc58413442f19cdff6a450b1a1ae167c270
Update the TestCaseUtils.clearJEBackend() method to use a different approach.
Instead of closing the environment, deleting the files, and re-opening the
environment, we are keeping the environment open and just truncating the
databases. This dramatically reduces the amount of memory required to run the
unit tests, apparently as a result of a memory leak in the Berkeley DB JE when
the environment is repeatedly opened and closed.

Note that the latest release of Berkeley DB JE (3.2.44, which we aren't yet
using) claims to have a fix for a similar problem (JE issue #15444 as described
in http://forums.oracle.com/forums/thread.jspa?messageID=1782659) but testing
with that JE version didn't appear to resolve the problem so it is likely that
the issue still exists. However, while it was causing a significant problem in
our test cases, it is unlikely to cause problems in production environments
because the JE environment should not be repeatedly opened and closed in the
same JVM instance.
2 files modified
40 ■■■■■ changed files
opends/src/server/org/opends/server/backends/jeb/RootContainer.java 9 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java 31 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/backends/jeb/RootContainer.java
@@ -670,6 +670,15 @@
    return (nextid.get() - 1);
  }
  /**
   * Resets the next entry ID counter to zero.  This should only be used after
   * clearing all databases.
   */
  public void resetNextEntryID()
  {
    nextid.set(1);
  }
  /**
opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
@@ -48,6 +48,8 @@
import org.opends.server.backends.MemoryBackend;
import org.opends.server.backends.jeb.BackendImpl;
import org.opends.server.backends.jeb.EntryContainer;
import org.opends.server.backends.jeb.RootContainer;
import org.opends.server.config.ConfigException;
import org.opends.server.core.AddOperation;
import org.opends.server.core.DirectoryServer;
@@ -469,32 +471,13 @@
       throws Exception
  {
    BackendImpl backend = (BackendImpl)DirectoryServer.getBackend(beID);
    TaskUtils.disableBackend(beID);
    try
    RootContainer rootContainer = backend.getRootContainer();
    for (EntryContainer ec : rootContainer.getEntryContainers())
    {
      String lockFile = LockFileManager.getBackendLockFileName(backend);
      StringBuilder failureReason = new StringBuilder();
      if (!LockFileManager.acquireExclusiveLock(lockFile, failureReason))
      {
        throw new RuntimeException(failureReason.toString());
      }
      try
      {
        backend.clearBackend();
      }
      finally
      {
        LockFileManager.releaseLock(lockFile, failureReason);
      }
      ec.clear();
      assertEquals(ec.getHighestEntryID().longValue(), 0L);
    }
    finally
    {
      TaskUtils.enableBackend(beID);
    }
    rootContainer.resetNextEntryID();
    if (createBaseEntry)
    {