From 94e1f8b8bca9bcb9bdf585b19bdfdb47a525add8 Mon Sep 17 00:00:00 2001
From: jakubs <jakubs>
Date: Mon, 13 Feb 2012 08:56:11 +0000
Subject: [PATCH] LMS-2767: Delete precommit directory. Add checks for it to
 unit test.

SVN: 24418
---
 .../DataSetRegistrationService.java           |  2 -
 .../registrator/DataSetStorageAlgorithm.java  |  2 +
 .../AbstractJythonDataSetHandlerTest.java     | 27 +++++++++----
 .../JythonTopLevelDataSetRegistratorTest.java | 39 ++++++++++++++++++-
 4 files changed, 58 insertions(+), 12 deletions(-)

diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/DataSetRegistrationService.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/DataSetRegistrationService.java
index 1946a1f69a0..b0c5f6ae0bf 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/DataSetRegistrationService.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/DataSetRegistrationService.java
@@ -51,8 +51,6 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
 public class DataSetRegistrationService<T extends DataSetInformation> implements
         IDataSetRegistrationService
 {
-    static final String STAGING_DIR = TopLevelDataSetRegistratorGlobalState.STAGING_DIR;
-
     private final AbstractOmniscientTopLevelDataSetRegistrator<T> registrator;
 
     private final OmniscientTopLevelDataSetRegistratorState registratorContext;
diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/DataSetStorageAlgorithm.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/DataSetStorageAlgorithm.java
index 58476b179eb..b7e0196fc0d 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/DataSetStorageAlgorithm.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/DataSetStorageAlgorithm.java
@@ -621,6 +621,8 @@ public class DataSetStorageAlgorithm<T extends DataSetInformation>
                         stagedFile.getName(), storagePaths.storeBaseDirectory.getAbsolutePath(),
                         stagedFile.getName()).execute();
             }
+            
+            storagePaths.precommitBaseDirectory.delete();
         }
     }
 
diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/AbstractJythonDataSetHandlerTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/AbstractJythonDataSetHandlerTest.java
index 90f4516a3cf..9908db34c8d 100644
--- a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/AbstractJythonDataSetHandlerTest.java
+++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/AbstractJythonDataSetHandlerTest.java
@@ -95,6 +95,10 @@ public abstract class AbstractJythonDataSetHandlerTest extends AbstractFileSyste
 
     protected File stagingDirectory;
 
+    protected File prestagingDirectory;
+
+    protected File precommitDirectory;
+
     protected File incomingDataSetFile;
 
     protected File markerFile;
@@ -133,8 +137,10 @@ public abstract class AbstractJythonDataSetHandlerTest extends AbstractFileSyste
         mailClient = context.mock(IMailClient.class);
         dataSourceQueryService = context.mock(IDataSourceQueryService.class);
         dynamicTransactionQuery = context.mock(DynamicTransactionQuery.class);
-        
+
         stagingDirectory = new File(workingDirectory, "staging");
+        prestagingDirectory = new File(workingDirectory, "pre-staging");
+        precommitDirectory = new File(workingDirectory, "pre-commit");
     }
 
     @AfterMethod
@@ -177,8 +183,9 @@ public abstract class AbstractJythonDataSetHandlerTest extends AbstractFileSyste
         TopLevelDataSetRegistratorGlobalState globalState =
                 new TopLevelDataSetRegistratorGlobalState("dss",
                         ch.systemsx.cisd.openbis.dss.generic.shared.Constants.DEFAULT_SHARE_ID,
-                        workingDirectory, workingDirectory, workingDirectory, openBisService, mailClient,
-                        dataSetValidator, dataSourceQueryService, myFactory, true, threadParameters);
+                        workingDirectory, workingDirectory, workingDirectory, openBisService,
+                        mailClient, dataSetValidator, dataSourceQueryService, myFactory, true,
+                        threadParameters);
         return globalState;
     }
 
@@ -195,7 +202,7 @@ public abstract class AbstractJythonDataSetHandlerTest extends AbstractFileSyste
                 }
             });
     }
