diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/ExperimentBasedArchivingTask.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/ExperimentBasedArchivingTask.java index 6921db5a03fec27f0ffcb6d64e1943b150cfddce..94ae0bf89a8dd504ef44241cced13848a62aad7f 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/ExperimentBasedArchivingTask.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/ExperimentBasedArchivingTask.java @@ -24,8 +24,10 @@ import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.EnumSet; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Properties; import java.util.Set; @@ -37,6 +39,8 @@ import ch.systemsx.cisd.common.exceptions.ConfigurationFailureException; import ch.systemsx.cisd.common.filesystem.HostAwareFile; import ch.systemsx.cisd.common.filesystem.IFreeSpaceProvider; import ch.systemsx.cisd.common.filesystem.SimpleFreeSpaceProvider; +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.maintenance.IDataStoreLockingMaintenanceTask; @@ -45,7 +49,6 @@ import ch.systemsx.cisd.common.utilities.ExtendedProperties; import ch.systemsx.cisd.common.utilities.PropertyParametersUtil; import ch.systemsx.cisd.common.utilities.PropertyUtils; import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; -import ch.systemsx.cisd.openbis.dss.generic.shared.IShareIdManager; import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProvider; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSet; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetArchivingStatus; @@ -68,19 +71,21 @@ public class ExperimentBasedArchivingTask implements IDataStoreLockingMaintenanc private static final Logger notificationLog = LogFactory.getLogger(LogCategory.NOTIFY, ExperimentBasedArchivingTask.class); + + private static final long ONE_KB_IN_BYTES = 1024L; static final String MINIMUM_FREE_SPACE_KEY = "minimum-free-space-in-MB"; - static final String STOREROOT_DIR_KEY = "storeroot-dir"; - - static final String MONITORED_SHARE_KEY = "monitored-share"; - static final String EXCLUDED_DATA_SET_TYPES_KEY = "excluded-data-set-types"; static final String MONITORED_DIR = "monitored-dir"; static final String FREE_SPACE_PROVIDER_PREFIX = "free-space-provider."; + static final String DATA_SET_SIZE_PREFIX = "data-set-size."; + + static final String DEFAULT_DATA_SET_TYPE = "DEFAULT"; + private static final EnumSet<DataSetArchivingStatus> ARCHIVE_STATES = EnumSet.of( DataSetArchivingStatus.ARCHIVE_PENDING, DataSetArchivingStatus.ARCHIVED); @@ -88,27 +93,22 @@ public class ExperimentBasedArchivingTask implements IDataStoreLockingMaintenanc private IFreeSpaceProvider freeSpaceProvider; - private File storeRoot; - private File monitoredDirectory; private long minimumFreeSpace; - private String shareIDOrNull; - - private final IShareIdManager shareIdManager; - private Set<String> excludedDataSetTypes; + private Map<String, Long> estimatedDataSetSizes; + public ExperimentBasedArchivingTask() { - this(ServiceProvider.getOpenBISService(), ServiceProvider.getShareIdManager()); + this(ServiceProvider.getOpenBISService()); } - ExperimentBasedArchivingTask(IEncapsulatedOpenBISService service, IShareIdManager shareIdManager) + ExperimentBasedArchivingTask(IEncapsulatedOpenBISService service) { this.service = service; - this.shareIdManager = shareIdManager; } public boolean requiresDataStoreLock() @@ -118,54 +118,27 @@ public class ExperimentBasedArchivingTask implements IDataStoreLockingMaintenanc public void setUp(String pluginName, Properties properties) { - storeRoot = setUpStoreRoot(properties); freeSpaceProvider = setUpFreeSpaceProvider(properties); - setUpMonitoredShareOrPath(properties); + monitoredDirectory = setUpMonitoredDirectory(properties); minimumFreeSpace = FileUtils.ONE_MB * PropertyUtils.getLong(properties, MINIMUM_FREE_SPACE_KEY, 1024); excludedDataSetTypes = new HashSet<String>(Arrays.asList(PropertyParametersUtil.parseItemisedProperty( properties.getProperty(EXCLUDED_DATA_SET_TYPES_KEY, ""), EXCLUDED_DATA_SET_TYPES_KEY))); + estimatedDataSetSizes = setUpEstimatedDataSetSizes(properties); } - private File setUpStoreRoot(Properties properties) - { - String storeRootFileName = - PropertyUtils.getMandatoryProperty(properties, STOREROOT_DIR_KEY); - File resultStoreRoot = new File(storeRootFileName); - if (resultStoreRoot.isDirectory() == false) - { - throw new ConfigurationFailureException( - "Store root doesn't exists or isn't a directory: " + storeRoot); - } - return resultStoreRoot; - } - - private void setUpMonitoredShareOrPath(Properties properties) + private File setUpMonitoredDirectory(Properties properties) { final String monitoredDirPath = PropertyUtils.getProperty(properties, MONITORED_DIR); - if (monitoredDirPath == null) - { - shareIDOrNull = PropertyUtils.getMandatoryProperty(properties, MONITORED_SHARE_KEY); - monitoredDirectory = new File(storeRoot, shareIDOrNull); - } else + File monitoredDir = new File(monitoredDirPath); + if (monitoredDir.isDirectory() == false) { - shareIDOrNull = null; - monitoredDirectory = new File(monitoredDirPath); - } - if (monitoredDirectory.isDirectory() == false) - { - if (monitorDataStoreShare()) - { - throw new ConfigurationFailureException("Share " + shareIDOrNull - + " doesn't exists or isn't a directory."); - } else - { - throw new ConfigurationFailureException("Directory '" + monitoredDirPath - + "' doesn't exists or isn't a directory."); - } + throw new ConfigurationFailureException("Directory '" + monitoredDirPath + + "' doesn't exists or isn't a directory."); } + return monitoredDir; } private IFreeSpaceProvider setUpFreeSpaceProvider(Properties properties) @@ -197,6 +170,27 @@ public class ExperimentBasedArchivingTask implements IDataStoreLockingMaintenanc } + private Map<String, Long> setUpEstimatedDataSetSizes(Properties properties) + { + ISimpleLogger log = new Log4jSimpleLogger(operationLog); + Properties dataSetSizeProps = + ExtendedProperties.getSubset(properties, DATA_SET_SIZE_PREFIX, true); + Map<String, Long> result = new HashMap<String, Long>(); + for (Object key : dataSetSizeProps.keySet()) + { + String dataSetType = ((String) key).toUpperCase(); + long estimatedSizeInBytes = + ONE_KB_IN_BYTES + * PropertyUtils.getPosLong(dataSetSizeProps, dataSetType, 0L, log); + if (estimatedSizeInBytes > 0) + { + result.put(dataSetType, estimatedSizeInBytes); + } + + } + return result; + } + public void execute() { long freeSpace = getFreeSpace(); @@ -232,22 +226,13 @@ public class ExperimentBasedArchivingTask implements IDataStoreLockingMaintenanc StringBuilder archivingMessages = new StringBuilder(); try { - if (monitorDataStoreShare()) - { - for (int i = 0; i < infos.size() && freeSpace < minimumFreeSpace; i++) - { - ExperimentDataSetsInfo info = infos.get(i); - freeSpace += info.calculateSize(); - archive(info, archivingMessages); - } - } else + for (int i = 0; i < infos.size() && freeSpace < minimumFreeSpace; i++) { - for (int i = 0; i < infos.size() && freeSpace < minimumFreeSpace; i++) + ExperimentDataSetsInfo info = infos.get(i); + long estimatedSpaceFreed = info.estimateSize(); + if (archive(info, archivingMessages)) { - if (archive(infos.get(i), archivingMessages)) - { - freeSpace = getFreeSpace(); - } + freeSpace += estimatedSpaceFreed; } } } finally @@ -259,16 +244,12 @@ public class ExperimentBasedArchivingTask implements IDataStoreLockingMaintenanc } } - private boolean monitorDataStoreShare() - { - return shareIDOrNull != null; - } - private long getFreeSpace() { try { - return 1024L * freeSpaceProvider.freeSpaceKb(new HostAwareFile(monitoredDirectory)); + return ONE_KB_IN_BYTES + * freeSpaceProvider.freeSpaceKb(new HostAwareFile(monitoredDirectory)); } catch (IOException ex) { throw CheckedExceptionTunnel.wrapIfNecessary(ex); @@ -314,11 +295,6 @@ public class ExperimentBasedArchivingTask implements IDataStoreLockingMaintenanc continue; } DataSet realDataSet = (DataSet) dataSet; - if (shareIDOrNull != null - && realDataSet.getShareId().equals(shareIDOrNull) == false) - { - continue; - } if (excludedDataSetTypes.contains(realDataSet.getDataSetType().getCode())) { continue; @@ -345,32 +321,37 @@ public class ExperimentBasedArchivingTask implements IDataStoreLockingMaintenanc } } - long calculateSize() + public long estimateSize() { - long sum = 0; - for (DataSet dataSet : dataSetsToBeArchived) + long sum = 0L; + for (DataSet dataSetToBeArchived : getDataSetsToBeArchived()) { - Long size = dataSet.getSize(); - if (size == null) - { - String dataSetCode = dataSet.getCode(); - shareIdManager.lock(dataSetCode); - try - { - File shareRoot = - new File(storeRoot, shareIdManager.getShareId(dataSetCode)); - String location = dataSet.getLocation(); - size = FileUtils.sizeOfDirectory(new File(shareRoot, location)); - } finally - { - shareIdManager.releaseLock(dataSetCode); - } - } - sum += size; + sum += estimateSize(dataSetToBeArchived); } return sum; } + private long estimateSize(DataSet dataSet) + { + String dataSetType = dataSet.getDataSetType().getCode().toUpperCase(); + Long estimatedDataSetSize = estimatedDataSetSizes.get(dataSetType); + if (estimatedDataSetSize == null) + { + estimatedDataSetSize = estimatedDataSetSizes.get(DEFAULT_DATA_SET_TYPE); + } + if (estimatedDataSetSize == null) + { + throw ConfigurationFailureException + .fromTemplate( + "Failed to estimate the average size for data set type '%s'. " + + "Please, configure the maintenance task with a '%s' or a '%s' property. ", + dataSetType, DATA_SET_SIZE_PREFIX + dataSetType, + DATA_SET_SIZE_PREFIX + DEFAULT_DATA_SET_TYPE); + + } + return estimatedDataSetSize.longValue(); + } + public String getExperimentIdentifier() { return experimentIdentifier; @@ -409,5 +390,4 @@ public class ExperimentBasedArchivingTask implements IDataStoreLockingMaintenanc return 0; } } - } diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/plugins/ExperimentBasedArchivingTaskTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/plugins/ExperimentBasedArchivingTaskTest.java index 66ab3308ed75bba2869997a69d7f6ba470f33e70..2f00fa70e04ae15c90995f0eac22f8bb5c26c11f 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/plugins/ExperimentBasedArchivingTaskTest.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/plugins/ExperimentBasedArchivingTaskTest.java @@ -24,7 +24,6 @@ import java.util.Date; import java.util.List; import java.util.Properties; -import org.apache.commons.io.FileUtils; import org.apache.log4j.Level; import org.jmock.Expectations; import org.jmock.Mockery; @@ -39,7 +38,6 @@ import ch.systemsx.cisd.common.filesystem.IFreeSpaceProvider; import ch.systemsx.cisd.common.logging.BufferedAppender; import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; -import ch.systemsx.cisd.openbis.dss.generic.shared.IShareIdManager; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSet; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetArchivingStatus; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment; @@ -82,8 +80,6 @@ public class ExperimentBasedArchivingTaskTest extends AbstractFileSystemTestCase private static final String LOCATION_PREFIX = "abc/"; - private static final String SHARE_ID = "3"; - private BufferedAppender logRecorder; private Mockery context; @@ -92,14 +88,12 @@ public class ExperimentBasedArchivingTaskTest extends AbstractFileSystemTestCase private IFreeSpaceProvider freeSpaceProvider; - private IShareIdManager shareIdManager; - private ExperimentBasedArchivingTask task; - private File share; - private Properties properties; + private File monitoredDir; + private Experiment e1; private Experiment e2; @@ -110,8 +104,6 @@ public class ExperimentBasedArchivingTaskTest extends AbstractFileSystemTestCase private ExternalData notARealDataSet; - private DataSet dataSetInAShareToBeIgnored; - private DataSet dataSetOfIgnoredType; private DataSet dataSetWithNoModificationDate; @@ -131,10 +123,9 @@ public class ExperimentBasedArchivingTaskTest extends AbstractFileSystemTestCase context = new Mockery(); service = context.mock(IEncapsulatedOpenBISService.class); freeSpaceProvider = context.mock(IFreeSpaceProvider.class); - shareIdManager = context.mock(IShareIdManager.class); MockFreeSpaceProvider.mock = freeSpaceProvider; - task = new ExperimentBasedArchivingTask(service, shareIdManager); + task = new ExperimentBasedArchivingTask(service); assertEquals(true, task.requiresDataStoreLock()); e1 = new ExperimentBuilder().id(41).identifier("/S/P/E1").getExperiment(); @@ -144,9 +135,6 @@ public class ExperimentBasedArchivingTaskTest extends AbstractFileSystemTestCase lockedDataSet = dataSet("lockedDataSet").modificationDate(new Date(100)) .status(DataSetArchivingStatus.LOCKED).getDataSet(); - dataSetInAShareToBeIgnored = - dataSet("dataSetInAShareToBeIgnored").modificationDate(new Date(120)).shareID("42") - .getDataSet(); dataSetOfIgnoredType = dataSet("dataSetOfIgnoredType").type("ABC").getDataSet(); dataSetWithNoModificationDate = dataSet("dataSetWithNoModificationDate").getDataSet(); oldDataSet = dataSet("oldDataSet").modificationDate(new Date(300)).getDataSet(); @@ -155,44 +143,24 @@ public class ExperimentBasedArchivingTaskTest extends AbstractFileSystemTestCase veryYoungDataSet = dataSet("veryYoungDataSet").modificationDate(new Date(2000)).getDataSet(); - share = new File(workingDirectory, "store/" + SHARE_ID); - share.mkdirs(); properties = new Properties(); - properties.setProperty(ExperimentBasedArchivingTask.STOREROOT_DIR_KEY, share.getParent()); - properties.setProperty(ExperimentBasedArchivingTask.MONITORED_SHARE_KEY, SHARE_ID); properties.setProperty(ExperimentBasedArchivingTask.MINIMUM_FREE_SPACE_KEY, "100"); properties.setProperty(ExperimentBasedArchivingTask.EXCLUDED_DATA_SET_TYPES_KEY, "ABC, B"); + monitoredDir = new File(workingDirectory, "/some/dir"); + monitoredDir.mkdirs(); + properties.setProperty(ExperimentBasedArchivingTask.MONITORED_DIR, + monitoredDir.getAbsolutePath()); properties.setProperty(ExperimentBasedArchivingTask.FREE_SPACE_PROVIDER_PREFIX + "class", MockFreeSpaceProvider.class.getName()); } private DataSetBuilder dataSet(String code) { - return new DataSetBuilder().code(code).shareID(SHARE_ID).type("A") + return new DataSetBuilder().code(code).type("A") .location(LOCATION_PREFIX + code).status(DataSetArchivingStatus.AVAILABLE) .registrationDate(new Date(100)); } - private void writeSomeDataTo(DataSet dataSet, int numberOfBytes) - { - File dataSetFolder = - new File(new File(share.getParentFile(), dataSet.getShareId()), - dataSet.getLocation()); - dataSetFolder.mkdirs(); - byte[] data = new byte[numberOfBytes]; - for (int i = 0; i < numberOfBytes; i++) - { - data[i] = (byte) i; - } - try - { - FileUtils.writeByteArrayToFile(new File(dataSetFolder, "data"), data); - } catch (IOException ex) - { - throw CheckedExceptionTunnel.wrapIfNecessary(ex); - } - } - @AfterMethod public void afterMethod() { @@ -211,6 +179,7 @@ public class ExperimentBasedArchivingTaskTest extends AbstractFileSystemTestCase lockedDataSet.setSize(100L); oldDataSet.setSize(20L); youngDataSet.setSize(10L); + prepareSizesAndTypes(lockedDataSet, oldDataSet, youngDataSet); prepareArchivingDataSets(oldDataSet, youngDataSet); task.setUp("", properties); @@ -249,22 +218,6 @@ public class ExperimentBasedArchivingTaskTest extends AbstractFileSystemTestCase context.assertIsSatisfied(); } - @Test - public void testArchiveExperimentContainingDataSetsFromDifferentShare() - { - prepareFreeSpaceProvider(99L); - prepareListExperiments(e1); - prepareListDataSetsOf(e1, dataSetInAShareToBeIgnored, youngDataSet); - youngDataSet.setSize(10L); - prepareArchivingDataSets(youngDataSet); - - task.setUp("", properties); - task.execute(); - - checkLog(logEntry(e1, youngDataSet)); - context.assertIsSatisfied(); - } - @Test public void testArchiveExperimentContainingDataSetsOfAnyType() { @@ -272,8 +225,9 @@ public class ExperimentBasedArchivingTaskTest extends AbstractFileSystemTestCase prepareFreeSpaceProvider(99L); prepareListExperiments(e1); prepareListDataSetsOf(e1, dataSetOfIgnoredType, youngDataSet); - dataSetOfIgnoredType.setSize(20L); + prepareDefaultDataSetSize(20L); youngDataSet.setSize(10L); + prepareSizesAndTypes(youngDataSet); prepareArchivingDataSets(dataSetOfIgnoredType, youngDataSet); task.setUp("", properties); @@ -290,6 +244,7 @@ public class ExperimentBasedArchivingTaskTest extends AbstractFileSystemTestCase prepareListExperiments(e1); prepareListDataSetsOf(e1, dataSetOfIgnoredType, youngDataSet); youngDataSet.setSize(10L); + prepareSizesAndTypes(youngDataSet); prepareArchivingDataSets(youngDataSet); task.setUp("", properties); @@ -312,6 +267,7 @@ public class ExperimentBasedArchivingTaskTest extends AbstractFileSystemTestCase middleOldDataSet.setSize(10L); prepareArchivingDataSets(oldDataSet); prepareArchivingDataSets(middleOldDataSet); + prepareSizesAndTypes(oldDataSet, middleOldDataSet); task.setUp("", properties); task.execute(); @@ -320,23 +276,6 @@ public class ExperimentBasedArchivingTaskTest extends AbstractFileSystemTestCase context.assertIsSatisfied(); } - @Test - public void testCalculatingDataSetSize() - { - prepareFreeSpaceProvider(99L); - prepareListExperiments(e1); - prepareListDataSetsOf(e1, youngDataSet); - writeSomeDataTo(youngDataSet, 700 * 1024); - prepareRetrievingShareIdFor(youngDataSet); - prepareArchivingDataSets(youngDataSet); - - task.setUp("", properties); - task.execute(); - - checkLog(logEntry(e1, youngDataSet)); - context.assertIsSatisfied(); - } - @Test public void testArchiveExperimentsUntilThereIsEnoughFreeSpace() { @@ -344,8 +283,9 @@ public class ExperimentBasedArchivingTaskTest extends AbstractFileSystemTestCase prepareListExperiments(e1, e2); prepareListDataSetsOf(e1, veryYoungDataSet); prepareListDataSetsOf(e2, oldDataSet, youngDataSet); - oldDataSet.setSize(500 * 1024L); - youngDataSet.setSize(700 * 1024L); + oldDataSet.setSize(500L); + youngDataSet.setSize(700L); + prepareSizesAndTypes(oldDataSet, youngDataSet); prepareArchivingDataSets(oldDataSet, youngDataSet); task.setUp("", properties); @@ -356,29 +296,29 @@ public class ExperimentBasedArchivingTaskTest extends AbstractFileSystemTestCase } @Test - public void testArchiveExperimentsWithMonitoredDirectoryUntilThereIsEnoughFreeSpace() + public void testArchiveAllExperiments() { - final File monitored = new File(workingDirectory, "/some/dir"); - monitored.mkdirs(); - prepareFreeSpaceProvider(monitored, 90L, 95L, 101L); + prepareFreeSpaceProvider(90L); prepareListExperiments(e3, e1, e2); - prepareListDataSetsOf(e3, lockedDataSet, dataSetInAShareToBeIgnored); + prepareListDataSetsOf(e3, lockedDataSet, dataSetWithNoModificationDate); prepareListDataSetsOf(e1, veryYoungDataSet); prepareListDataSetsOf(e2, oldDataSet, youngDataSet); - lockedDataSet.setSize(1000 * 1024L); - dataSetInAShareToBeIgnored.setSize(100 * 1024L); - oldDataSet.setSize(500 * 1024L); - youngDataSet.setSize(700 * 1024L); - prepareArchivingDataSets(dataSetInAShareToBeIgnored); + lockedDataSet.setSize(1000L); + dataSetWithNoModificationDate.setSize(100L); + oldDataSet.setSize(500L); + youngDataSet.setSize(700L); + prepareArchivingDataSets(dataSetWithNoModificationDate); prepareArchivingDataSets(oldDataSet, youngDataSet); - properties.remove(ExperimentBasedArchivingTask.MONITORED_SHARE_KEY); - properties.put(ExperimentBasedArchivingTask.MONITORED_DIR, monitored.getPath()); + prepareArchivingDataSets(veryYoungDataSet); + prepareDefaultDataSetSize(5000L); + prepareSizesAndTypes(dataSetWithNoModificationDate, oldDataSet, youngDataSet); + task.setUp("", properties); task.execute(); - checkLog(true, logEntry(e3, dataSetInAShareToBeIgnored), - logEntry(e2, oldDataSet, youngDataSet)); + checkLog(true, logEntry(e3, dataSetWithNoModificationDate), + logEntry(e2, oldDataSet, youngDataSet), logEntry(e1, veryYoungDataSet)); context.assertIsSatisfied(); } @@ -391,8 +331,10 @@ public class ExperimentBasedArchivingTaskTest extends AbstractFileSystemTestCase prepareListDataSetsOf(e2, dataSetWithNoModificationDate); prepareArchivingDataSets(youngDataSet); prepareArchivingDataSets(dataSetWithNoModificationDate); - youngDataSet.setSize(700 * 1024L); - dataSetWithNoModificationDate.setSize(500 * 1024L); + youngDataSet.setSize(700L); + dataSetWithNoModificationDate.setSize(500L); + + prepareSizesAndTypes(youngDataSet, dataSetWithNoModificationDate); task.setUp("", properties); task.execute(); @@ -434,21 +376,19 @@ public class ExperimentBasedArchivingTaskTest extends AbstractFileSystemTestCase private void prepareFreeSpaceProvider(final long freeSpace) { - prepareFreeSpaceProvider(share, freeSpace); + prepareFreeSpaceProvider(monitoredDir, freeSpace); } - private void prepareFreeSpaceProvider(final File dir, final long... freeSpace) + private void prepareFreeSpaceProvider(final File dir, final long freeSpace) { context.checking(new Expectations() { { try { - for (long fs : freeSpace) - { - one(freeSpaceProvider).freeSpaceKb(new HostAwareFile(dir)); - will(returnValue(1024L * fs)); - } + File absoluteFile = new File(dir.getAbsolutePath()); + one(freeSpaceProvider).freeSpaceKb(new HostAwareFile(absoluteFile)); + will(returnValue(1024L * freeSpace)); } catch (IOException ex) { throw CheckedExceptionTunnel.wrapIfNecessary(ex); @@ -485,26 +425,31 @@ public class ExperimentBasedArchivingTaskTest extends AbstractFileSystemTestCase }); } - private void prepareArchivingDataSets(ExternalData... dataSets) + private void prepareDefaultDataSetSize(long defaultSize) { - final List<String> dataSetCodes = getDataSetCodes(dataSets); - context.checking(new Expectations() - { - { - one(service).archiveDataSets(dataSetCodes, true); - } - }); + properties.put(ExperimentBasedArchivingTask.DATA_SET_SIZE_PREFIX + + ExperimentBasedArchivingTask.DEFAULT_DATA_SET_TYPE, "" + defaultSize); } - private void prepareRetrievingShareIdFor(final DataSet dataSet) + private void prepareSizesAndTypes(DataSet... dataSets) { + for (DataSet dataSet : dataSets) + { + String dataSetSize = String.valueOf(dataSet.getSize()); + String dataSetType = "DS_TYPE_" + dataSetSize; + dataSet.getDataSetType().setCode(dataSetType); + properties.put(ExperimentBasedArchivingTask.DATA_SET_SIZE_PREFIX + dataSetType, + dataSetSize); + } + } + + private void prepareArchivingDataSets(ExternalData... dataSets) + { + final List<String> dataSetCodes = getDataSetCodes(dataSets); context.checking(new Expectations() { { - one(shareIdManager).lock(dataSet.getCode()); - one(shareIdManager).getShareId(dataSet.getCode()); - will(returnValue(dataSet.getShareId())); - one(shareIdManager).releaseLock(dataSet.getCode()); + one(service).archiveDataSets(dataSetCodes, true); } }); }