Skip to content
Snippets Groups Projects
Commit bf617b94 authored by felmer's avatar felmer
Browse files

LMS-2761 chaching improved and tested

SVN: 24591
parent ade7da0c
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
*/
public class Cache
{
private static final long LIVE_TIME = 1000;
static final long LIVE_TIME = 1000;
private static final class TimeStampedObject<T>
{
......@@ -71,7 +71,7 @@ public class Cache
return getObject(externalData, code);
}
void putDataSet(ExternalData dataSet)
void putExternalData(ExternalData dataSet)
{
externalData.put(dataSet.getCode(), timestamp(dataSet));
}
......@@ -81,7 +81,7 @@ public class Cache
return getObject(experiments, experimentId);
}
void putDataSet(Experiment experiment)
void putExperiment(Experiment experiment)
{
experiments.put(experiment.getIdentifier(), timestamp(experiment));
}
......
......@@ -111,7 +111,7 @@ public class FtpPathResolverContext
service.listDataSetsByCode(sessionToken, codesToAskFor);
for (ExternalData newDataSet : newDataSets)
{
cache.putDataSet(newDataSet);
cache.putExternalData(newDataSet);
dataSets.add(newDataSet);
}
}
......@@ -131,7 +131,7 @@ public class FtpPathResolverContext
Collections.singletonList(experimentIdentifier),
new ExperimentFetchOptions());
experiment = result.isEmpty() ? null : result.get(0);
cache.putDataSet(experiment);
cache.putExperiment(experiment);
}
return experiment;
}
......
/*
* Copyright 2012 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.dss.generic.server.ftp;
import org.testng.AssertJUnit;
import org.testng.annotations.Test;
import ch.systemsx.cisd.common.utilities.ITimeProvider;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet.DataSetInitializer;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.EntityRegistrationDetails;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.EntityRegistrationDetails.EntityRegistrationDetailsInitializer;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ContainerDataSet;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
/**
*
*
* @author Franz-Josef Elmer
*/
public class CacheTest extends AssertJUnit
{
@Test
public void testGetDataSet()
{
DataSetInitializer initializer = new DataSetInitializer();
initializer.setCode("ds1");
initializer.setDataSetTypeCode("A");
initializer.setExperimentIdentifier("E");
EntityRegistrationDetailsInitializer initializer2 = new EntityRegistrationDetailsInitializer();
initializer.setRegistrationDetails(new EntityRegistrationDetails(initializer2));
DataSet dataSet = new DataSet(initializer);
Cache cache = cache(0, Cache.LIVE_TIME / 2, Cache.LIVE_TIME + 1);
cache.putDataSet(dataSet);
assertSame(dataSet, cache.getDataSet(dataSet.getCode()));
assertEquals(null, cache.getDataSet(dataSet.getCode()));
}
@Test
public void testGetExternalData()
{
ExternalData dataSet = new ContainerDataSet();
dataSet.setCode("ds1");
Cache cache = cache(0, Cache.LIVE_TIME / 2, Cache.LIVE_TIME + 1);
cache.putExternalData(dataSet);
assertSame(dataSet, cache.getExternalData(dataSet.getCode()));
assertEquals(null, cache.getExternalData(dataSet.getCode()));
}
@Test
public void testGetExperiment()
{
Experiment experiment = new Experiment();
experiment.setIdentifier("e1");
Cache cache = cache(0, Cache.LIVE_TIME / 2, Cache.LIVE_TIME + 1);
cache.putExperiment(experiment);
assertSame(experiment, cache.getExperiment(experiment.getIdentifier()));
assertEquals(null, cache.getExperiment(experiment.getIdentifier()));
}
private Cache cache(final long... timestamps)
{
return new Cache(new ITimeProvider()
{
private int index;
public long getTimeInMilliseconds()
{
return timestamps[Math.min(index++, timestamps.length - 1)];
}
});
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment