From 8f744dc058bd07cdac6bd1d473312ce60d78a30e Mon Sep 17 00:00:00 2001 From: nwoodward Date: Wed, 15 May 2024 17:14:21 -0500 Subject: [PATCH] added CacheManager tests and fixed a bug with the temp dir --- .../LoopingDuplicationTaskProducerTest.java | 48 ++++++++++++++++--- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/loopingduptaskproducer/src/test/java/org/duracloud/mill/ltp/dup/LoopingDuplicationTaskProducerTest.java b/loopingduptaskproducer/src/test/java/org/duracloud/mill/ltp/dup/LoopingDuplicationTaskProducerTest.java index 11f4ef00..4cb8a255 100644 --- a/loopingduptaskproducer/src/test/java/org/duracloud/mill/ltp/dup/LoopingDuplicationTaskProducerTest.java +++ b/loopingduptaskproducer/src/test/java/org/duracloud/mill/ltp/dup/LoopingDuplicationTaskProducerTest.java @@ -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; @@ -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 @@ -118,7 +117,9 @@ public void setUp() throws Exception { @After public void tearDown() throws Exception { verifyAll(); - cache.clear(); + if (cache != null) { + cache.clear(); + } } /** @@ -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() { @@ -277,6 +279,37 @@ public void setMorsels(LinkedHashSet 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 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 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(); @@ -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); } }