private GlobalConfiguration getGlobalConfiguration() { GlobalConfigurationBuilder builder = new GlobalConfigurationBuilder(); return builder.read(getWebCacheManager().getCacheManagerConfiguration()) .classLoader(Thread.currentThread().getContextClassLoader()) .transport().clusterName("wboss") .build(); } }
@Test(expectedExceptions = CacheConfigurationException.class) public void testClusterNameNull() { GlobalConfigurationBuilder gc = new GlobalConfigurationBuilder(); gc.transport().clusterName(null).build(); }
.defaultTransport() .addProperty("configurationFile", "default-configs/default-jgroups-kubernetes.xml") .build();
public static EmbeddedCacheManager createCacheManager(GlobalConfigurationBuilder globalBuilder, ConfigurationBuilder builder, boolean keepJmxDomain) { if (globalBuilder.transport().build().transport().transport() != null) { throw new IllegalArgumentException("Use TestCacheManagerFactory.createClusteredCacheManager(...) for clustered cache managers"); } return newDefaultCacheManager(true, globalBuilder, builder, keepJmxDomain); }
private static Cache mockCache(String nodeName, Configuration configuration, TimeService timeService) { String cacheName = "mock-cache"; AdvancedCache cache = mock(AdvancedCache.class, RETURNS_DEEP_STUBS); GlobalConfiguration gc = new GlobalConfigurationBuilder() .transport().nodeName(nodeName) .build(); Set<String> cachesSet = new HashSet<>(); EmbeddedCacheManager cm = mock(EmbeddedCacheManager.class); when(cm.getCacheManagerConfiguration()).thenReturn(gc); GlobalComponentRegistry gcr = new GlobalComponentRegistry(gc, cm, cachesSet); BasicComponentRegistry gbcr = gcr.getComponent(BasicComponentRegistry.class); gbcr.replaceComponent(TimeService.class.getName(), timeService, true); ComponentRegistry registry = new ComponentRegistry(cacheName, configuration, cache, gcr, configuration.getClass().getClassLoader()); when(cache.getClassLoader()).thenReturn(PersistenceMockUtil.class.getClassLoader()); when(cache.getCacheManager().getCacheManagerConfiguration()) .thenReturn(gc); when(cache.getName()).thenReturn(cacheName); when(cache.getAdvancedCache()).thenReturn(cache); when(cache.getComponentRegistry()).thenReturn(registry); when(cache.getStatus()).thenReturn(ComponentStatus.RUNNING); when(cache.getCacheConfiguration()).thenReturn(configuration); return cache; }
public static EmbeddedCacheManager createCacheManager(GlobalConfigurationBuilder globalBuilder, ConfigurationBuilder builder) { if (globalBuilder.transport().build().transport().transport() != null) { throw new IllegalArgumentException("Use TestCacheManagerFactory.createClusteredCacheManager(...) for clustered cache managers"); } amendTransport(globalBuilder); return newDefaultCacheManager(true, globalBuilder, builder, false); }
@Bean(destroyMethod = "stop") public DefaultCacheManager defaultCacheManager() throws IOException { final String configXml = infinispanProperties.getEmbedded().getConfigXml(); final GlobalConfiguration defaultGlobalConfiguration = new GlobalConfigurationBuilder() .globalJmxStatistics().jmxDomain(DEFAULT_JMX_DOMAIN).enable() .transport().clusterName(infinispanProperties.getEmbedded().getClusterName()) .build(); final GlobalConfiguration globalConfiguration = infinispanGlobalConfigurer == null? defaultGlobalConfiguration : infinispanGlobalConfigurer.getGlobalConfiguration(); final DefaultCacheManager manager = configXml.isEmpty()? new DefaultCacheManager(globalConfiguration) : new DefaultCacheManager(configXml); configureCaches(manager); return manager; }
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 testConfigBuilder() { GlobalConfiguration globalConfig = new GlobalConfigurationBuilder() .transport().defaultTransport() .build(); Configuration cacheConfig = new ConfigurationBuilder().persistence().addStore(LevelDBStoreConfigurationBuilder.class).location(tmpDataDirectory) .expiredLocation(tmpExpiredDirectory).implementationType(LevelDBStoreConfiguration.ImplementationType.AUTO).build(); StoreConfiguration cacheLoaderConfig = cacheConfig.persistence().stores().get(0); assertTrue(cacheLoaderConfig instanceof LevelDBStoreConfiguration); LevelDBStoreConfiguration leveldbConfig = (LevelDBStoreConfiguration) cacheLoaderConfig; assertEquals(tmpDataDirectory, leveldbConfig.location()); assertEquals(tmpExpiredDirectory, leveldbConfig.expiredLocation()); EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfig); cacheManager.defineConfiguration("testCache", cacheConfig); cacheManager.start(); Cache<String, String> cache = cacheManager.getCache("testCache"); cache.put("hello", "there"); cache.stop(); cacheManager.stop(); }