Skip to content

Commit

Permalink
adds configuration to the resource pools builder; plus some tests (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwoodward authored May 21, 2024
1 parent a1ad05d commit 4df1670
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.ehcache.config.builders.CacheConfigurationBuilder;
import org.ehcache.config.builders.CacheManagerBuilder;
import org.ehcache.config.builders.ResourcePoolsBuilder;
import org.ehcache.config.units.MemoryUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -68,7 +69,7 @@ public static void main(String[] args) {
@Override
protected LoopingTaskProducer buildTaskProducer() {

List<PropertyDefinition> defintions =
List<PropertyDefinition> definitions =
new PropertyDefinitionListBuilder().addAws()
.addSwift()
.addNotificationConfig()
Expand All @@ -82,7 +83,7 @@ protected LoopingTaskProducer buildTaskProducer() {
.addLocalDuplicationDir()
.addWorkDir()
.build();
PropertyVerifier verifier = new PropertyVerifier(defintions);
PropertyVerifier verifier = new PropertyVerifier(definitions);
verifier.verify(System.getProperties());

LoopingTaskProducerConfigurationManager config = new LoopingTaskProducerConfigurationManager();
Expand Down Expand Up @@ -148,7 +149,7 @@ protected LoopingTaskProducer buildTaskProducer() {
.withCache("contentIdCache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(
String.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()))
ResourcePoolsBuilder.newResourcePoolsBuilder().disk(100, MemoryUnit.MB, true)))
.build(true);
Cache<String, String> cache = cacheManager.getCache("contentIdCache", String.class, String.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@
import org.ehcache.config.builders.CacheConfigurationBuilder;
import org.ehcache.config.builders.CacheManagerBuilder;
import org.ehcache.config.builders.ResourcePoolsBuilder;
import org.ehcache.config.units.EntryUnit;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;


/**
* @author Daniel Bernstein
* Date: Nov 6, 2013
Expand Down Expand Up @@ -118,7 +120,9 @@ public void setUp() throws Exception {
@After
public void tearDown() throws Exception {
verifyAll();
cache.clear();
if (cache != null) {
cache.clear();
}
}

/**
Expand Down Expand Up @@ -183,7 +187,8 @@ public void testNonExistentSpace() throws CredentialsRepoException, ParseExcepti
}

private void setupLoopingTaskProducerConfig(int times) {
expect(this.config.getWorkDirectoryPath()).andReturn("java.io.tmpdir").times(times);
expect(this.config.getWorkDirectoryPath()).andReturn(
String.valueOf(Path.of(System.getProperty("java.io.tmpdir")))).times(times);
}

private void setupNotificationManager() {
Expand Down Expand Up @@ -277,6 +282,37 @@ public void setMorsels(LinkedHashSet<DuplicationMorsel> morsels2) {

}

/**
* Test setting up the ehcache CacheManager without a resource pool
*/
@Test(expected = IllegalArgumentException.class)
public void testSetupCacheWithoutStore() throws Exception {
replayAll();
CacheManager testCacheManager = CacheManagerBuilder.newCacheManagerBuilder().build(true);
testCacheManager.createCache(CACHE_NAME,
CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()));
Cache<String, String> testCache = testCacheManager.getCache(CACHE_NAME, String.class, String.class);
testCache.clear();
testCacheManager.close();
}

/**
* Test setting up the ehcache CacheManager with a resource pool
*/
@Test
public void testSetupCacheWithStore() {
replayAll();
CacheManager testCacheManager = CacheManagerBuilder.newCacheManagerBuilder().build(true);
testCacheManager.createCache(CACHE_NAME,
CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10, EntryUnit.ENTRIES)));
Cache<String, String> testCache = testCacheManager.getCache(CACHE_NAME, String.class, String.class);
Assert.assertNotNull(testCache);
testCache.clear();
testCacheManager.close();
}

private String createStateFilePath() {
final var path = Path.of(System.getProperty("java.io.tmpdir"), System.currentTimeMillis() + ".json").toString();
new File(path).deleteOnExit();
Expand Down Expand Up @@ -501,7 +537,8 @@ private void setupCache() {
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().build(true);
cacheManager.createCache(CACHE_NAME,
CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
ResourcePoolsBuilder.heap(10)));
ResourcePoolsBuilder.newResourcePoolsBuilder()
.heap(10, EntryUnit.ENTRIES)));
cache = cacheManager.getCache(CACHE_NAME, String.class, String.class);
}
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.10.0</version>
<version>3.10.8</version>
</dependency>

</dependencies>
Expand Down

0 comments on commit 4df1670

Please sign in to comment.