From c56f9babdfc911a783dbf8ebaa25ac8852dce34c Mon Sep 17 00:00:00 2001
From: dugan <dugan@localhost>
Date: Thu, 05 Oct 2006 17:01:32 +0000
Subject: [PATCH] Fixes for issues 755 and 743
---
opendj-sdk/opends/src/server/org/opends/server/backends/jeb/VerifyJob.java | 76 ++++++------
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestVerifyJob.java | 144 ++++++++++++++++++++++++
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/JebTestCase.java | 82 +++++++++++++
3 files changed, 264 insertions(+), 38 deletions(-)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/backends/jeb/VerifyJob.java b/opendj-sdk/opends/src/server/org/opends/server/backends/jeb/VerifyJob.java
index 3fda5c2..5a1501c 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/backends/jeb/VerifyJob.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/backends/jeb/VerifyJob.java
@@ -177,6 +177,13 @@
* A list of the attribute indexes to be verified.
*/
ArrayList<AttributeIndex> attrIndexList = new ArrayList<AttributeIndex>();
+/**
+ * The types of indexes that are verifiable.
+ */
+ enum IndexType
+ {
+ PRES, EQ, SUBSTRING, ORDERING;
+ }
/**
* Construct a VerifyJob.
@@ -286,34 +293,27 @@
// Make a note of the time we started.
long startTime = System.currentTimeMillis();
+ // Start a timer for the progress report.
+ Timer timer = new Timer();
+ TimerTask progressTask = new ProgressTask();
+ timer.scheduleAtFixedRate(progressTask, progressInterval,
+ progressInterval);
+
+ // Iterate through the index keys.
try
{
- // Start a timer for the progress report.
- Timer timer = new Timer();
- TimerTask progressTask = new ProgressTask();
- timer.scheduleAtFixedRate(progressTask, progressInterval,
- progressInterval);
-
- // Iterate through the index keys.
- try
+ if (cleanMode)
{
- if (cleanMode)
- {
iterateIndex();
- }
- else
- {
- iterateID2Entry();
- }
}
- finally
+ else
{
- timer.cancel();
+ iterateID2Entry();
}
}
finally
{
- entryContainer.close();
+ timer.cancel();
}
long finishTime = System.currentTimeMillis();
@@ -517,11 +517,14 @@
else
{
AttributeIndex attrIndex = attrIndexList.get(0);
-
- iterateAttrIndex(attrIndex.getAttributeType(), attrIndex.equalityIndex);
- iterateAttrIndex(attrIndex.getAttributeType(), attrIndex.presenceIndex);
- iterateAttrIndex(attrIndex.getAttributeType(), attrIndex.substringIndex);
- iterateAttrIndex(attrIndex.getAttributeType(), attrIndex.orderingIndex);
+ iterateAttrIndex(attrIndex.getAttributeType(),
+ attrIndex.equalityIndex, IndexType.EQ );
+ iterateAttrIndex(attrIndex.getAttributeType(),
+ attrIndex.presenceIndex, IndexType.PRES);
+ iterateAttrIndex(attrIndex.getAttributeType(),
+ attrIndex.substringIndex, IndexType.SUBSTRING);
+ iterateAttrIndex(attrIndex.getAttributeType(),
+ attrIndex.orderingIndex, IndexType.ORDERING);
}
}
@@ -917,7 +920,8 @@
* @throws JebException If an error occurs in the JE backend.
* @throws DatabaseException If an error occurs in the JE database.
*/
- private void iterateAttrIndex(AttributeType attrType, Index index)
+ private void iterateAttrIndex(AttributeType attrType,
+ Index index, IndexType indexType)
throws JebException, DatabaseException
{
if (index == null)
@@ -962,31 +966,29 @@
byte[] bytes;
SearchFilter sf;
- switch (value[0])
+ switch (indexType)
{
- case '*':
- bytes = new byte[value.length-1];
- System.arraycopy(value, 1, bytes, 0, value.length-1);
-
+ case SUBSTRING:
ArrayList<ByteString> subAnyElements =
new ArrayList<ByteString>(1);
- subAnyElements.add(new ASN1OctetString(bytes));
+ subAnyElements.add(new ASN1OctetString(value));
sf = SearchFilter.createSubstringFilter(attrType,null,
subAnyElements,null);
break;
-
- case '=':
- bytes = new byte[value.length-1];
- System.arraycopy(value, 1, bytes, 0, value.length-1);
-
+ /* TODO
+ * This ORDERING case needs further study
+ * about what type of SearchFilter should be created.
+ * case ORDERING:
+ * */
+ case EQ:
AttributeValue assertionValue =
- new AttributeValue(attrType, new ASN1OctetString(bytes));
+ new AttributeValue(attrType, new ASN1OctetString(value));
sf = SearchFilter.createEqualityFilter(attrType,assertionValue);
break;
- case '+':
+ case PRES:
sf = SearchFilter.createPresenceFilter(attrType);
break;
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/JebTestCase.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/JebTestCase.java
index 7da0cca..7831bc0 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/JebTestCase.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/JebTestCase.java
@@ -26,7 +26,26 @@
*/
package org.opends.server.backends.jeb;
+import static org.testng.Assert.assertEquals;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Random;
+import java.util.TreeMap;
+
+import org.opends.server.core.AddOperation;
+import org.opends.server.core.DeleteOperation;
+import org.opends.server.protocols.internal.InternalClientConnection;
+import org.opends.server.tools.makeldif.MakeLDIFInputStream;
+import org.opends.server.tools.makeldif.TemplateFile;
+import org.opends.server.types.DN;
+import org.opends.server.types.DNComparator;
+import org.opends.server.types.LDIFImportConfig;
+import org.opends.server.types.ResultCode;
import org.opends.server.DirectoryServerTestCase;
+import org.opends.server.TestCaseUtils;
+import org.opends.server.types.Entry;
+import org.opends.server.util.LDIFReader;
import org.testng.annotations.Test;
/**
@@ -34,5 +53,66 @@
*/
@Test(groups = { "precommit", "jeb" })
public abstract class JebTestCase extends DirectoryServerTestCase {
- // No implementation required.
+ private DNComparator comparator = new DNComparator();
+ private TreeMap<DN,Entry> entryTreeMap = new TreeMap<DN,Entry>(comparator);
+ int numEntries;
+
+ /**
+ * This method takes an MakeLDIF template and a number of entries to create
+ * and adds the created entries into server.
+ *
+ * @param template MakeLDIF template to use.
+ * @param numEntries Number of entries to create and add.
+ * @throws Exception if the entries cannot be created or if the add
+ * fails.
+ */
+ protected void
+ createLoadEntries(String[] template, int numEntries) throws Exception {
+ InternalClientConnection connection =
+ InternalClientConnection.getRootConnection();
+ String makeLDIFPath =
+ System.getProperty(TestCaseUtils.PROPERTY_BUILD_ROOT) +
+ File.separator + "resource"+File.separator+"MakeLDIF";
+ TemplateFile templateFile =
+ new TemplateFile(makeLDIFPath, new Random());
+ ArrayList<String> warnings = new ArrayList<String>();
+ templateFile.parse(template, warnings);
+ MakeLDIFInputStream ldifEntryStream =
+ new MakeLDIFInputStream(templateFile);
+ LDIFReader reader =
+ new LDIFReader(new LDIFImportConfig(ldifEntryStream));
+ for(int i =0; i<numEntries;i++) {
+ Entry entry = reader.readEntry(false);
+ entryTreeMap.put(entry.getDN(), entry);
+ AddOperation addOperation =
+ connection.processAdd(entry.getDN(),
+ entry.getObjectClasses(),
+ entry.getUserAttributes(),
+ entry.getOperationalAttributes());
+ assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS,
+ "Add of this entry was not successful");
+ }
+ reader.close();
+ this.numEntries=numEntries;
+ }
+
+ /**This method should be used to remove the entries created in the
+ * above loadEntries method.
+ * Note that it starts at the last key and works backwards so that the leaf
+ * entries are removed first before the top level nodes.
+ *
+ * @throws Exception if the entries cannot be removed.
+ */
+ protected void
+ removeLoadedEntries() throws Exception {
+ InternalClientConnection connection =
+ InternalClientConnection.getRootConnection();
+ for(int j =0; j < numEntries; j++) {
+ DN entryDN = entryTreeMap.lastKey();
+ DeleteOperation deleteOperation =
+ connection.processDelete(entryDN);
+ entryTreeMap.remove(entryDN);
+ assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
+ }
+ }
}
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestVerifyJob.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestVerifyJob.java
new file mode 100644
index 0000000..dccaeca
--- /dev/null
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestVerifyJob.java
@@ -0,0 +1,144 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying * information:
+ * Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ * Portions Copyright 2006 Sun Microsystems, Inc.
+ */
+package org.opends.server.backends.jeb;
+
+import org.opends.server.config.ConfigEntry;
+import org.opends.server.core.DirectoryServer;
+import org.opends.server.TestCaseUtils;
+import org.opends.server.types.DN;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+public class TestVerifyJob extends JebTestCase
+{
+ private static String cfgDN="ds-cfg-backend-id=userRoot,cn=Backends,cn=config";
+ /* number of entries to test with */
+ private static int numEntries=10;
+ private static String vBranch = "ou=verify";
+ private static String suffix="dc=example,dc=com";
+ private static String beID="userRoot";
+
+ @DataProvider(name = "indexes")
+ public Object[][] indexes() {
+ return new Object[][] {
+ { "telephoneNumber"},
+ { "id2subtree"},
+ {"id2children"},
+ {"dn2id"}
+ };
+ }
+
+ private static String[] template = new String[] {
+ "define suffix="+suffix,
+ "define maildomain=example.com",
+ "define numusers=" + numEntries,
+ "",
+ "branch: [suffix]",
+ "",
+ "branch: " + vBranch +",[suffix]",
+ "subordinateTemplate: person:[numusers]",
+ "",
+ "template: person",
+ "rdnAttr: uid",
+ "objectClass: top",
+ "objectClass: person",
+ "objectClass: organizationalPerson",
+ "objectClass: inetOrgPerson",
+ "givenName: <first>",
+ "sn: <last>",
+ "cn: {givenName} {sn}",
+ "initials: {givenName:1}<random:chars:" +
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ:1>{sn:1}",
+ "employeeNumber: <sequential:0>",
+ "uid: user.{employeeNumber}",
+ "mail: {uid}@[maildomain]",
+ "userPassword: password",
+ "telephoneNumber: <random:telephone>",
+ "homePhone: <random:telephone>",
+ "pager: <random:telephone>",
+ "mobile: <random:telephone>",
+ "street: <random:numeric:5> <file:streets> Street",
+ "l: <file:cities>",
+ "st: <file:states>",
+ "postalCode: <random:numeric:5>",
+ "postalAddress: {cn}${street}${l}, {st} {postalCode}",
+ "description: This is the description for {cn}.",
+ ""};
+
+ @BeforeClass
+ public void setup() throws Exception {
+ TestCaseUtils.startServer();
+ createLoadEntries(template, numEntries);
+ }
+
+ @AfterClass
+ public void cleanUp() throws Exception {
+ removeLoadedEntries();
+ }
+
+ /**
+ * Performs a non-clean verify against a backend using the
+ * entries loaded in the setup initializer.
+ *
+ * @throws Exception if the verify fails.
+ */
+ @Test()
+ public void testVerifyJob() throws Exception {
+ DN configDN= DN.decode(cfgDN);
+ DN[] baseDNs = new DN[] {
+ DN.decode(suffix)
+ };
+ VerifyConfig verifyConfig = new VerifyConfig();
+ verifyConfig.setBaseDN(baseDNs[0]);
+ ConfigEntry configEntry = DirectoryServer.getConfigEntry(configDN);
+ BackendImpl be=(BackendImpl) DirectoryServer.getBackend(beID);
+ be.verifyBackend(verifyConfig, configEntry, baseDNs);
+ }
+
+
+ /**
+ * Performs a clean verify against a backend using the index
+ * name passed into it from the indexes array above.
+ * @param index Index name to verify.
+ * @throws Exception if the backend index cannot be verified.
+ */
+ @Test(dataProvider = "indexes")
+ public void testCleanVerifyJob(String index) throws Exception {
+ DN configDN= DN.decode(cfgDN);
+ DN[] baseDNs = new DN[] {
+ DN.decode(suffix)
+ };
+ VerifyConfig verifyConfig = new VerifyConfig();
+ verifyConfig.setBaseDN(baseDNs[0]);
+ verifyConfig.addCleanIndex(index);
+ ConfigEntry configEntry = DirectoryServer.getConfigEntry(configDN);
+ BackendImpl be=(BackendImpl) DirectoryServer.getBackend(beID);
+ be.verifyBackend(verifyConfig, configEntry, baseDNs);
+ }
+}
--
Gitblit v1.10.0