@Produces public Configuration customDefaultConfiguration() { return new ConfigurationBuilder() .memory().size(16) .build(); } }
@Test public void testEvictionSize() { Configuration configuration = new ConfigurationBuilder() .memory().size(20) .build(); Assert.assertEquals(configuration.memory().size(), 20); }
@Test public void testOffHeap() { dataContainerFactory.configuration = new ConfigurationBuilder() .memory().storageType(StorageType.OFF_HEAP).build(); assertEquals(OffHeapDataContainer.class, dataContainerFactory.construct(COMPONENT_NAME).getClass()); }
@Test(expectedExceptions = CacheConfigurationException.class) public void testStoreAsBinary() { new ConfigurationBuilder().simpleCache(true).memory().storageType(StorageType.BINARY).build(); }
@Test public void testSegmentedOffHeapAndL1() { dataContainerFactory = spy(new DataContainerFactory()); doReturn(mock(OffHeapConcurrentMap.class)) .when(dataContainerFactory) .createAndStartOffHeapConcurrentMap(anyInt(), anyInt()); dataContainerFactory.globalConfiguration = GlobalConfigurationBuilder.defaultClusteredBuilder().build(); dataContainerFactory.configuration = new ConfigurationBuilder().clustering() .cacheMode(CacheMode.DIST_ASYNC) .l1().enable() .memory().storageType(StorageType.OFF_HEAP).build(); assertEquals(L1SegmentedDataContainer.class, this.dataContainerFactory.construct(COMPONENT_NAME).getClass()); }
@Test public void testEvictionRemoveNotSegmented() { dataContainerFactory.configuration = new ConfigurationBuilder().clustering() .memory().evictionStrategy(EvictionStrategy.REMOVE).size(1000).build(); assertEquals(DefaultDataContainer.class, this.dataContainerFactory.construct(COMPONENT_NAME).getClass()); }
/** * <p>Defines the "large" cache configuration.</p> * * <p>This cache will be registered with the produced configuration in the default cache manager.</p> */ @Large @ConfigureCache("large") @Produces @SuppressWarnings("unused") public Configuration largeConfiguration() { return new ConfigurationBuilder() .memory().size(1024) .build(); }
/** * <p>Defines the "very-large" cache configuration.</p> * * <p>This cache will be registered with the produced configuration in the specific cache manager.</p> */ @VeryLarge @ConfigureCache("very-large") @Produces @SuppressWarnings("unused") public Configuration veryLargeConfiguration() { return new ConfigurationBuilder() .memory().size(4096) .build(); }
/** * <p>Configures a "tiny" cache (with a very low number of entries), and associates it with the qualifier {@link * Tiny}.</p> * * <p>This will use the default cache container.</p> */ @Tiny @ConfigureCache("tiny") @Produces public Configuration tinyConfiguration() { return new ConfigurationBuilder() .memory().size(1) .build(); }
/** * <p>Configures a "small" cache (with a pretty low number of entries), and associates it with the qualifier {@link * Small}.</p> * * <p>This will use the default cache container.</p> */ @Small @ConfigureCache("small") @Produces public Configuration smallConfiguration() { return new ConfigurationBuilder() .memory().size(10) .build(); } }
@Test public void testEvictionRemoveNotSegmentedOffHeap() { dataContainerFactory.configuration = new ConfigurationBuilder().clustering() .memory().storageType(StorageType.OFF_HEAP).evictionStrategy(EvictionStrategy.REMOVE).size(1000) .build(); assertEquals(BoundedOffHeapDataContainer.class, this.dataContainerFactory.construct(COMPONENT_NAME).getClass()); }
@Test public void testSegmentedOffHeap() { dataContainerFactory.configuration = new ConfigurationBuilder().clustering().cacheMode(CacheMode.DIST_ASYNC) .memory().storageType(StorageType.OFF_HEAP).build(); assertTrue(dataContainerFactory.globalConfiguration.features().isAvailable(DataContainerFactory.SEGMENTATION_FEATURE)); assertEquals(DefaultSegmentedDataContainer.class, dataContainerFactory.construct(COMPONENT_NAME).getClass()); }
@Override protected EmbeddedCacheManager createCacheManager() throws Exception { ConfigurationBuilder cfg = new ConfigurationBuilder(); cfg .memory().storageType(StorageType.BINARY).evictionType(EvictionType.MEMORY).size(MAX_MEMORY) .build(); EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(cfg); cache = cm.getCache(); return cm; }
/** * Associates the "large" cache with the qualifier {@link Large}. * * @param cacheManager the specific cache manager associated to this cache. This cache manager is used to get the * default cache configuration. */ @Large @ConfigureCache("large") @Produces @SuppressWarnings("unused") public Configuration largeConfiguration(@Large EmbeddedCacheManager cacheManager) { return new ConfigurationBuilder() .read(cacheManager.getDefaultCacheConfiguration()) .memory().size(2000) .build(); }
/** * Associates the "small" cache with the qualifier {@link Small}. * * @param cacheManager the specific cache manager associated to this cache. This cache manager is used to get the * default cache configuration. */ @Small @ConfigureCache("small") @Produces @SuppressWarnings("unused") public Configuration smallConfiguration(@Small EmbeddedCacheManager cacheManager) { return new ConfigurationBuilder() .read(cacheManager.getDefaultCacheConfiguration()) .memory().size(20) .build(); }
/** * Overrides the default embedded cache manager to define the quick and large cache configurations externally. */ @Produces @ApplicationScoped @SuppressWarnings("unused") public EmbeddedCacheManager defaultCacheManager() { EmbeddedCacheManager externalCacheContainerManager = TestCacheManagerFactory.createCacheManager(false); // define large configuration externalCacheContainerManager.defineConfiguration("large", new ConfigurationBuilder() .memory().size(100) .build()); // define quick configuration externalCacheContainerManager.defineConfiguration("quick", new ConfigurationBuilder() .expiration().wakeUpInterval(1l) .build()); return externalCacheContainerManager; }
public void testConfigOverriding() { ConfigurationBuilder c = new ConfigurationBuilder(); c.memory().storageType(StorageType.BINARY); ecm = TestCacheManagerFactory.createCacheManager(c); ecm.defineConfiguration("newCache", new ConfigurationBuilder().read(c.build()).memory().storageType(StorageType.OBJECT).build()); assertEquals(StorageType.OBJECT, ecm.getCache("newCache").getCacheConfiguration().memory().storageType()); }
public void testStoreAsBinaryOnBoth() { ConfigurationBuilder c = new ConfigurationBuilder(); c.memory().storageType(StorageType.BINARY).build(); ecm = TestCacheManagerFactory.createCacheManager(c); ecm.getCache().put(key, value); DataConversion keyDataConversion = ecm.getCache().getAdvancedCache().getKeyDataConversion(); DataConversion valueDataConversion = ecm.getCache().getAdvancedCache().getValueDataConversion(); DataContainer<?, ?> dc = ecm.getCache().getAdvancedCache().getDataContainer(); InternalCacheEntry entry = dc.iterator().next(); Object key = entry.getKey(); Object value = entry.getValue(); assertTrue(key instanceof WrappedBytes); assertEquals(keyDataConversion.fromStorage(key), this.key); assertTrue(value instanceof WrappedBytes); assertEquals(valueDataConversion.fromStorage(value), this.value); } }