diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/ByExpermientPolicy.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/ByExpermientPolicy.java index 7efbabd783d509dd2d462b9c7ff7943e5bfcd080..e838f0980f05abac950769110887d9dec73d3bfe 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/ByExpermientPolicy.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/ByExpermientPolicy.java @@ -112,14 +112,22 @@ public class ByExpermientPolicy extends BaseGroupingPolicy implements IAutoArchi { DatasetListWithTotal result = new DatasetListWithTotal(); + // if there is one huge data set. archive it first for (AbstractExternalData ds : datasets) { - if (result.getCumulatedSize() + ds.getSize() > maxArchiveSize) + if (ds.getSize() >= maxArchiveSize) { - continue; // optimistically try to fit as much as possible + result.add(ds); + return result; } + } - result.add(ds); + for (AbstractExternalData ds : datasets) + { + if (result.getCumulatedSize() + ds.getSize() <= maxArchiveSize) + { + result.add(ds); + } } return result; diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/plugins/ByExperimentPolicyTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/plugins/ByExperimentPolicyTest.java index 58494b894134dddba2f00669bee03bea9215fcc6..1fd7cd9ae046a903c3bcd9a7b400fa8a2802ed26 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/plugins/ByExperimentPolicyTest.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/plugins/ByExperimentPolicyTest.java @@ -232,6 +232,28 @@ public class ByExperimentPolicyTest extends AssertJUnit context.assertIsSatisfied(); } + @Test + public void testTooBigDataSetsAreArchivedOnTheirOwn() + { + ExtendedProperties props = new ExtendedProperties(); + props.setProperty(BaseGroupingPolicy.MINIMAL_ARCHIVE_SIZE, "500"); + props.setProperty(BaseGroupingPolicy.MAXIMAL_ARCHIVE_SIZE, "1000"); + + ByExpermientPolicy policy = new ByExpermientPolicy(props); + + ArrayList<AbstractExternalData> dataSets = new ArrayList<AbstractExternalData>(); + dataSets.add(ctx.createDataset("p1", "e1", "dt1", "ds1", 7000L)); + dataSets.add(ctx.createDataset("p1", "e1", "dt1", "ds2", 8000L)); + dataSets.add(ctx.createDataset("p1", "e1", "dt1", "ds3", 9000L)); + dataSets.add(ctx.createDataset("p1", "e2", "dt1", "ds4", 9000L)); + + List<AbstractExternalData> filtered = policy.filter(dataSets); + + assertEquals("[ds1]", extractCodes(filtered).toString()); + + context.assertIsSatisfied(); + } + @Test public void testSameDatatypeIsGroupedSmalls() {