From 0d88ba4b58e27627ac2cb852d14fe91a0174c6dc Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 03 Sep 2013 13:08:51 +0000
Subject: [PATCH] LDAPreplicationDomain.java: Reverted if statement conditions to do early exit in loops or methods. Reduced variable scopes. Moved clearJEBackend() to TestCaseUtils and renamed it clearJEBackend2(). Extracted method allOperationalAttributes. Increased vertical density.
---
opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java | 62 ++++++++++++++++++++++++++++++-
1 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
index da7b013..a0f584e 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
@@ -50,6 +50,7 @@
import org.opends.server.core.AddOperation;
import org.opends.server.core.DeleteOperation;
import org.opends.server.core.DirectoryServer;
+import org.opends.server.core.LockFileManager;
import org.opends.server.extensions.ConfigFileHandler;
import org.opends.server.loggers.*;
import org.opends.server.loggers.debug.DebugLogger;
@@ -63,6 +64,7 @@
import org.opends.server.protocols.ldap.BindResponseProtocolOp;
import org.opends.server.protocols.ldap.LDAPMessage;
import org.opends.server.protocols.ldap.LDAPReader;
+import org.opends.server.tasks.TaskUtils;
import org.opends.server.tools.LDAPModify;
import org.opends.server.tools.dsconfig.DSConfig;
import org.opends.server.types.*;
@@ -951,8 +953,64 @@
}
/**
- * This was used to track down which test was trashing the indexes.
- * We left it here because it might be useful again.
+ * Clears all the entries from the JE backend determined by the be id passed
+ * into the method.
+ *
+ * @param createBaseEntry
+ * Indicate whether to automatically create the base entry and add it
+ * to the backend.
+ * @param beID
+ * The be id to clear.
+ * @param dn
+ * The suffix of the backend to create if the the createBaseEntry
+ * boolean is true.
+ * @throws Exception
+ * If an unexpected problem occurs.
+ */
+ public static void clearJEBackend2(boolean createBaseEntry, String beID, String dn)
+ throws Exception
+ {
+ BackendImpl backend = (BackendImpl) DirectoryServer.getBackend(beID);
+
+ // FIXME Should setBackendEnabled be part of TaskUtils ?
+ TaskUtils.disableBackend(beID);
+
+ try
+ {
+ 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);
+ }
+ }
+ finally
+ {
+ TaskUtils.enableBackend(beID);
+ }
+
+ if (createBaseEntry)
+ {
+ DN baseDN = DN.decode(dn);
+ Entry e = createEntry(baseDN);
+ backend = (BackendImpl) DirectoryServer.getBackend(beID);
+ backend.addEntry(e, null);
+ }
+ }
+
+ /**
+ * This was used to track down which test was trashing the indexes. We left it
+ * here because it might be useful again.
*/
public static void printUntrustedIndexes()
{
--
Gitblit v1.10.0