From 472ab9f6983def2889f0a4d29a477b1de6349e90 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Tue, 30 Jan 2007 17:27:58 +0000
Subject: [PATCH] Make sure that the modifyTimestamp in the schema entry gets updated when the add schema file task is used to update the server schema.

---
 opends/src/server/org/opends/server/tasks/AddSchemaFileTask.java                                 |    3 ++-
 opends/src/server/org/opends/server/backends/SchemaBackend.java                                  |   13 +++++++++++++
 opends/tests/unit-tests-testng/src/server/org/opends/server/tasks/AddSchemaFileTaskTestCase.java |   33 +++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+), 1 deletions(-)

diff --git a/opends/src/server/org/opends/server/backends/SchemaBackend.java b/opends/src/server/org/opends/server/backends/SchemaBackend.java
index d9d94f7..571c31f 100644
--- a/opends/src/server/org/opends/server/backends/SchemaBackend.java
+++ b/opends/src/server/org/opends/server/backends/SchemaBackend.java
@@ -218,6 +218,9 @@
   // The set of supported features for this backend.
   private HashSet<String> supportedFeatures;
 
+  // The time that the schema was last modified.
+  private long modifyTime;
+
 
 
   /**
@@ -768,6 +771,16 @@
                                valueSet));
     operationalAttrs.put(createTimestampType, attrList);
 
+    if (DirectoryServer.getSchema().getYoungestModificationTime() != modifyTime)
+    {
+      synchronized (this)
+      {
+        modifyTime = DirectoryServer.getSchema().getYoungestModificationTime();
+        modifyTimestamp =
+             GeneralizedTimeSyntax.createGeneralizedTimeValue(modifyTime);
+      }
+    }
+
     valueSet = new LinkedHashSet<AttributeValue>(1);
     valueSet.add(modifiersName);
     attrList = new ArrayList<Attribute>(1);
diff --git a/opends/src/server/org/opends/server/tasks/AddSchemaFileTask.java b/opends/src/server/org/opends/server/tasks/AddSchemaFileTask.java
index 4e6eba6..9989d36 100644
--- a/opends/src/server/org/opends/server/tasks/AddSchemaFileTask.java
+++ b/opends/src/server/org/opends/server/tasks/AddSchemaFileTask.java
@@ -29,8 +29,8 @@
 
 
 import java.io.File;
-import java.util.TreeSet;
 import java.util.List;
+import java.util.TreeSet;
 import java.util.concurrent.locks.Lock;
 
 import org.opends.server.backends.task.Task;
@@ -226,6 +226,7 @@
         }
       }
 
+      schema.setYoungestModificationTime(System.currentTimeMillis());
       DirectoryServer.setSchema(schema);
       return TaskState.COMPLETED_SUCCESSFULLY;
     }
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/tasks/AddSchemaFileTaskTestCase.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/tasks/AddSchemaFileTaskTestCase.java
index e68ca5a..b957fa1 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/tasks/AddSchemaFileTaskTestCase.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/tasks/AddSchemaFileTaskTestCase.java
@@ -80,6 +80,15 @@
   public void testAddValidSchemaFile()
          throws Exception
   {
+    // Get the last modified timestamp from the schema and then sleep for two
+    // milliseconds to make sure that any potential updates to the last
+    // modification time that it won't have any chance of happening in the same
+    // millisecond as the last update.
+    long beforeModifyTimestamp =
+              DirectoryServer.getSchema().getYoungestModificationTime();
+    Thread.sleep(2);
+
+
     SchemaTestMatchingRule matchingRule =
          new SchemaTestMatchingRule("testAddValidSchemaFileMatch",
                                     "1.3.6.1.4.1.26027.1.999.23");
@@ -144,6 +153,8 @@
 
     Task task = getCompletedTask(DN.decode(taskDNStr));
     assertEquals(task.getTaskState(), TaskState.COMPLETED_SUCCESSFULLY);
+    assertFalse(DirectoryServer.getSchema().getYoungestModificationTime() ==
+                     beforeModifyTimestamp);
   }
 
 
@@ -158,6 +169,15 @@
   public void testAddMultipleValidSchemaFiles()
          throws Exception
   {
+    // Get the last modified timestamp from the schema and then sleep for two
+    // milliseconds to make sure that any potential updates to the last
+    // modification time that it won't have any chance of happening in the same
+    // millisecond as the last update.
+    long beforeModifyTimestamp =
+              DirectoryServer.getSchema().getYoungestModificationTime();
+    Thread.sleep(2);
+
+
     String schemaDirectory = SchemaConfigManager.getSchemaDirectoryPath();
 
 
@@ -267,6 +287,8 @@
 
     Task task = getCompletedTask(DN.decode(taskDNStr));
     assertEquals(task.getTaskState(), TaskState.COMPLETED_SUCCESSFULLY);
+    assertFalse(DirectoryServer.getSchema().getYoungestModificationTime() ==
+                     beforeModifyTimestamp);
   }
 
 
@@ -351,6 +373,15 @@
   public void testAddEmptySchemaFile()
          throws Exception
   {
+    // Get the last modified timestamp from the schema and then sleep for two
+    // milliseconds to make sure that any potential updates to the last
+    // modification time that it won't have any chance of happening in the same
+    // millisecond as the last update.
+    long beforeModifyTimestamp =
+              DirectoryServer.getSchema().getYoungestModificationTime();
+    Thread.sleep(2);
+
+
     String schemaDirectory = SchemaConfigManager.getSchemaDirectoryPath();
 
     File emptyFile = new File(schemaDirectory, "05-empty.ldif");
@@ -380,6 +411,8 @@
 
     Task task = getCompletedTask(DN.decode(taskDNStr));
     assertEquals(task.getTaskState(), TaskState.COMPLETED_SUCCESSFULLY);
+    assertFalse(DirectoryServer.getSchema().getYoungestModificationTime() ==
+                     beforeModifyTimestamp);
   }
 
 

--
Gitblit v1.10.0