本文整理汇总了Java中org.ehcache.config.builders.CacheConfigurationBuilder.newCacheConfigurationBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java CacheConfigurationBuilder.newCacheConfigurationBuilder方法的具体用法?Java CacheConfigurationBuilder.newCacheConfigurationBuilder怎么用?Java CacheConfigurationBuilder.newCacheConfigurationBuilder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ehcache.config.builders.CacheConfigurationBuilder
的用法示例。
在下文中一共展示了CacheConfigurationBuilder.newCacheConfigurationBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
}
示例2: testCreate
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
public void testCreate() throws Exception {
CacheConfigurationBuilder<Long, String> configBuilder =
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(ClusteredResourcePoolBuilder.clusteredShared("primary")));
ClusteringServiceConfiguration configuration =
ClusteringServiceConfigurationBuilder.cluster(URI.create(CLUSTER_URI_BASE + "my-application"))
.autoCreate()
.build();
DefaultClusteringService service = new DefaultClusteringService(configuration);
PersistableResourceService.PersistenceSpaceIdentifier spaceIdentifier = service.getPersistenceSpaceIdentifier("cacheAlias", configBuilder
.build());
assertThat(spaceIdentifier, instanceOf(ClusteredCacheIdentifier.class));
assertThat(((ClusteredCacheIdentifier) spaceIdentifier).getId(), is("cacheAlias"));
}
示例3: createCache
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
public void createCache(String title, Class keyType, Class<? extends Serializable> valueType, int heapMb,int timeToLiveSeconds,int timeToIdleSeconds) {
CacheConfigurationBuilder builder = CacheConfigurationBuilder.newCacheConfigurationBuilder(keyType, valueType,
ResourcePoolsBuilder.newResourcePoolsBuilder().heap(heapMb, MemoryUnit.MB)
) ;
if(timeToLiveSeconds>10){
builder = builder.withExpiry(Expirations.timeToLiveExpiration(Duration.of(timeToLiveSeconds, TimeUnit.SECONDS)));
}
if(timeToIdleSeconds>0){
builder = builder.withExpiry(Expirations.timeToIdleExpiration(Duration.of(timeToIdleSeconds, TimeUnit.SECONDS)));
}
cacheManager.createCache(title, builder.build());
KEY_TYPE_MAP.put(title, keyType);
VALUE_TYPE_MAP.put(title, valueType);
}
示例4: 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));
}
}
示例5: 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));
}
}
示例6: 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));
}
}
示例7: 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"));
}
示例8: testWarmup
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
@Ignore
public void testWarmup() throws SyntaxException {
CacheConfigurationBuilder<Long, byte[]> builder = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, byte[].class,
newResourcePoolsBuilder().heap(250000, EntryUnit.ENTRIES).build());
final CacheManager cacheManager = newCacheManagerBuilder()
.withCache("one", builder.build())
.build(true);
final Cache<Long, byte[]> one = cacheManager.getCache("one", Long.class, byte[].class);
final Cache<Long, byte[]> two = cacheManager.getCache("two", Long.class, byte[].class);
ConcurrencyConfig concurrency = ConcurrencyConfig.concurrencyConfig().threads(4).timeout(50, MINUTES);
ObjectGenerator<Long> keyGenerator = new LongGenerator();
ObjectGenerator<byte[]> valueGenerator = fixedLengthByteArray(1000);
EhcacheResult[] resultsReported = new EhcacheResult[] { GET, PUT, MISS };
Scenario scenario = scenario("Test phase").exec(
put(keyGenerator, valueGenerator, sequentially(), singletonList(cache("one", one))),
get(Long.class, byte[].class).using(keyGenerator, valueGenerator).sequentially()
);
System.out.println("----------> Test phase");
StatisticsPeekHolder finalStats = Runner.setUp(
scenario)
.warmup(during(25, seconds))
.executed(during(30, seconds))
.config(concurrency,
ReportingConfig.report(EhcacheResult.class, resultsReported).log(text(), html()))
.config(cacheConfig(Long.class, byte[].class).cache("one", one)
)
.start();
System.out.println("----------> Done");
cacheManager.close();
}
示例9: before
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Before
public void before() {
CacheConfigurationBuilder<Long, String> cacheConfiguration =
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.heap(1, MB));
cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.using(service)
.withCache(CACHE, cacheConfiguration)
.build();
}
示例10: testSingleTier
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
public void testSingleTier() {
// tag::clusteredOnly[]
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, // <1>
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(ClusteredResourcePoolBuilder.clusteredDedicated(2, MemoryUnit.GB))); // <2>
// end::clusteredOnly[]
}
示例11: 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 );
}
示例12: tier
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
@Ignore
public void tier() {
int heap = 200000;
int offheap = 1;
int disk = 2;
long nbElementsHeap = MemoryUnit.MB.toBytes(heap) / MemoryUnit.KB.toBytes(1);
long nbElements = MemoryUnit.GB.toBytes(disk) / MemoryUnit.KB.toBytes(1);
CacheConfigurationBuilder<String, byte[]> cacheBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, byte[].class,
newResourcePoolsBuilder()
.heap(nbElementsHeap, EntryUnit.ENTRIES)
.offheap(offheap, MemoryUnit.GB)
.disk(disk, MemoryUnit.GB)
.build());
ConcurrencyConfig concurrency = ConcurrencyConfig.concurrencyConfig()
.threads(4).timeout(30, MINUTES);
ObjectGenerator<String> keyGenerator = fixedLengthString(10);
ObjectGenerator<byte[]> valueGenerator = fixedLengthByteArray(1024);
CacheManager cacheManager = newCacheManagerBuilder()
.with(new CacheManagerPersistenceConfiguration(new File("/data/PerfTest3")))
.withCache("one", cacheBuilder.build())
.build(true);
Cache<String, byte[]> one = cacheManager.getCache("one", String.class, byte[].class);
try {
System.out.println("----------> Cache Warm up phase");
long start = System.nanoTime();
Runner.setUp(
scenario("Cache warm up phase")
.exec(put(keyGenerator, valueGenerator, sequentially(), singletonList(cache("one", one)))))
.executed(times(nbElements))
.config(concurrency)
.config(report(EhcacheResult.class, new EhcacheResult[] { PUT }).log(text(), html("warmup-tier")))
.config(cacheConfig(String.class, byte[].class)
.cache("one", one)
)
.start();
long end = System.nanoTime();
System.out.println("Warmup time = " + TimeUnit.NANOSECONDS.toMillis((end - start)) + "ms");
Integer testLength = Integer.parseInt(System.getProperty("testLength", "7"));
System.out.println("----------> Test phase");
StatisticsPeekHolder finalStats = Runner.setUp(
scenario("Test phase")
.exec(
weighted(0.90, get(String.class, byte[].class).using(keyGenerator, valueGenerator)
.atRandom(GAUSSIAN, 0, nbElements, nbElements / 10)),
weighted(0.10, put(keyGenerator, valueGenerator, atRandom(GAUSSIAN, 0, nbElements, nbElements / 10),
singletonList(cache("one", one)))
)))
.warmup(during(3, minutes))
.executed(during(testLength, minutes))
.config(concurrency)
.config(report(EhcacheResult.class, new EhcacheResult[] { PUT, GET, MISS })
.log(text(), html("test-tier")))
.config(cacheConfig(String.class, byte[].class)
.cache("one", one)
)
.start();
System.out.println("----------> Done");
} catch (SyntaxException e) {
e.printStackTrace();
} finally {
cacheManager.close();
}
}
示例13: testReplace
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
@Ignore
public void testReplace() throws SyntaxException {
CacheConfigurationBuilder<Long, Long> builder = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, Long.class,
newResourcePoolsBuilder().heap(250000, EntryUnit.ENTRIES).build());
final CacheManager cacheManager = newCacheManagerBuilder()
.withCache("one", builder.build())
.build(true);
final Cache<Long, Long> one = cacheManager.getCache("one", Long.class, Long.class);
ConcurrencyConfig concurrency = ConcurrencyConfig.concurrencyConfig()
.threads(4).timeout(50, MINUTES);
int nbElements = 250000;
ObjectGenerator<Long> keyGenerator = new LongGenerator();
ObjectGenerator<Long> valueGenerator = new LongGenerator();
ReportingConfig reportingConfig = ReportingConfig.report(EhcacheResult.class).log(text());
CacheConfig<Long, Long> cacheConfig = cacheConfig(Long.class, Long.class).cache("one", one);
Runner.setUp(
scenario("warmup phase").exec(
put(keyGenerator, valueGenerator, sequentially(), singletonList(cache("one", one)
))))
.executed(times(nbElements))
.config(concurrency, reportingConfig)
.config(cacheConfig)
.start()
;
Runner.setUp(
scenario("Test phase").exec(
removeForKeyAndValue(Long.class, Long.class).using(keyGenerator, valueGenerator).sequentially()
))
.executed(during(1, minutes))
.config(concurrency, reportingConfig)
.config(cacheConfig)
.start()
;
cacheManager.close();
}
示例14: testHisto
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
@Ignore
public void testHisto() throws SyntaxException {
CacheConfigurationBuilder<Long, byte[]> builder = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, byte[].class,
newResourcePoolsBuilder().heap(250000, EntryUnit.ENTRIES).build());
final CacheManager cacheManager = newCacheManagerBuilder()
.withCache("one", builder.build())
.withCache("two", builder.build())
.build(true);
final Cache<Long, byte[]> one = cacheManager.getCache("one", Long.class, byte[].class);
final Cache<Long, byte[]> two = cacheManager.getCache("two", Long.class, byte[].class);
ConcurrencyConfig concurrency = ConcurrencyConfig.concurrencyConfig()
.threads(4).timeout(50, MINUTES);
ObjectGenerator<Long> keyGenerator = new LongGenerator();
ObjectGenerator<byte[]> valueGenerator = fixedLengthByteArray(1000);
EhcacheResult[] resultsReported = new EhcacheResult[] { GET, PUT, MISS };
Scenario scenario = scenario("Test phase").exec(
put(keyGenerator, valueGenerator, sequentially(), asList(cache("one", one), cache("two", two))),
get(Long.class, byte[].class).using(keyGenerator, valueGenerator).sequentially()
);
System.out.println("----------> Warm up phase");
Runner.setUp(scenario)
.executed(during(15, seconds))
.config(concurrency,
ReportingConfig.report(EhcacheResult.class, resultsReported).log(text()))
.config(cacheConfig(Long.class, byte[].class).cache("one", one).cache("two", two)
)
.start();
System.out.println("----------> Test phase");
Runner.setUp(
scenario)
.executed(during(30, seconds))
.config(concurrency,
ReportingConfig.report(EhcacheResult.class, resultsReported).log(text(), html()))
.config(cacheConfig(Long.class, byte[].class).cache("one", one).cache("two", two)
)
.start();
System.out.println("----------> Done");
cacheManager.close();
}
示例15: testBasic
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
@Test
@Ignore
public void testBasic() {
int heap = 200000;
int offheap = 1;
int disk = 2;
long nbElementsHeap = MemoryUnit.MB.toBytes(heap) / MemoryUnit.KB.toBytes(1);
long nbElements = MemoryUnit.GB.toBytes(disk) / MemoryUnit.KB.toBytes(1);
CacheConfigurationBuilder<String, byte[]> cacheBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, byte[].class,
newResourcePoolsBuilder()
.heap(nbElementsHeap, EntryUnit.ENTRIES)
.offheap(offheap, MemoryUnit.GB)
.build());
ConcurrencyConfig concurrency = ConcurrencyConfig.concurrencyConfig()
.threads(4).timeout(30, MINUTES);
ObjectGenerator<String> keyGenerator = fixedLengthString(10);
ObjectGenerator<byte[]> valueGenerator = fixedLengthByteArray(1024);
CacheManager cacheManager = newCacheManagerBuilder()
.with(new CacheManagerPersistenceConfiguration(new File("/data/PerfTest3")))
.withCache("one", cacheBuilder.build())
.build(true);
Cache<String, byte[]> one = cacheManager.getCache("one", String.class, byte[].class);
try {
System.out.println("----------> Cache Warm up phase");
long start = System.nanoTime();
Runner.setUp(
scenario("Cache warm up phase")
.exec(put(keyGenerator, valueGenerator, sequentially(), singletonList(cache("one", one)))))
.executed(times(nbElements))
.config(concurrency)
.config(report(EhcacheResult.class, new EhcacheResult[] { PUT }).log(text()))
.config(cacheConfig(String.class, byte[].class)
.cache("one", one)
)
// .start()
;
long end = System.nanoTime();
System.out.println("Warmup time = " + TimeUnit.NANOSECONDS.toMillis((end - start)) + "ms");
Integer testLength = Integer.parseInt(System.getProperty("testLength", "7"));
System.out.println("----------> Test phase");
StatisticsPeekHolder finalStats = Runner.setUp(
scenario("Test phase")
.exec(
weighted(0.90, get(String.class, byte[].class).using(keyGenerator, valueGenerator)
.atRandom(GAUSSIAN, 0, nbElements, nbElements / 10)),
weighted(0.10, put(keyGenerator, valueGenerator, atRandom(GAUSSIAN, 0, nbElements, nbElements / 10),
singletonList(cache("one", one))))
))
.warmup(during(30, seconds))
.executed(during(2, minutes))
.config(concurrency)
.config(report(EhcacheResult.class, new EhcacheResult[] { PUT, GET, MISS })
.collect(gcStatistics()).log(text(), html("test-basic") ))
.config(cacheConfig(String.class, byte[].class)
.cache("one", one)
)
.start();
System.out.println("----------> Done");
} catch (SyntaxException e) {
e.printStackTrace();
} finally {
cacheManager.close();
}
}