Refine search
@Test public void testSimplePutIfAbsentWithLoaderAndWriter_existsInStore() throws Exception { testCache.put(1, "un"); reset(cacheWriter); assertThat(testCache.putIfAbsent(1, "one"), is(false)); assertThat(testCache.get(1), Matchers.<CharSequence>equalTo("un")); verifyZeroInteractions(cacheLoader); verifyZeroInteractions(cacheWriter); }
@Test public void test_getAveragePutTime() throws Exception { assertThat(heapStatistics.getAveragePutTime(), is(0.0f)); heapCache.put("key", "value"); heapCache.put("key", "value"); heapCache.put("key", "value"); heapCache.put("key", "value"); heapCache.put("key", "value"); assertFor(1100L, () -> heapStatistics.getAveragePutTime(), is(not(0.0f))); assertThat(heapStatistics.getAveragePutTime(), greaterThan(0.0f)); }
@Test public void test_getCacheHitsAndMisses() { heapCache.put("key1", "value1"); heapCache.put("key3", "value3"); heapCache.put("key5", "value5"); HashSet<String> keys = new HashSet<>(5); for (int i = 1; i <= 5; i++) { keys.add("key" + i); } heapCache.getAll(keys); assertThat(heapStatistics.getCacheHits(), is(3L)); assertThat(heapStatistics.getCacheMisses(), is(2L)); }
@Test public void testTemplateAddsListeners() throws Exception { CacheManager cacheManager = cachingProvider.getCacheManager(getClass().getResource("/ehcache-107-listeners.xml") .toURI(), getClass().getClassLoader()); MutableConfiguration<String, String> configuration = new MutableConfiguration<>(); configuration.setTypes(String.class, String.class); MutableCacheEntryListenerConfiguration<String, String> listenerConfiguration = new MutableCacheEntryListenerConfiguration<>(Test107CacheEntryListener::new, null, false, true); configuration.addCacheEntryListenerConfiguration(listenerConfiguration); Cache<String, String> cache = cacheManager.createCache("foos", configuration); cache.put("Hello", "Bonjour"); assertThat(Test107CacheEntryListener.seen.size(), Matchers.is(1)); assertThat(TestCacheEventListener.seen.size(), Matchers.is(1)); }
@Test public void testSimpleReplace3ArgsWithLoaderAndWriter_existsInStore_notEquals() throws Exception { testCache.put(1, "un"); reset(cacheWriter); assertThat(testCache.replace(1, "uno", "one"), is(false)); assertThat(testCache.get(1), Matchers.<CharSequence>equalTo("un")); verifyZeroInteractions(cacheLoader); verifyZeroInteractions(cacheWriter); }
@Test public void testCopierAtServiceLevel() throws Exception { CacheManager cacheManager = cachingProvider.getCacheManager( getClass().getResource("/ehcache-107-default-copiers.xml").toURI(), getClass().getClassLoader()); MutableConfiguration<Long, Client> config = new MutableConfiguration<>(); config.setTypes(Long.class, Client.class); Cache<Long, Client> bar = cacheManager.createCache("bar", config); Client client = new Client("tc", 1000000L); long key = 42L; bar.put(key, client); assertThat(bar.get(key), not(sameInstance(client))); }