Java Code Examples for org.ehcache.config.builders.ResourcePoolsBuilder#build()
The following examples show how to use
org.ehcache.config.builders.ResourcePoolsBuilder#build() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EhcacheRuntimeConfigurationTest.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test public void testUpdateResources() throws Exception { CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.newResourcePoolsBuilder() .heap(10L, EntryUnit.ENTRIES).disk(10, MemoryUnit.MB).build()).build(); try (CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder() .with(new CacheManagerPersistenceConfiguration(diskPath.newFolder("myData"))) .withCache("cache", cacheConfiguration).build(true)) { Cache<Long, String> cache = cacheManager.getCache("cache", Long.class, String.class); ResourcePoolsBuilder poolsBuilder = ResourcePoolsBuilder.newResourcePoolsBuilder(); poolsBuilder = poolsBuilder.heap(20L, EntryUnit.ENTRIES); ResourcePools pools = poolsBuilder.build(); cache.getRuntimeConfiguration().updateResourcePools(pools); assertThat(cache.getRuntimeConfiguration().getResourcePools() .getPoolForResource(ResourceType.Core.HEAP).getSize(), is(20L)); pools = poolsBuilder.build(); cache.getRuntimeConfiguration().updateResourcePools(pools); assertThat(cache.getRuntimeConfiguration().getResourcePools() .getPoolForResource(ResourceType.Core.HEAP).getSize(), is(20L)); } }
Example 2
Source File: EhcacheRuntimeConfigurationTest.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test public void testUpdateFailureDoesNotUpdate() { CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.newResourcePoolsBuilder() .heap(10L, EntryUnit.ENTRIES).build()).build(); try(CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder() .withCache("cache", cacheConfiguration).build(true)) { Cache<Long, String> cache = cacheManager.getCache("cache", Long.class, String.class); ResourcePoolsBuilder poolsBuilder = ResourcePoolsBuilder.newResourcePoolsBuilder(); poolsBuilder = poolsBuilder.heap(20L, EntryUnit.ENTRIES).disk(10, MemoryUnit.MB); ResourcePools pools = poolsBuilder.build(); try { cache.getRuntimeConfiguration().updateResourcePools(pools); fail("We expect illegal arguments"); } catch (IllegalArgumentException iae) { // expected assertThat(iae.getMessage(), is("Pools to be updated cannot contain previously undefined resources pools")); } assertThat(cache.getRuntimeConfiguration().getResourcePools() .getPoolForResource(ResourceType.Core.HEAP).getSize(), is(10L)); } }
Example 3
Source File: AbstractCalculationTest.java From ehcache3 with Apache License 2.0 | 4 votes |
protected AbstractCalculationTest(ResourcePoolsBuilder poolBuilder) { this.resources = poolBuilder.build(); }
Example 4
Source File: ResourceConfigurationParser.java From ehcache3 with Apache License 2.0 | 4 votes |
public ResourcePools parseResourceConfiguration(CacheTemplate cacheTemplate, ResourcePoolsBuilder resourcePoolsBuilder) { if (cacheTemplate.getHeap() != null) { resourcePoolsBuilder = resourcePoolsBuilder.with(parseHeapConfiguration(cacheTemplate.getHeap())); } else if (!cacheTemplate.getResources().isEmpty()) { for (Element element : cacheTemplate.getResources()) { ResourcePool resourcePool; if (!CORE_SCHEMA_NS.equals(element.getNamespaceURI())) { resourcePool = parseResourceExtension(element); } else { try { Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); unmarshaller.setSchema(CORE_SCHEMA); Object resource = unmarshaller.unmarshal(element); if (resource instanceof Heap) { resourcePool = parseHeapConfiguration((Heap) resource); } else if (resource instanceof Offheap) { MemoryType offheapResource = ((Offheap) resource).getValue(); resourcePool = new SizedResourcePoolImpl<>(org.ehcache.config.ResourceType.Core.OFFHEAP, offheapResource.getValue().longValue(), parseMemory(offheapResource), false); } else if (resource instanceof Disk) { PersistableMemoryType diskResource = ((Disk) resource).getValue(); resourcePool = new SizedResourcePoolImpl<>(org.ehcache.config.ResourceType.Core.DISK, diskResource.getValue().longValue(), parseMemory(diskResource), diskResource.isPersistent()); } else { // Someone updated the core resources without updating *this* code ... throw new AssertionError("Unrecognized resource: " + element + " / " + resource.getClass().getName()); } } catch (JAXBException e) { throw new IllegalArgumentException("Can't find parser for resource: " + element, e); } } resourcePoolsBuilder = resourcePoolsBuilder.with(resourcePool); } } else { throw new XmlConfigurationException("No resources defined for the cache: " + cacheTemplate.id()); } return resourcePoolsBuilder.build(); }