From 0970a537bfaaa0238347e42e54d9458d7da6b595 Mon Sep 17 00:00:00 2001
From: Gary Williams <gary.williams@forgerock.com>
Date: Mon, 19 Mar 2012 17:59:33 +0000
Subject: [PATCH] Functional tests show tail of error log on stopping server

---
 opendj-sdk/opends/tests/staf-tests/shared/functions/dsadm.xml |   33 ++++++++++++++++++++++++++++++++-
 opendj-sdk/opends/tests/staf-tests/shared/python/common.py    |   12 ++++++++++--
 opendj-sdk/opends/tests/staf-tests/shared/functions/utils.xml |   13 ++++++++-----
 3 files changed, 50 insertions(+), 8 deletions(-)

diff --git a/opendj-sdk/opends/tests/staf-tests/shared/functions/dsadm.xml b/opendj-sdk/opends/tests/staf-tests/shared/functions/dsadm.xml
index 19f8906..8fc4cef 100755
--- a/opendj-sdk/opends/tests/staf-tests/shared/functions/dsadm.xml
+++ b/opendj-sdk/opends/tests/staf-tests/shared/functions/dsadm.xml
@@ -657,6 +657,15 @@
           STAFCmdParamsList.append('-H')
  
         STAFCmdParams=' '.join(STAFCmdParamsList)
+
+        from java.util import Date
+        from java.text import SimpleDateFormat
+        import re
+        
+        pattern=re.compile("\[(.*)\]")
+        formatter = SimpleDateFormat("dd/MMM/yy:H:m:s Z")
+
+        stop_current_time = Date()
       </script>
       
       <message>
@@ -700,6 +709,28 @@
           </else>
         </if>
       </if>
+
+      <!-- Get Errors log -->
+      <message>
+        'Getting tail of error log on %s/logs/errors' % dsPath
+      </message>
+      <call function="'getFile'">
+        { 'location'    : location,
+          'filename'    : '%s/logs/errors' % dsPath
+        }
+      </call>
+      <script>
+        for line in STAXResult[1].split('\n'):
+          mymatch = pattern.match(line)
+          if mymatch:
+            timestamp=mymatch.group(1)
+            timestamp_object = formatter.parse(timestamp)
+            if date_compare(stop_current_time,timestamp_object) == 'Less':
+              print line
+      </script>
+      <message>
+        'Result = %s' % STAXResult
+      </message>
     </sequence>
   </function>
 
@@ -1041,7 +1072,7 @@
       </call>
 
       <script>
-         savSTAXResult = STAXResult
+        savSTAXResult = STAXResult
         resultString = STAXResult[0][1]
       </script>
 
diff --git a/opendj-sdk/opends/tests/staf-tests/shared/functions/utils.xml b/opendj-sdk/opends/tests/staf-tests/shared/functions/utils.xml
index b198112..2ab9b55 100755
--- a/opendj-sdk/opends/tests/staf-tests/shared/functions/utils.xml
+++ b/opendj-sdk/opends/tests/staf-tests/shared/functions/utils.xml
@@ -798,11 +798,14 @@
       </loop>
 
       <if expr="checkRC != 48">
-        <message>
-          'Server is not stopped after %sms \
-          (%s/logs/server.pid still exists on %s)' \
-          % (noOfLoops*noOfMilliSeconds,dsPath,location)
-        </message>
+        <sequence>
+          <message>
+            'Server is not stopped after %sms \
+            (%s/logs/server.pid still exists on %s)' \
+            % (noOfLoops*noOfMilliSeconds,dsPath,location)
+          </message>
+          <tcstatus result="'fail'"/>
+        </sequence>
       </if>
     </sequence>
   </function>
diff --git a/opendj-sdk/opends/tests/staf-tests/shared/python/common.py b/opendj-sdk/opends/tests/staf-tests/shared/python/common.py
index 4a54c8e..b50c9bf 100644
--- a/opendj-sdk/opends/tests/staf-tests/shared/python/common.py
+++ b/opendj-sdk/opends/tests/staf-tests/shared/python/common.py
@@ -24,7 +24,7 @@
 #
 #
 #      Copyright 2007-2009 Sun Microsystems, Inc.
-#      Portions Copyright 2011 ForgeRock AS.
+#      Portions Copyright 2011-2012 ForgeRock AS.
 
 __version__ = "$Revision$"
 # $Source$
@@ -57,7 +57,8 @@
             "host_is_localhost" ,
             "md5_hash" ,
             "value_not_string" ,
-            "get_system_uid"
+            "get_system_uid" ,
+            "date_compare"
             ]
 
 class format_testcase:
@@ -881,3 +882,10 @@
   from java.lang import System
   return System.getProperty("user.name")
 
+def date_compare(date1,date2):
+  if date1.compareTo(date2) > 0:
+    return "Greater"
+  elif date1.compareTo(date2) < 0:
+    return "Less"
+  else:
+    return "Equal"

--
Gitblit v1.10.0