From 86b05df49a3e844bf3a1e13699dd29061c2d9b14 Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Mon, 28 Mar 2011 12:33:46 +0000
Subject: [PATCH] LMS-2136 EagerShufflingTask: logging added

SVN: 20510
---
 .../postregistration/EagerShufflingTask.java  |  6 +++++
 .../EagerShufflingTaskTest.java               | 22 +++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/postregistration/EagerShufflingTask.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/postregistration/EagerShufflingTask.java
index 61642adfbf3..a7f7db4e041 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/postregistration/EagerShufflingTask.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/postregistration/EagerShufflingTask.java
@@ -31,6 +31,7 @@ import ch.systemsx.cisd.common.logging.ISimpleLogger;
 import ch.systemsx.cisd.common.logging.Log4jSimpleLogger;
 import ch.systemsx.cisd.common.logging.LogCategory;
 import ch.systemsx.cisd.common.logging.LogFactory;
+import ch.systemsx.cisd.common.logging.LogLevel;
 import ch.systemsx.cisd.common.utilities.ClassUtils;
 import ch.systemsx.cisd.common.utilities.PropertyParametersUtil;
 import ch.systemsx.cisd.common.utilities.PropertyUtils;
@@ -160,6 +161,8 @@ public class EagerShufflingTask extends AbstractPostRegistrationTask
             shareWithMostFreeOrNull = finder.tryToFindShare(dataSet, shares);
             if (shareWithMostFreeOrNull == null)
             {
+                logger.log(LogLevel.WARN, "No share found for shuffling data set " + dataSetCode
+                        + ".");
                 return new NoCleanupTask();
             }
             return new NoCleanupTask();
@@ -178,6 +181,9 @@ public class EagerShufflingTask extends AbstractPostRegistrationTask
                 dataSetMover.moveDataSetToAnotherShare(
                         new File(share, dataSet.getDataSetLocation()),
                         shareWithMostFreeOrNull.getShare(), logger);
+                logger.log(LogLevel.INFO, "Data set " + dataSetCode
+                        + " succesffully moved from share " + dataSet.getDataSetShareId() + " to "
+                        + shareWithMostFreeOrNull.getShareId() + ".");
             }
         }
     }
diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/postregistration/EagerShufflingTaskTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/postregistration/EagerShufflingTaskTest.java
index d6d65bdc873..841946b16af 100644
--- a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/postregistration/EagerShufflingTaskTest.java
+++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/postregistration/EagerShufflingTaskTest.java
@@ -39,6 +39,7 @@ import ch.systemsx.cisd.common.filesystem.HostAwareFile;
 import ch.systemsx.cisd.common.filesystem.IFreeSpaceProvider;
 import ch.systemsx.cisd.common.logging.BufferedAppender;
 import ch.systemsx.cisd.common.logging.ISimpleLogger;
+import ch.systemsx.cisd.common.logging.LogLevel;
 import ch.systemsx.cisd.common.test.RecordingMatcher;
 import ch.systemsx.cisd.etlserver.plugins.IDataSetMover;
 import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService;
@@ -115,6 +116,7 @@ public class EagerShufflingTaskTest extends AbstractFileSystemTestCase
         prepareFreeSpaceProvider(hostAwareFileMatcher, 200, 100, 300, 400);
         prepareListDataSets();
         prepareGetShareId();
+        RecordingMatcher<String> infoMessageMatcher = prepareLogging(LogLevel.INFO);
         context.checking(new Expectations()
             {
                 {
@@ -126,6 +128,8 @@ public class EagerShufflingTaskTest extends AbstractFileSystemTestCase
         executor.createCleanupTask();
         executor.execute();
         
+        assertEquals("Data set ds-1 succesffully moved from share 1 to 4.",
+                infoMessageMatcher.recordedObject());
         assertHostAwareFile(hostAwareFileMatcher);
         context.assertIsSatisfied();
     }
@@ -139,6 +143,7 @@ public class EagerShufflingTaskTest extends AbstractFileSystemTestCase
         prepareFreeSpaceProvider(hostAwareFileMatcher, 200, 100, 10, 0);
         prepareListDataSets();
         prepareGetShareId();
+        RecordingMatcher<String> infoMessageMatcher = prepareLogging(LogLevel.INFO);
         context.checking(new Expectations()
             {
                 {
@@ -150,6 +155,8 @@ public class EagerShufflingTaskTest extends AbstractFileSystemTestCase
         executor.createCleanupTask();
         executor.execute();
 
+        assertEquals("Data set ds-1 succesffully moved from share 1 to 2.",
+                infoMessageMatcher.recordedObject());
         assertHostAwareFile(hostAwareFileMatcher);
         context.assertIsSatisfied();
     }
@@ -162,15 +169,30 @@ public class EagerShufflingTaskTest extends AbstractFileSystemTestCase
                 new RecordingMatcher<HostAwareFile>();
         prepareFreeSpaceProvider(hostAwareFileMatcher, 200, 10, 10, 0);
         prepareListDataSets();
+        RecordingMatcher<String> logMessageMatcher = prepareLogging(LogLevel.WARN);
         
         IPostRegistrationTaskExecutor executor = task.createExecutor(DATA_SET_CODE1);
         executor.createCleanupTask();
         executor.execute();
         
+        assertEquals("No share found for shuffling data set ds-1.",
+                logMessageMatcher.recordedObject());
         assertHostAwareFile(hostAwareFileMatcher);
         context.assertIsSatisfied();
     }
 
+    private RecordingMatcher<String> prepareLogging(final LogLevel level)
+    {
+        final RecordingMatcher<String> logMessageMatcher = new RecordingMatcher<String>();
+        context.checking(new Expectations()
+            {
+                {
+                    one(logger).log(with(level), with(logMessageMatcher));
+                }
+            });
+        return logMessageMatcher;
+    }
+
     private void prepareListDataSets()
     {
         context.checking(new Expectations()
-- 
GitLab