-    
+
     /**
      * adds an extension to the Jython Path, so that all libraries in it will be visible to the
      * Jython environment.
@@ -236,11 +243,15 @@ public abstract class AbstractJythonDataSetHandlerTest extends AbstractFileSyste
             threadProperties.put(ch.systemsx.cisd.etlserver.ThreadParameters.VALIDATION_SCRIPT_KEY,
                     validationScriptPropertyOrNull);
         }
-        threadProperties.setProperty(DataSetRegistrationService.STAGING_DIR,
+        threadProperties.setProperty(TopLevelDataSetRegistratorGlobalState.STAGING_DIR,
                 stagingDirectory.getPath());
-        
-        threadProperties.put(ThreadParameters.DATASET_REGISTRATION_PRE_STAGING_BEHAVIOR, "use_original");
-        
+        threadProperties.setProperty(TopLevelDataSetRegistratorGlobalState.PRE_STAGING_DIR,
+                prestagingDirectory.getPath());
+        threadProperties.setProperty(TopLevelDataSetRegistratorGlobalState.PRE_COMMIT_DIR,
+                precommitDirectory.getPath());
+        threadProperties.put(ThreadParameters.DATASET_REGISTRATION_PRE_STAGING_BEHAVIOR,
+                "use_original");
+
         return threadProperties;
     }
 
diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/JythonTopLevelDataSetRegistratorTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/JythonTopLevelDataSetRegistratorTest.java
index 9650f6c8c3f..7b60b3d380c 100644
--- a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/JythonTopLevelDataSetRegistratorTest.java
+++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/JythonTopLevelDataSetRegistratorTest.java
@@ -28,6 +28,8 @@ import java.util.Properties;
 
 import org.hamcrest.core.IsAnything;
 import org.jmock.Expectations;
+import org.jmock.api.Invocation;
+import org.jmock.lib.action.CustomAction;
 import org.python.core.PyException;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
@@ -96,6 +98,8 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractJythonDataSetH
         didServiceRollbackHappen = false;
     }
 
+    
+    
     @Test
     public void testSimpleTransaction()
     {
@@ -108,6 +112,9 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractJythonDataSetH
         final Experiment experiment = builder.getExperiment();
         final RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails> atomicatOperationDetails =
                 new RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails>();
+        
+        
+        
         context.checking(new Expectations()
             {
                 {
@@ -121,9 +128,12 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractJythonDataSetH
                     one(dataSetValidator).assertValidDataSet(DATA_SET_TYPE,
                             new File(new File(stagingDirectory, DATA_SET_CODE), "sub_data_set_1"));
                     one(openBisService).performEntityOperations(with(atomicatOperationDetails));
-                    will(returnValue(new AtomicEntityOperationResult()));
-
+                    
+                    will(doAll(returnValue(new AtomicEntityOperationResult()), checkPrecommitDirIsNotEmpty()));
+                    
                     one(openBisService).setStorageConfirmed(DATA_SET_CODE);
+                
+                    will(checkPrecommitDirIsEmpty());
                 }
             });
 
@@ -172,6 +182,31 @@ public class JythonTopLevelDataSetRegistratorTest extends AbstractJythonDataSetH
                 incomingDataSetFile.listFiles().length, 0);
     }
 
+    private CustomAction checkPrecommitDirIsEmpty()
+    {
+        return new CustomAction("foo")
+        {
+            public Object invoke(Invocation invocation) throws Throwable
+            {
+                assertEquals("[]", Arrays.asList(handler.getGlobalState().getPreCommitDir().list())
+                        .toString());
+                return null;
+            }
+        };
+    }
+    
+    private CustomAction checkPrecommitDirIsNotEmpty()
+    {
+        return new CustomAction("foo")
+        {
+            public Object invoke(Invocation invocation) throws Throwable
+            {
+                assertNotSame(0, handler.getGlobalState().getPreCommitDir().list().length);
+                return null;
+            }
+        };
+    }
+    
     private void checkStagingDirIsEmpty()
     {
         assertEquals("[]", Arrays.asList(handler.getGlobalState().getStagingDir().list())
-- 
GitLab