From e25d897908d93ab4f9cabadb1029ad3352602d5d Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Wed, 31 Oct 2007 22:19:14 +0000
Subject: [PATCH] This set of fixes mainly address the issues where the JE backend does not handle attributes with options and subtypes correctly when they are being indexed.  With this fix: - All values of an indexed attribute type will be indexed correctly on modifies, adds, and deletes.  - Updates to subordinate types will now update the superior type if its indexed.  - Adding and deleting superior attribute types that are not allowed by any object classes (ie. name) will be correctly handled - Deleting all values from an attribute with no options will no longer delete the values from the same attribute but with options.  

---
 opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestBackendImpl.java |  154 +++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 136 insertions(+), 18 deletions(-)

diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestBackendImpl.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestBackendImpl.java
index 8595001..10f0180 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestBackendImpl.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestBackendImpl.java
@@ -129,6 +129,9 @@
         "objectClass: organizationalPerson",
         "objectClass: inetOrgPerson",
         "givenName: Aaren",
+        "givenName;lang-fr: test2",
+        "givenName;lang-cn: test2",
+        "givenName;lang-es: test3",
         "sn: Atp",
         "cn: Aaren Atp",
         "initials: APA",
@@ -1019,7 +1022,8 @@
     Entry newEntry;
     EntryID entryID;
     AttributeType attribute;
-    AttributeIndex index;
+    AttributeIndex titleIndex;
+    AttributeIndex nameIndex;
     HashSet<ASN1OctetString> addKeys;
     DatabaseEntry key;
     PresenceIndexer presenceIndexer;
@@ -1036,12 +1040,46 @@
       ArrayList<Modification> modifications = new ArrayList<Modification>();
       modifications.add(new Modification(ModificationType.ADD, new
           Attribute("title", "debugger")));
+
+      attribute = DirectoryServer.getAttributeType("title");
+      LinkedHashSet<AttributeValue> values = new LinkedHashSet<AttributeValue>();
+      values.add(new AttributeValue(attribute, "debugger2"));
+      LinkedHashSet<String> options = new LinkedHashSet<String>(1);
+      options.add("lang-en");
+      Attribute attr = new Attribute(attribute, "title", options, values);
+      modifications.add(new Modification(ModificationType.ADD, attr));
+
       modifications.add(new Modification(ModificationType.DELETE, new
           Attribute("cn", "Aaren Atp")));
       modifications.add(new Modification(ModificationType.ADD, new
           Attribute("cn", "Aaren Rigor")));
       modifications.add(new Modification(ModificationType.ADD, new
           Attribute("cn", "Aarenister Rigor")));
+
+      attribute = DirectoryServer.getAttributeType("givenname");
+      values = new LinkedHashSet<AttributeValue>();
+      values.add(new AttributeValue(attribute, "test"));
+      options = new LinkedHashSet<String>(1);
+      options.add("lang-de");
+      attr = new Attribute(attribute, "givenName", options, values);
+      modifications.add(new Modification(ModificationType.ADD, attr));
+
+      attribute = DirectoryServer.getAttributeType("givenname");
+      values = new LinkedHashSet<AttributeValue>();
+      values.add(new AttributeValue(attribute, "test2"));
+      options = new LinkedHashSet<String>(1);
+      options.add("lang-cn");
+      attr = new Attribute(attribute, "givenName", options, values);
+      modifications.add(new Modification(ModificationType.DELETE, attr));
+
+      attribute = DirectoryServer.getAttributeType("givenname");
+      values = new LinkedHashSet<AttributeValue>();
+      values.add(new AttributeValue(attribute, "newtest3"));
+      options = new LinkedHashSet<String>(1);
+      options.add("lang-es");
+      attr = new Attribute(attribute, "givenName", options, values);
+      modifications.add(new Modification(ModificationType.REPLACE, attr));
+
       modifications.add(new Modification(ModificationType.REPLACE, new
           Attribute("employeenumber", "222")));
 
