本文整理汇总了Java中org.ehcache.config.builders.CacheConfigurationBuilder.build方法的典型用法代码示例。如果您正苦于以下问题:Java CacheConfigurationBuilder.build方法的具体用法?Java CacheConfigurationBuilder.build怎么用?Java CacheConfigurationBuilder.build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ehcache.config.builders.CacheConfigurationBuilder
的用法示例。
在下文中一共展示了CacheConfigurationBuilder.build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newCacheConfigurationBuilder_oneExpiryThreeResourcePools
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
public void newCacheConfigurationBuilder_oneExpiryThreeResourcePools() throws Exception {
//given
addProp(CacheConfigurationServiceImpl.PROP_KEY_SUFFIX_TIME_TO_IDLE_SECS,60);
addProp(CacheConfigurationServiceImpl.PROP_KEY_SUFFIX_MAX_ENTRIES_HEAP,1);
addProp(CacheConfigurationServiceImpl.PROP_KEY_SUFFIX_MAX_MB_OFF_HEAP,2);
addProp(CacheConfigurationServiceImpl.PROP_KEY_SUFFIX_MAX_MB_DISK,3);
//when
CacheConfigurationBuilder<String,String> builder = cacheConfigurationService.newCacheConfigurationBuilder(CACHE_NAME, String.class, String.class);
CacheConfiguration<String, String> cacheConfiguration = builder.build();
//then
assertThat(cacheConfiguration.getResourcePools().getResourceTypeSet().size()).isEqualTo(3);
assertThat(cacheConfiguration.getExpiry()).isEqualTo(Expirations.timeToIdleExpiration(Duration.of(60, TimeUnit.SECONDS)));
}
示例2: testPutAll_without_cache_writer
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
public void testPutAll_without_cache_writer() throws Exception {
CacheConfigurationBuilder cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
heap(100));
CacheConfiguration<String, String> cacheConfiguration = cacheConfigurationBuilder.build();
CacheManagerBuilder<CacheManager> managerBuilder = CacheManagerBuilder.newCacheManagerBuilder();
CacheManager cacheManager = managerBuilder.withCache("myCache", cacheConfiguration).build(true);
Cache<String, String> myCache = cacheManager.getCache("myCache", String.class, String.class);
HashMap<String, String> stringStringHashMap = new HashMap<>();
for (int i = 0; i < 3; i++) {
stringStringHashMap.put("key" + i, "value" + i);
}
// the call to putAll
myCache.putAll(stringStringHashMap);
for (int i = 0; i < 3; i++) {
assertThat(myCache.get("key" + i), is("value" + i));
}
}
示例3: testPutAll_with_cache_writer
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
public void testPutAll_with_cache_writer() throws Exception {
CacheConfigurationBuilder cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
heap(100));
CacheConfiguration<String, String> cacheConfiguration = cacheConfigurationBuilder
.build();
CacheLoaderWriterProvider cacheLoaderWriterProvider = mock(CacheLoaderWriterProvider.class);
CacheLoaderWriter cacheLoaderWriter = mock(CacheLoaderWriter.class);
doThrow(new RuntimeException("We should not have called .write() but .writeAll()")).when(cacheLoaderWriter).write(ArgumentMatchers
.any(), ArgumentMatchers.any());
when(cacheLoaderWriterProvider.createCacheLoaderWriter(anyString(), ArgumentMatchers.any(CacheConfiguration.class))).thenReturn(cacheLoaderWriter);
CacheManagerBuilder<CacheManager> managerBuilder = CacheManagerBuilder.newCacheManagerBuilder().using(cacheLoaderWriterProvider);
CacheManager cacheManager = managerBuilder.withCache("myCache", cacheConfiguration).build(true);
Cache<String, String> myCache = cacheManager.getCache("myCache", String.class, String.class);
HashMap<String, String> stringStringHashMap = new HashMap<>();
for (int i = 0; i < 3; i++) {
stringStringHashMap.put("key" + i, "value" + i);
}
// the call to putAll
myCache.putAll(stringStringHashMap);
verify(cacheLoaderWriter, times(3)).writeAll(ArgumentMatchers.any(Iterable.class));
Set set = new HashSet(){{add(entry("key0", "value0"));}};
verify(cacheLoaderWriter).writeAll(set);
set = new HashSet(){{add(entry("key1", "value1"));}};
verify(cacheLoaderWriter).writeAll(set);
set = new HashSet(){{add(entry("key2", "value2"));}};
verify(cacheLoaderWriter).writeAll(set);
for (int i = 0; i < 3; i++) {
assertThat(myCache.get("key" + i), is("value" + i));
}
}
示例4: testPutAll_with_cache_writer_that_throws_exception
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
public void testPutAll_with_cache_writer_that_throws_exception() throws Exception {
CacheConfigurationBuilder cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
heap(100));
CacheConfiguration<String, String> cacheConfiguration = cacheConfigurationBuilder
.build();
CacheLoaderWriterProvider cacheLoaderWriterProvider = mock(CacheLoaderWriterProvider.class);
CacheLoaderWriter cacheLoaderWriterThatThrows = mock(CacheLoaderWriter.class);
doThrow(new RuntimeException("We should not have called .write() but .writeAll()")).when(cacheLoaderWriterThatThrows).write(ArgumentMatchers
.any(), ArgumentMatchers.any());
doThrow(new Exception("Simulating an exception from the cache writer")).when(cacheLoaderWriterThatThrows).writeAll(ArgumentMatchers.any(Iterable.class));
when(cacheLoaderWriterProvider.createCacheLoaderWriter(anyString(), ArgumentMatchers.any(CacheConfiguration.class))).thenReturn(cacheLoaderWriterThatThrows);
CacheManagerBuilder<CacheManager> managerBuilder = CacheManagerBuilder.newCacheManagerBuilder().using(cacheLoaderWriterProvider);
CacheManager cacheManager = managerBuilder.withCache("myCache", cacheConfiguration).build(true);
Cache<String, String> myCache = cacheManager.getCache("myCache", String.class, String.class);
HashMap<String, String> stringStringHashMap = new HashMap<>();
for (int i = 0; i < 3; i++) {
stringStringHashMap.put("key" + i, "value" + i);
}
// the call to putAll
try {
myCache.putAll(stringStringHashMap);
fail();
} catch (BulkCacheWritingException bcwe) {
assertThat(bcwe.getFailures().size(), is(3));
assertThat(bcwe.getSuccesses().size(), is(0));
}
}
示例5: testPutAll_store_throws_cache_exception
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
public void testPutAll_store_throws_cache_exception() throws Exception {
CacheConfigurationBuilder cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
heap(100));
CacheConfiguration<String, String> cacheConfiguration = cacheConfigurationBuilder
.build();
CacheLoaderWriterProvider cacheLoaderWriterProvider = mock(CacheLoaderWriterProvider.class);
CacheLoaderWriter cacheLoaderWriter = mock(CacheLoaderWriter.class);
doThrow(new RuntimeException("We should not have called .write() but .writeAll()")).when(cacheLoaderWriter).write(ArgumentMatchers.any(), ArgumentMatchers.any());
when(cacheLoaderWriterProvider.createCacheLoaderWriter(anyString(), ArgumentMatchers.any(CacheConfiguration.class))).thenReturn(cacheLoaderWriter);
CacheManagerBuilder<CacheManager> managerBuilder = CacheManagerBuilder.newCacheManagerBuilder().using(cacheLoaderWriterProvider).using(new CustomStoreProvider());
CacheManager cacheManager = managerBuilder.withCache("myCache", cacheConfiguration).build(true);
Cache<String, String> myCache = cacheManager.getCache("myCache", String.class, String.class);
Map<String, String> stringStringHashMap = new HashMap<>();
for (int i = 0; i < 3; i++) {
stringStringHashMap.put("key" + i, "value" + i);
}
// the call to putAll
myCache.putAll(stringStringHashMap);
for (int i = 0; i < 3; i++) {
// the store threw an exception when we call bulkCompute
assertThat(myCache.get("key" + i), is(nullValue()));
// but still, the cache writer could writeAll the values !
// assertThat(cacheWriterToHashMapMap.get("key" + i), is("value" + i));
}
// but still, the cache writer could writeAll the values at once !
verify(cacheLoaderWriter, times(1)).writeAll(ArgumentMatchers.any(Iterable.class));
Set set = new HashSet() {{add(entry("key0", "value0")); add(entry("key1", "value1")); add(entry("key2", "value2"));}};
verify(cacheLoaderWriter).writeAll(set);
}
示例6: testGetAll_without_cache_loader
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
public void testGetAll_without_cache_loader() throws Exception {
CacheConfigurationBuilder cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
heap(100));
CacheConfiguration<String, String> cacheConfiguration = cacheConfigurationBuilder.build();
CacheManagerBuilder<CacheManager> managerBuilder = CacheManagerBuilder.newCacheManagerBuilder();
CacheManager cacheManager = managerBuilder.withCache("myCache", cacheConfiguration).build(true);
Cache<String, String> myCache = cacheManager.getCache("myCache", String.class, String.class);
for (int i = 0; i < 3; i++) {
myCache.put("key" + i, "value" + i);
}
Set<String> fewKeysSet = new HashSet<String>() {
{
add("key0");
add("key2");
}
};
// the call to getAll
Map<String, String> fewEntries = myCache.getAll(fewKeysSet);
assertThat(fewEntries.size(), is(2));
assertThat(fewEntries.get("key0"), is("value0"));
assertThat(fewEntries.get("key2"), is("value2"));
}
示例7: testGetAll_with_cache_loader
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
public void testGetAll_with_cache_loader() throws Exception {
CacheConfigurationBuilder cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
heap(100));
CacheConfiguration<String, String> cacheConfiguration = cacheConfigurationBuilder.build();
CacheLoaderWriterProvider cacheLoaderWriterProvider = mock(CacheLoaderWriterProvider.class);
CacheLoaderWriter cacheLoaderWriter = mock(CacheLoaderWriter.class);
when(cacheLoaderWriter.load(ArgumentMatchers.any())).thenThrow(new RuntimeException("We should not have called .load() but .loadAll()"));
when(cacheLoaderWriterProvider.createCacheLoaderWriter(anyString(), ArgumentMatchers.any(CacheConfiguration.class))).thenReturn(cacheLoaderWriter);
CacheManagerBuilder<CacheManager> managerBuilder = CacheManagerBuilder.newCacheManagerBuilder().using(cacheLoaderWriterProvider);
CacheManager cacheManager = managerBuilder.withCache("myCache", cacheConfiguration).build(true);
when(cacheLoaderWriter.loadAll(argThat(IsCollectionContaining.<String>hasItem("key0")))).thenReturn(new HashMap(){{put("key0","value0");}});
when(cacheLoaderWriter.loadAll(argThat(IsCollectionContaining.<String>hasItem("key2")))).thenReturn(new HashMap(){{put("key2","value2");}});
Cache<String, String> myCache = cacheManager.getCache("myCache", String.class, String.class);
Set<String> fewKeysSet = new HashSet<String>() {
{
add("key0");
add("key2");
}
};
// the call to getAll
Map<String, String> fewEntries = myCache.getAll(fewKeysSet);
assertThat(fewEntries.size(), is(2));
assertThat(fewEntries.get("key0"), is("value0"));
assertThat(fewEntries.get("key2"), is("value2"));
}
示例8: testGetAll_cache_loader_throws_exception
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
public void testGetAll_cache_loader_throws_exception() throws Exception {
CacheConfigurationBuilder cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
heap(100));
CacheConfiguration<String, String> cacheConfiguration = cacheConfigurationBuilder.build();
CacheLoaderWriterProvider cacheLoaderWriterProvider = mock(CacheLoaderWriterProvider.class);
CacheLoaderWriter cacheLoaderWriter = mock(CacheLoaderWriter.class);
when(cacheLoaderWriter.load(ArgumentMatchers.any())).thenThrow(new RuntimeException("We should not have called .load() but .loadAll()"));
when(cacheLoaderWriter.loadAll(ArgumentMatchers.any(Iterable.class))).thenThrow(new Exception("Simulating an exception from the cache loader"));
when(cacheLoaderWriterProvider.createCacheLoaderWriter(anyString(), ArgumentMatchers.any(CacheConfiguration.class))).thenReturn(cacheLoaderWriter);
CacheManagerBuilder<CacheManager> managerBuilder = CacheManagerBuilder.newCacheManagerBuilder().using(cacheLoaderWriterProvider);
CacheManager cacheManager = managerBuilder.withCache("myCache", cacheConfiguration).build(true);
Cache<String, String> myCache = cacheManager.getCache("myCache", String.class, String.class);
Set<String> fewKeysSet = new HashSet<String>() {
{
add("key0");
add("key2");
}
};
// the call to getAll
try {
myCache.getAll(fewKeysSet);
fail();
} catch (BulkCacheLoadingException bcwe) {
// since onHeapStore.bulkComputeIfAbsent sends batches of 1 element,
assertThat(bcwe.getFailures().size(), is(2));
assertThat(bcwe.getSuccesses().size(), is(0));
}
}
示例9: testGetAll_store_throws_cache_exception
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
public void testGetAll_store_throws_cache_exception() throws Exception {
CacheConfigurationBuilder cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
heap(100));
CacheConfiguration<String, String> cacheConfiguration = cacheConfigurationBuilder.build();
CacheLoaderWriterProvider cacheLoaderWriterProvider = mock(CacheLoaderWriterProvider.class);
CacheLoaderWriter cacheLoaderWriter = mock(CacheLoaderWriter.class);
when(cacheLoaderWriter.load(ArgumentMatchers.any())).thenThrow(new RuntimeException("We should not have called .load() but .loadAll()"));
when(cacheLoaderWriterProvider.createCacheLoaderWriter(anyString(), ArgumentMatchers.any(CacheConfiguration.class))).thenReturn(cacheLoaderWriter);
CacheManagerBuilder<CacheManager> managerBuilder = CacheManagerBuilder.newCacheManagerBuilder().using(cacheLoaderWriterProvider).using(new CustomStoreProvider());
CacheManager cacheManager = managerBuilder.withCache("myCache", cacheConfiguration).build(true);
when(cacheLoaderWriter.loadAll(argThat(hasItems("key0", "key2")))).thenReturn( new HashMap(){{put("key0","value0"); put("key2","value2");}});
Cache<String, String> myCache = cacheManager.getCache("myCache", String.class, String.class);
Set<String> fewKeysSet = new HashSet<String>() {
{
add("key0");
add("key2");
}
};
// the call to getAll
Map<String, String> fewEntries = myCache.getAll(fewKeysSet);
assertThat(fewEntries.size(), is(2));
assertThat(fewEntries.get("key0"), is("value0"));
assertThat(fewEntries.get("key2"), is("value2"));
}
示例10: testRemoveAll_without_cache_writer
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
public void testRemoveAll_without_cache_writer() throws Exception {
CacheConfigurationBuilder cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
heap(100));
CacheConfiguration<String, String> cacheConfiguration = cacheConfigurationBuilder.build();
CacheManagerBuilder<CacheManager> managerBuilder = CacheManagerBuilder.newCacheManagerBuilder();
CacheManager cacheManager = managerBuilder.withCache("myCache", cacheConfiguration).build(true);
Cache<String, String> myCache = cacheManager.getCache("myCache", String.class, String.class);
for (int i = 0; i < 3; i++) {
myCache.put("key" + i, "value" + i);
}
Set<String> fewKeysSet = new HashSet<String>() {
{
add("key0");
add("key2");
}
};
// the call to removeAll
myCache.removeAll(fewKeysSet);
for (int i = 0; i < 3; i++) {
if (i == 0 || i == 2) {
assertThat(myCache.get("key" + i), is(nullValue()));
} else {
assertThat(myCache.get("key" + i), is("value" + i));
}
}
}
示例11: newCacheConfigurationBuilder_twoExpiries
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test(expected = RuntimeException.class)
public void newCacheConfigurationBuilder_twoExpiries() throws Exception {
//given
addProp(CacheConfigurationServiceImpl.PROP_KEY_SUFFIX_TIME_TO_IDLE_SECS,60);
addProp(CacheConfigurationServiceImpl.PROP_KEY_SUFFIX_TIME_TO_LIVE_SECS,120);
//when
CacheConfigurationBuilder<String,String> builder = cacheConfigurationService.newCacheConfigurationBuilder(CACHE_NAME, String.class, String.class);
CacheConfiguration<String, String> cacheConfiguration = builder.build();
//then
//nothing as an exception is throw
}
示例12: createNewCache
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
private <T> EhCacheImpl<T> createNewCache( String cacheId, Class<T> valueType )
{
configuration.refresh();
EhCacheConfiguration config = configuration.get();
ResourcePoolsBuilder poolsBuilder = ResourcePoolsBuilder.newResourcePoolsBuilder();
poolsBuilder = poolsBuilder.heap( config.heapSize().get(), MemoryUnit.valueOf( config.heapUnit().get() ) );
if( config.offHeapSize().get() != null )
{
poolsBuilder = poolsBuilder.offheap( config.offHeapSize().get(),
MemoryUnit.valueOf( config.offHeapUnit().get() ) );
}
if( config.diskSize().get() != null )
{
poolsBuilder = poolsBuilder.disk( config.diskSize().get(),
MemoryUnit.valueOf( config.diskUnit().get() ),
config.diskPersistent().get() );
}
CacheConfigurationBuilder<String, T> configBuilder = CacheConfigurationBuilder
.newCacheConfigurationBuilder( String.class, valueType, poolsBuilder );
if( config.maxObjectSize().get() != null )
{
configBuilder = configBuilder.withSizeOfMaxObjectSize( config.maxObjectSize().get(),
MemoryUnit.valueOf( config.maxObjectSizeUnit().get() ) );
}
if( config.maxObjectGraphDepth().get() != null )
{
configBuilder = configBuilder.withSizeOfMaxObjectGraph( config.maxObjectGraphDepth().get() );
}
switch( config.expiry().get() )
{
case "TIME_TO_IDLE":
configBuilder = configBuilder.withExpiry( timeToIdleExpiration( Duration.of(
config.expiryLength().get() == null ? - 1L : config.expiryLength().get(),
TimeUnit.valueOf( config.expiryTimeUnit().get() ) ) ) );
break;
case "TIME_TO_LIVE":
configBuilder = configBuilder.withExpiry( timeToLiveExpiration( Duration.of(
config.expiryLength().get() == null ? - 1L : config.expiryLength().get(),
TimeUnit.valueOf( config.expiryTimeUnit().get() ) ) ) );
break;
case "NONE":
default:
configBuilder = configBuilder.withExpiry( noExpiration() );
break;
}
CacheConfiguration<String, T> cacheConfig = configBuilder.build();
org.ehcache.Cache<String, T> cache = cacheManager.createCache( cacheId, cacheConfig );
return new EhCacheImpl<>( cacheId, cache, valueType );
}
示例13: testRemoveAll_with_cache_writer
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
public void testRemoveAll_with_cache_writer() throws Exception {
CacheConfigurationBuilder cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
heap(100));
CacheConfiguration<String, String> cacheConfiguration = cacheConfigurationBuilder
.build();
CacheLoaderWriterProvider cacheLoaderWriterProvider = mock(CacheLoaderWriterProvider.class);
CacheLoaderWriter cacheLoaderWriter = mock(CacheLoaderWriter.class);
doThrow(new RuntimeException("We should not have called .write() but .writeAll()")).when(cacheLoaderWriter).delete(ArgumentMatchers.any());
when(cacheLoaderWriterProvider.createCacheLoaderWriter(anyString(), ArgumentMatchers.any(CacheConfiguration.class))).thenReturn(cacheLoaderWriter);
CacheManagerBuilder<CacheManager> managerBuilder = CacheManagerBuilder.newCacheManagerBuilder().using(cacheLoaderWriterProvider);
CacheManager cacheManager = managerBuilder.withCache("myCache", cacheConfiguration).build(true);
Cache<String, String> myCache = cacheManager.getCache("myCache", String.class, String.class);
for (int i = 0; i < 3; i++) {
myCache.put("key" + i, "value" + i);
}
Set<String> fewKeysSet = new HashSet<String>() {
{
add("key0");
add("key2");
}
};
// the call to removeAll
myCache.removeAll(fewKeysSet);
for (int i = 0; i < 3; i++) {
if (i == 0 || i == 2) {
assertThat(myCache.get("key" + i), is(nullValue()));
} else {
assertThat(myCache.get("key" + i), is("value" + i));
}
}
Set set = new HashSet(){{add("key0");}};
verify(cacheLoaderWriter).deleteAll(set);
set = new HashSet(){{add("key2");}};
verify(cacheLoaderWriter).deleteAll(set);
}
示例14: testRemoveAll_cache_writer_throws_exception
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
public void testRemoveAll_cache_writer_throws_exception() throws Exception {
CacheConfigurationBuilder cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
heap(100));
CacheConfiguration<String, String> cacheConfiguration = cacheConfigurationBuilder
.build();
CacheLoaderWriterProvider cacheLoaderWriterProvider = mock(CacheLoaderWriterProvider.class);
CacheLoaderWriter cacheLoaderWriterThatThrows = mock(CacheLoaderWriter.class);
doThrow(new Exception("Simulating an exception from the cache writer")).when(cacheLoaderWriterThatThrows).deleteAll(ArgumentMatchers.any(Iterable.class));
when(cacheLoaderWriterProvider.createCacheLoaderWriter(anyString(), ArgumentMatchers.any(CacheConfiguration.class))).thenReturn(cacheLoaderWriterThatThrows);
CacheManagerBuilder<CacheManager> managerBuilder = CacheManagerBuilder.newCacheManagerBuilder().using(cacheLoaderWriterProvider);
CacheManager cacheManager = managerBuilder.withCache("myCache", cacheConfiguration).build(true);
Cache<String, String> myCache = cacheManager.getCache("myCache", String.class, String.class);
for (int i = 0; i < 3; i++) {
myCache.put("key" + i, "value" + i);
}
doThrow(new RuntimeException("We should not have called .write() but .writeAll()")).when(cacheLoaderWriterThatThrows).write(ArgumentMatchers
.any(), ArgumentMatchers.any());
Set<String> fewKeysSet = new HashSet<String>() {
{
add("key0");
add("key2");
}
};
// the call to removeAll
try {
myCache.removeAll(fewKeysSet);
fail();
} catch (BulkCacheWritingException bcwe) {
assertThat(bcwe.getFailures().size(), is(2));
assertThat(bcwe.getSuccesses().size(), is(0));
}
}
示例15: testRemoveAll_with_store_that_throws
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
public void testRemoveAll_with_store_that_throws() throws Exception {
CacheConfigurationBuilder cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
heap(100));
CacheConfiguration<String, String> cacheConfiguration = cacheConfigurationBuilder
.build();
CacheLoaderWriterProvider cacheLoaderWriterProvider = mock(CacheLoaderWriterProvider.class);
CacheLoaderWriter cacheLoaderWriter = mock(CacheLoaderWriter.class);
when(cacheLoaderWriterProvider.createCacheLoaderWriter(anyString(), ArgumentMatchers.any(CacheConfiguration.class))).thenReturn(cacheLoaderWriter);
CacheManagerBuilder<CacheManager> managerBuilder = CacheManagerBuilder.newCacheManagerBuilder().using(cacheLoaderWriterProvider).using(new CustomStoreProvider());
CacheManager cacheManager = managerBuilder.withCache("myCache", cacheConfiguration).build(true);
Cache<String, String> myCache = cacheManager.getCache("myCache", String.class, String.class);
for (int i = 0; i < 3; i++) {
myCache.put("key" + i, "value" + i);
}
doThrow(new RuntimeException("We should not have called .write() but .writeAll()")).when(cacheLoaderWriter).write(ArgumentMatchers
.any(), ArgumentMatchers.any());
Set<String> fewKeysSet = new HashSet<String>() {
{
add("key0");
add("key2");
}
};
// the call to removeAll
myCache.removeAll(fewKeysSet);
for (int i = 0; i < 3; i++) {
if (i == 0 || i == 2) {
assertThat(myCache.get("key" + i), is(nullValue()));
} else {
assertThat(myCache.get("key" + i), is("value" + i));
}
}
Set set = new HashSet(){{add("key0"); add("key2");}};
verify(cacheLoaderWriter).deleteAll(set);
}