Skip to content

Commit

Permalink
added CacheManager tests and fixed a bug with the temp dir
Browse files Browse the repository at this point in the history
  • Loading branch information
nwoodward committed May 15, 2024
1 parent d0e2f83 commit 8f744dc
Showing 1 changed file with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
*/
package org.duracloud.mill.ltp.dup;

import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.isA;

import java.io.File;
import java.nio.file.Path;
import java.text.ParseException;
Expand Down Expand Up @@ -51,12 +47,15 @@
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;

import static org.easymock.EasyMock.*;

/**
* @author Daniel Bernstein
* Date: Nov 6, 2013
Expand Down Expand Up @@ -118,7 +117,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 +184,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 +279,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 +534,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

0 comments on commit 8f744dc

Please sign in to comment.