@@ -1053,19 +1091,31 @@
       assertNotNull(entryID);
 
 
-      attribute = newEntry.getAttribute("title").get(0).getAttributeType();
-      index = ec.getAttributeIndex(attribute);
+      attribute = DirectoryServer.getAttributeType("title");
+      titleIndex = ec.getAttributeIndex(attribute);
+      attribute = DirectoryServer.getAttributeType("name");
+      nameIndex = ec.getAttributeIndex(attribute);
 
-      //This current entry in the DB shouldn't be in the presence index.
+      //This current entry in the DB shouldn't be in the presence titleIndex.
       addKeys = new HashSet<ASN1OctetString>();
       addKeys.add(new ASN1OctetString(AttributeIndex.presenceKey.getData()));
       key = new DatabaseEntry();
       for (ASN1OctetString keyBytes : addKeys) {
         key.setData(keyBytes.value());
       }
-      assertEquals(index.presenceIndex.containsID(null, key, entryID),
+      assertEquals(titleIndex.presenceIndex.containsID(null, key, entryID),
           ConditionResult.FALSE);
 
+      //This current entry should be in the presence nameIndex.
+      addKeys = new HashSet<ASN1OctetString>();
+      addKeys.add(new ASN1OctetString(AttributeIndex.presenceKey.getData()));
+      key = new DatabaseEntry();
+      for (ASN1OctetString keyBytes : addKeys) {
+        key.setData(keyBytes.value());
+      }
+      assertEquals(nameIndex.presenceIndex.containsID(null, key, entryID),
+          ConditionResult.TRUE);
+
       ArrayList<Control> noControls = new ArrayList<Control>(0);
       InternalClientConnection conn =
           InternalClientConnection.getRootConnection();
@@ -1098,55 +1148,123 @@
               entry.getAttribute("cn").get(0).getAttributeType(),
               "Aaren Atp")));
 
+      options = new LinkedHashSet<String>();
+      options.add("lang-de");
+      assertTrue(entry.getAttribute("givenname", options).get(0).getValues().contains(
+          new AttributeValue(
+              entry.getAttribute("givenname", options).get(0).getAttributeType(),
+              "test")));
+      options = new LinkedHashSet<String>();
+      options.add("lang-cn");
+      assertNull
+          (entry.getAttribute("givenname", options));
+      options = new LinkedHashSet<String>();
+      options.add("lang-es");
+      assertTrue(entry.getAttribute("givenname", options).get(0).getValues().contains(
+          new AttributeValue(
+              entry.getAttribute("givenname", options).get(0).getAttributeType(),
+              "newtest3")));
+      options = new LinkedHashSet<String>();
+      options.add("lang-fr");
+      assertTrue(entry.getAttribute("givenname", options).get(0).getValues().contains(
+          new AttributeValue(
+              entry.getAttribute("givenname", options).get(0).getAttributeType(),
+              "test2")));
+
       assertTrue(entry.getAttribute("employeenumber").contains(new
           Attribute("employeenumber", "222")));
       assertFalse(entry.getAttribute("employeenumber").contains(new
           Attribute("employeenumber", "1")));
 
       addKeys = new HashSet<ASN1OctetString>();
-      presenceIndexer = new PresenceIndexer(index.getAttributeType());
+      presenceIndexer = new PresenceIndexer(titleIndex.getAttributeType());
       presenceIndexer.indexEntry(null, entry, addKeys);
 
       key = new DatabaseEntry();
       for (ASN1OctetString keyBytes : addKeys) {
         key.setData(keyBytes.value());
-      }
-      assertEquals(index.presenceIndex.containsID(null, key, entryID),
+        assertEquals(titleIndex.presenceIndex.containsID(null, key, entryID),
           ConditionResult.TRUE);
+      }
 
       addKeys = new HashSet<ASN1OctetString>();
