@Override public String getName() { GlobalConfiguration global = this.cache.getCacheManager().getCacheManagerConfiguration(); TransportConfiguration transport = global.transport(); return transport.transport() != null ? transport.clusterName() : global.globalJmxStatistics().cacheManagerName(); }
@Override public void accept(ConfigurationBuilder builder) { super.accept(builder); HashConfigurationBuilder hash = builder.clustering().hash().numSegments(this.segments); // ConsistentHashStrategy.INTER_CACHE is Infinispan's default behavior if (this.consistentHashStrategy == ConsistentHashStrategy.INTRA_CACHE) { hash.consistentHashFactory(this.global.get().transport().hasTopologyInfo() ? new TopologyAwareConsistentHashFactory() : new DefaultConsistentHashFactory()); } } }
@Override public void start() { GlobalConfigurationBuilder builder = new GlobalConfigurationBuilder(); // WFLY-6685 Prevent Infinispan from registering channel mbeans // The JGroups subsystem already does this builder.globalJmxStatistics().read(this.configuration.globalJmxStatistics()).disable(); // ISPN-4755 workaround TransportConfiguration transport = this.configuration.transport(); builder.transport() .clusterName(transport.clusterName()) .distributedSyncTimeout(transport.distributedSyncTimeout()) .initialClusterSize(transport.initialClusterSize()) .initialClusterTimeout(transport.initialClusterTimeout(), TimeUnit.MILLISECONDS) .machineId(transport.machineId()) .nodeName(transport.nodeName()) .rackId(transport.rackId()) .siteId(transport.siteId()) .transport(transport.transport()) .withProperties(transport.properties()) ; this.configuration = builder.build(); super.start(); }
@Test(dataProvider = "params") public void runTest(ClusterExecutionPolicy policy, int site, int rack, int machine, int invocationCount) throws InterruptedException, ExecutionException, TimeoutException { actualInvocations.set(0); EmbeddedCacheManager cacheManager = cacheManagers.stream().filter(cm -> { TransportConfiguration tc = cm.getCacheManagerConfiguration().transport(); return Integer.valueOf(tc.siteId()) == site && Integer.valueOf(tc.rackId()) == rack && Integer.valueOf(tc.machineId()) == machine; }).findFirst().orElseThrow(() -> new AssertionError("No cache manager matches site: " + site + " rack: " + rack + " machine: " + machine)); cacheManager.executor().filterTargets(policy).submit(() -> actualInvocations.incrementAndGet()).get(10, TimeUnit.SECONDS); assertEquals(invocationCount, actualInvocations.get()); } }
/** * Carry out any initialization tasks that might be necessary */ @Override public void initialize() { cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true); if(entryCache == null) { cacheManager.defineConfiguration(LDCACHE_ENTRY_CACHE, defaultConfiguration); entryCache = cacheManager.<String,CacheEntry>getCache(LDCACHE_ENTRY_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP); } log.info("initialised cache manager ({})", globalConfiguration.isClustered() ? "cluster name: "+globalConfiguration.transport().clusterName() : "single host"); }
private void defineTopologyCacheConfig(EmbeddedCacheManager cacheManager) { InternalCacheRegistry internalCacheRegistry = cacheManager.getGlobalComponentRegistry().getComponent(InternalCacheRegistry.class); internalCacheRegistry.registerInternalCache(configuration.topologyCacheName(), createTopologyCacheConfig(cacheManager.getCacheManagerConfiguration().transport().distributedSyncTimeout()).build(), EnumSet.of(InternalCacheRegistry.Flag.EXCLUSIVE)); }
@Override public String getName() { GlobalConfiguration global = this.cache.getCacheManager().getCacheManagerConfiguration(); TransportConfiguration transport = global.transport(); return transport.transport() != null ? transport.clusterName() : global.globalJmxStatistics().cacheManagerName(); }
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 JChannel createJGroupsChannel(GlobalConfiguration oldGC) { GlobalConfigurationBuilder builder = new GlobalConfigurationBuilder().read(oldGC); TestCacheManagerFactory.amendTransport(builder); GlobalConfiguration gc = builder.build(); Properties p = gc.transport().properties(); String jgroupsCfg = p.getProperty(JGroupsTransport.CONFIGURATION_STRING); try { JChannel channel = new JChannel(new ByteArrayInputStream(jgroupsCfg.getBytes())); channel.setName(gc.transport().nodeName()); channel.connect(gc.transport().clusterName()); return channel; } catch (Exception e) { throw new CacheException(e); } } }
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); }
@Override public void accept(ConfigurationBuilder builder) { super.accept(builder); HashConfigurationBuilder hash = builder.clustering().hash().numSegments(this.segments); // ConsistentHashStrategy.INTER_CACHE is Infinispan's default behavior if (this.consistentHashStrategy == ConsistentHashStrategy.INTRA_CACHE) { hash.consistentHashFactory(this.global.get().transport().hasTopologyInfo() ? new TopologyAwareConsistentHashFactory() : new DefaultConsistentHashFactory()); } } }
@Override public void call() { GlobalConfiguration globalCfg = cm.getCacheManagerConfiguration(); assertTrue(globalCfg.transport().transport() instanceof JGroupsTransport); assertEquals("demoCluster", globalCfg.transport().clusterName()); Configuration cfg = cm.getDefaultCacheConfiguration(); assertEquals(CacheMode.REPL_SYNC, cfg.clustering().cacheMode()); }
@AfterClass(alwaysRun = true) protected void destroy() { if (cleanupAfterTest()) { TestingUtil.clearContent(cacheManagers); TestingUtil.killCacheManagers(cacheManagers); } for (EmbeddedCacheManager cm : cacheManagers) { String nodeName = cm.getCacheManagerConfiguration().transport().nodeName(); assertTrue("Invalid node name for test " + getCurrentTestShortName() + ": " + nodeName, nodeName != null && nodeName.contains(getCurrentTestShortName())); } cacheManagers.clear(); listeners.clear(); }
private void withClusteredServer(HotRodServerConfigurationBuilder builder, BiConsumer<Configuration, Long> consumer) { Stoppable.useCacheManager(TestCacheManagerFactory.createClusteredCacheManager(hotRodCacheConfiguration()), cm -> Stoppable.useServer(startHotRodServer(cm, serverPort(), builder), server -> { Configuration cfg = cm.getCacheConfiguration(server.getConfiguration().topologyCacheName()); consumer.accept(cfg, cm.getCacheManagerConfiguration().transport().distributedSyncTimeout()); })); }
@Test public void testIfSpringEmbeddedCacheManagerFactoryBeanAllowesOverridingGlobalConfiguration() throws Exception { GlobalConfigurationBuilder overriddenConfiguration = new GlobalConfigurationBuilder(); overriddenConfiguration.transport().rackId("r2"); objectUnderTest = SpringEmbeddedCacheManagerFactoryBeanBuilder .defaultBuilder().fromFile(NAMED_ASYNC_CACHE_CONFIG_LOCATION, getClass()) .withGlobalConfiguration(overriddenConfiguration).build(); final SpringEmbeddedCacheManager springEmbeddedCacheManager = objectUnderTest.getObject(); assertEquals( "Transport for cache configured in" + CACHE_NAME_FROM_CONFIGURATION_FILE + "is assigned to r1 rack. But later Global Configuration overrides " + "this setting to r2. Obviously created SpringEmbeddedCacheManagerFactoryBean does not support this kind " + "of overriding.", "r2", springEmbeddedCacheManager.getNativeCacheManager().getCacheManagerConfiguration().transport().rackId()); }
private static void amendTransport(GlobalConfigurationBuilder builder, TransportFlags flags) { String testName = TestResourceTracker.getCurrentTestName(); GlobalConfiguration gc = builder.build(); if (gc.transport().transport() != null) { // Remove any configuration file that might have been set. builder.transport().removeProperty(JGroupsTransport.CONFIGURATION_FILE); builder.transport().addProperty(JGroupsTransport.CONFIGURATION_STRING, getJGroupsConfig(testName, flags)); } }
public static EmbeddedCacheManager fromStream(InputStream is, boolean keepJmxDomainName, boolean defaultParsersOnly, boolean start) throws IOException { ParserRegistry parserRegistry = new ParserRegistry(Thread.currentThread().getContextClassLoader(), defaultParsersOnly); ConfigurationBuilderHolder holder = parserRegistry.parse(is); // The node name is set in each DefaultThreadFactory individually, override it here String testShortName = TestResourceTracker.getCurrentTestShortName(); GlobalConfiguration gc = holder.getGlobalConfigurationBuilder().build(); updateNodeName(testShortName, gc.listenerThreadPool()); updateNodeName(testShortName, gc.expirationThreadPool()); updateNodeName(testShortName, gc.persistenceThreadPool()); updateNodeName(testShortName, gc.stateTransferThreadPool()); updateNodeName(testShortName, gc.asyncThreadPool()); updateNodeName(testShortName, gc.transport().transportThreadPool()); return createClusteredCacheManager(start, holder, keepJmxDomainName); }
public void testGlobalConfig() throws Exception { ConfigurationBuilderHolder holder = parse(); GlobalConfiguration gc = holder.getGlobalConfigurationBuilder().build(); BlockingThreadPoolExecutorFactory listenerThreadPool = gc.listenerThreadPool().threadPoolFactory(); assertEquals(2, listenerThreadPool.maxThreads()); BlockingThreadPoolExecutorFactory persistenceThreadPool = gc.persistenceThreadPool().threadPoolFactory(); assertEquals(4, persistenceThreadPool.maxThreads()); Properties transportProps = gc.transport().properties(); assertEquals("jgroups-tcp.xml", transportProps.get("configurationFile")); Configuration configuration = holder.getDefaultConfigurationBuilder().build(); assertEquals(IsolationLevel.READ_COMMITTED, configuration.locking().isolationLevel()); } }
@Override public void check(ConfigurationBuilderHolder holder) { GlobalConfiguration globalConfiguration = getGlobalConfiguration(holder); assertEquals(4, globalConfiguration.transport().initialClusterSize()); assertEquals(30000, globalConfiguration.transport().initialClusterTimeout()); MemoryConfiguration mc = getConfiguration(holder, "off-heap-memory").memory(); assertEquals(StorageType.OFF_HEAP, mc.storageType()); assertEquals(10000000, mc.size()); assertEquals(4, mc.addressCount()); assertEquals(EvictionType.MEMORY, mc.evictionType()); mc = getConfiguration(holder, "binary-memory").memory(); assertEquals(StorageType.BINARY, mc.storageType()); assertEquals(1, mc.size()); mc = getConfiguration(holder, "object-memory").memory(); assertEquals(StorageType.OBJECT, mc.storageType()); } },