/** * Here we inject {@link Configuration}. */ @Bean public InfinispanCacheConfigurer cacheConfigurer() { logger.info("Defining {} configuration", CACHE_NAME); return manager -> { Configuration ispnConfig = new ConfigurationBuilder() .clustering().cacheMode(CacheMode.DIST_SYNC) .build(); manager.defineConfiguration(CACHE_NAME, ispnConfig); }; }
public static synchronized Configuration getDefaultConfiguration(CacheMode cacheMode) { if (defaults == null) { ConfigurationBuilderHolder holder = load(DEFAULTS); Configuration defaultConfig = holder.getDefaultConfigurationBuilder().build(); Map<CacheMode, Configuration> map = new EnumMap<>(CacheMode.class); map.put(defaultConfig.clustering().cacheMode(), defaultConfig); for (ConfigurationBuilder builder : holder.getNamedConfigurationBuilders().values()) { Configuration config = builder.build(); map.put(config.clustering().cacheMode(), config); } for (CacheMode mode : CacheMode.values()) { if (!map.containsKey(mode)) { map.put(mode, new ConfigurationBuilder().read(defaultConfig).clustering().cacheMode(mode).build()); } } defaults = map; } return defaults.get(cacheMode); }
.clustering() .cacheMode(CacheMode.REPL_SYNC) .build();
@Test public void testDefaultSegmented() { dataContainerFactory.configuration = new ConfigurationBuilder().clustering() .cacheMode(CacheMode.DIST_ASYNC).build(); assertEquals(DefaultSegmentedDataContainer.class, this.dataContainerFactory.construct(COMPONENT_NAME).getClass()); }
@Test public void testNotAvailableFeature() { Features features = mock(Features.class); dataContainerFactory.globalConfiguration = mock(GlobalConfiguration.class); when(dataContainerFactory.globalConfiguration.features()).thenReturn(features); when(features.isAvailable(DataContainerFactory.SEGMENTATION_FEATURE)).thenReturn(false); dataContainerFactory.configuration = new ConfigurationBuilder().clustering() .memory().storageType(StorageType.OFF_HEAP).evictionStrategy(EvictionStrategy.REMOVE).size(1000) .clustering().cacheMode(CacheMode.DIST_ASYNC).build(); assertEquals(BoundedOffHeapDataContainer.class, this.dataContainerFactory.construct(COMPONENT_NAME).getClass()); } }
@BeforeMethod private void configureBeforeMethod() { mockedCacheManager = mock(DefaultCacheManager.class); // We return the real global component registry to avoid to mock all the dependencies in the world when(mockedCacheManager.getGlobalComponentRegistry()).thenReturn(cacheManager.getGlobalComponentRegistry()); internalCacheRegistry.registerInternalCache(INTERNAL_CACHE_NAME, new ConfigurationBuilder().clustering().cacheMode(CacheMode.DIST_ASYNC).build(), EnumSet.of(InternalCacheRegistry.Flag.EXCLUSIVE)); cacheManager.defineConfiguration(CACHE_NAME, new ConfigurationBuilder().build()); }
@Test public void testEvictionRemoveSegmented() { dataContainerFactory.configuration = new ConfigurationBuilder().clustering() .memory().evictionStrategy(EvictionStrategy.REMOVE).size(1000) .clustering().cacheMode(CacheMode.DIST_ASYNC).build(); assertEquals(BoundedSegmentedDataContainer.class, this.dataContainerFactory.construct(COMPONENT_NAME).getClass()); }
@Test public void testEvictionRemoveSegmentedOffHeap() { dataContainerFactory.configuration = new ConfigurationBuilder().clustering() .memory().storageType(StorageType.OFF_HEAP).evictionStrategy(EvictionStrategy.REMOVE).size(1000) .clustering().cacheMode(CacheMode.DIST_ASYNC).build(); assertEquals(SegmentedBoundedOffHeapDataContainer.class, this.dataContainerFactory.construct( COMPONENT_NAME).getClass()); }
public void testOnePhaseCommitConfigured() throws XAException { Configuration configuration = new ConfigurationBuilder().clustering().cacheMode(CacheMode.INVALIDATION_ASYNC).build(); TestingUtil.inject(txCoordinator, configuration); txCoordinator.start(); assert XAResource.XA_OK == xaAdapter.prepare(xid); }
public void test1PcAndNonExistentXid2() { Configuration configuration = new ConfigurationBuilder().clustering().cacheMode(CacheMode.DIST_SYNC).build(); TestingUtil.inject(txCoordinator, configuration); try { EmbeddedXid doesNotExists = new EmbeddedXid(uuid); xaAdapter.commit(doesNotExists, true); assert false; } catch (XAException e) { assertEquals(XAException.XAER_NOTA, e.errorCode); } } }
@Override protected void createCacheManagers() throws Throwable { ConfigurationBuilder cfg = new ConfigurationBuilder(); cfg .persistence() .addStore(DummyInMemoryStoreConfigurationBuilder.class) .storeName(SharedStoreTest.class.getName()) .purgeOnStartup(false).shared(true) .clustering() .cacheMode(cacheMode) .build(); createCluster(cfg, 3); // don't create the caches here, we want them to join the cluster one by one }
public void test1PcAndNonExistentXid() { Configuration configuration = new ConfigurationBuilder().clustering().cacheMode(CacheMode.INVALIDATION_ASYNC).build(); TestingUtil.inject(txCoordinator, configuration); try { EmbeddedXid doesNotExists = new EmbeddedXid(uuid); xaAdapter.commit(doesNotExists, false); assert false; } catch (XAException e) { assertEquals(XAException.XAER_NOTA, e.errorCode); } }
private EmbeddedCacheManager createCacheManagerProgrammatically() { System.out.println("Starting a cache manager with a programmatic configuration"); DefaultCacheManager cacheManager = new DefaultCacheManager( GlobalConfigurationBuilder.defaultClusteredBuilder() .transport().nodeName(nodeName).addProperty("configurationFile", "jgroups.xml") .build(), new ConfigurationBuilder() .clustering() .cacheMode(CacheMode.REPL_SYNC) .build() ); // The only way to get the "repl" cache to be exactly the same as the default cache is to not define it at all cacheManager.defineConfiguration("dist", new ConfigurationBuilder() .clustering() .cacheMode(CacheMode.DIST_SYNC) .hash().numOwners(2) .build() ); return cacheManager; }
public void testNoneIsolationLevelInCluster() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.locking().isolationLevel(IsolationLevel.NONE) .clustering().cacheMode(CacheMode.REPL_SYNC).build(); withCacheManager(new CacheManagerCallable( TestCacheManagerFactory.createClusteredCacheManager(builder)) { @Override public void call() { Configuration cfg = cm.getCache().getCacheConfiguration(); assertEquals(IsolationLevel.READ_COMMITTED, cfg.locking().isolationLevel()); } }); }
private EmbeddedCacheManager createCacheManager(int index) { GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder(); gcb.transport().defaultTransport(); TestCacheManagerFactory.amendGlobalConfiguration(gcb, new TransportFlags().withPortRange(index)); ConfigurationBuilder defaultCacheConfig = new ConfigurationBuilder(); EmbeddedCacheManager cm = TestCacheManagerFactory.newDefaultCacheManager(false, gcb, defaultCacheConfig, false); registerCacheManager(cm); Configuration replCfg = new ConfigurationBuilder().clustering().cacheMode(CacheMode.REPL_SYNC).build(); cm.defineConfiguration(REPL_CACHE_NAME, replCfg); Configuration distCfg = new ConfigurationBuilder().clustering().cacheMode(CacheMode.DIST_SYNC).build(); cm.defineConfiguration(DIST_CACHE_NAME, distCfg); Configuration scatteredCfg = new ConfigurationBuilder().clustering().cacheMode(CacheMode.SCATTERED_SYNC).build(); cm.defineConfiguration(SCATTERED_CACHE_NAME, scatteredCfg); return cm; }
@Test public void testBuildTimestampsRegionWithCacheNameOverride() { final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache"; final String myTimestampsCache = "mytimestamps-cache"; Properties p = createProperties(); p.setProperty(TIMESTAMPS_CACHE_RESOURCE_PROP, myTimestampsCache); TestRegionFactory factory = createRegionFactory(p, m -> { ClusteringConfigurationBuilder builder = new ConfigurationBuilder().clustering().cacheMode(CacheMode.LOCAL); m.defineConfiguration(myTimestampsCache, builder.build()); }); try { InfinispanBaseRegion region = factory.buildTimestampsRegion(timestamps); assertTrue(isDefinedCache(factory, timestamps)); // default timestamps cache is async replicated assertEquals(CacheMode.LOCAL, region.getCache().getCacheConfiguration().clustering().cacheMode()); } finally { factory.stop(); } }
@Override public void call() { // DIST_ASYNC isn't default so it should stay applied CacheMode cacheMode = CacheMode.DIST_ASYNC; String templateName = "dist-cache-template"; cm.defineConfiguration(templateName, new ConfigurationBuilder().clustering().cacheMode(cacheMode).template(true).build()); CacheMode overrideCacheMode = CacheMode.REPL_ASYNC; Configuration overrideConfiguration = new ConfigurationBuilder().clustering().cacheMode(overrideCacheMode).build(); String ourCacheName = "my-cache"; cm.defineConfiguration(ourCacheName, templateName, overrideConfiguration); Cache cache = cm.getCache(ourCacheName); // We expect the override to take precedence assertEquals(overrideCacheMode, cache.getCacheConfiguration().clustering().cacheMode()); } });