-      orderingIndexer = new OrderingIndexer(index.getAttributeType());
+      presenceIndexer = new PresenceIndexer(nameIndex.getAttributeType());
+      presenceIndexer.indexEntry(null, entry, addKeys);
+
+      key = new DatabaseEntry();
+      for (ASN1OctetString keyBytes : addKeys) {
+        key.setData(keyBytes.value());
+        assertEquals(nameIndex.presenceIndex.containsID(null, key, entryID),
+          ConditionResult.TRUE);
+      }
+
+      addKeys = new HashSet<ASN1OctetString>();
+      orderingIndexer = new OrderingIndexer(titleIndex.getAttributeType());
       orderingIndexer.indexEntry(null, entry, addKeys);
 
       key = new DatabaseEntry();
       for (ASN1OctetString keyBytes : addKeys) {
         key.setData(keyBytes.value());
-      }
-      assertEquals(index.orderingIndex.containsID(null, key, entryID),
+        assertEquals(titleIndex.orderingIndex.containsID(null, key, entryID),
           ConditionResult.TRUE);
+      }
 
       addKeys = new HashSet<ASN1OctetString>();
-      equalityIndexer = new EqualityIndexer(index.getAttributeType());
+      orderingIndexer = new OrderingIndexer(nameIndex.getAttributeType());
+      orderingIndexer.indexEntry(null, entry, addKeys);
+
+      key = new DatabaseEntry();
+      for (ASN1OctetString keyBytes : addKeys) {
+        key.setData(keyBytes.value());
+        assertEquals(nameIndex.orderingIndex.containsID(null, key, entryID),
+          ConditionResult.TRUE);
+      }
+
+      addKeys = new HashSet<ASN1OctetString>();
+      equalityIndexer = new EqualityIndexer(titleIndex.getAttributeType());
       equalityIndexer.indexEntry(null, entry, addKeys);
 
       key = new DatabaseEntry();
       for (ASN1OctetString keyBytes : addKeys) {
         key.setData(keyBytes.value());
-      }
-      assertEquals(index.equalityIndex.containsID(null, key, entryID),
+        assertEquals(titleIndex.equalityIndex.containsID(null, key, entryID),
           ConditionResult.TRUE);
+      }
 
       addKeys = new HashSet<ASN1OctetString>();
-      substringIndexer = new SubstringIndexer(index.getAttributeType(),
-                   index.getConfiguration().getSubstringLength());
+      equalityIndexer = new EqualityIndexer(nameIndex.getAttributeType());
+      equalityIndexer.indexEntry(null, entry, addKeys);
+
+      key = new DatabaseEntry();
+      for (ASN1OctetString keyBytes : addKeys) {
+        key.setData(keyBytes.value());
+        assertEquals(nameIndex.equalityIndex.containsID(null, key, entryID),
+          ConditionResult.TRUE);
+      }
+
+      addKeys = new HashSet<ASN1OctetString>();
+      substringIndexer = new SubstringIndexer(titleIndex.getAttributeType(),
+                   titleIndex.getConfiguration().getSubstringLength());
       substringIndexer.indexEntry(null, entry, addKeys);
 
       key = new DatabaseEntry();
       for (ASN1OctetString keyBytes : addKeys) {
         key.setData(keyBytes.value());
-      }
-      assertEquals(index.substringIndex.containsID(null, key, entryID),
+        assertEquals(titleIndex.substringIndex.containsID(null, key, entryID),
           ConditionResult.TRUE);
+      }
+
+      addKeys = new HashSet<ASN1OctetString>();
+      substringIndexer = new SubstringIndexer(nameIndex.getAttributeType(),
+                   nameIndex.getConfiguration().getSubstringLength());
+      substringIndexer.indexEntry(null, entry, addKeys);
+
+      key = new DatabaseEntry();
+      for (ASN1OctetString keyBytes : addKeys) {
+        key.setData(keyBytes.value());
+        assertEquals(nameIndex.substringIndex.containsID(null, key, entryID),
+          ConditionResult.TRUE);
+      }
     }
     finally
     {

--
Gitblit v1.10.0