Index: client/hotrod-client/src/test/java/org/infinispan/client/hotrod/xsite/AbstractHotRodSiteFailoverTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- client/hotrod-client/src/test/java/org/infinispan/client/hotrod/xsite/AbstractHotRodSiteFailoverTest.java (revision 5b85da93ae5cb022eacf6e5b25228565d876c649) +++ client/hotrod-client/src/test/java/org/infinispan/client/hotrod/xsite/AbstractHotRodSiteFailoverTest.java (date 1636656234185) @@ -19,6 +19,7 @@ import org.infinispan.client.hotrod.test.InternalRemoteCacheManager; import org.infinispan.commons.jmx.MBeanServerLookup; import org.infinispan.commons.jmx.TestMBeanServerLookup; +import org.infinispan.commons.test.TestResourceTracker; import org.infinispan.configuration.cache.BackupConfiguration.BackupStrategy; import org.infinispan.configuration.cache.BackupConfigurationBuilder; import org.infinispan.configuration.cache.CacheMode; @@ -28,15 +29,15 @@ import org.infinispan.server.hotrod.HotRodServer; import org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder; import org.infinispan.test.TestingUtil; -import org.infinispan.commons.test.TestResourceTracker; import org.infinispan.xsite.AbstractXSiteTest; import org.testng.annotations.AfterClass; abstract class AbstractHotRodSiteFailoverTest extends AbstractXSiteTest { - static String SITE_A = "LON-1"; - static String SITE_B = "NYC-2"; - static int NODES_PER_SITE = 2; + static final String SITE_A = "LON-1"; + static final String SITE_B = "NYC-2"; + static final int NODES_PER_SITE = 2; + static final String CACHE_NAME = "testCache"; protected final MBeanServerLookup mBeanServerLookup = TestMBeanServerLookup.create(); @@ -45,15 +46,15 @@ RemoteCacheManager client(String siteName, Optional backupSiteName) { HotRodServer server = siteServers.get(siteName).get(0); org.infinispan.client.hotrod.configuration.ConfigurationBuilder clientBuilder = - HotRodClientTestingUtil.newRemoteConfigurationBuilder(); + HotRodClientTestingUtil.newRemoteConfigurationBuilder(); /* * Use 127.0.0.1 as host address to avoid the first PING after a cluster switch causing an invalidation of the * channel pools just to switch from localhost -> 127.0.0.1. This causes immediately subsequent ops to be * executed twice. */ clientBuilder - .addServer().host("127.0.0.1").port(server.getPort()) - .maxRetries(3); // Some retries so that shutdown nodes can be skipped + .addServer().host("127.0.0.1").port(server.getPort()) + .maxRetries(3); // Some retries so that shutdown nodes can be skipped clientBuilder.statistics().jmxEnable().jmxName(backupSiteName.orElse("default")).mBeanServerLookup(mBeanServerLookup); clientBuilder.asyncExecutorFactory().addExecutorProperty(ConfigurationProperties.DEFAULT_EXECUTOR_FACTORY_THREADNAME_PREFIX, TestResourceTracker.getCurrentTestShortName()); @@ -65,10 +66,10 @@ if (backupPort.isPresent()) log.debugf("Client for site '%s' connecting to main server in port %d, and backup cluster node port is %d", - siteName, server.getPort(), backupPort.get()); + siteName, server.getPort(), backupPort.get()); else log.debugf("Client for site '%s' connecting to main server in port %d", - siteName, server.getPort()); + siteName, server.getPort()); return new InternalRemoteCacheManager(clientBuilder.build()); } @@ -79,7 +80,7 @@ protected void killSite(String siteName) { log.debugf("Kill site '%s' with ports: %s", siteName, - siteServers.get(siteName).stream().map(s -> String.valueOf(s.getPort())).collect(Collectors.joining(", "))); + siteServers.get(siteName).stream().map(s -> String.valueOf(s.getPort())).collect(Collectors.joining(", "))); siteServers.get(siteName).forEach(HotRodClientTestingUtil::killServers); site(siteName).cacheManagers().forEach(TestingUtil::killCacheManagers); @@ -95,7 +96,7 @@ protected void destroy() { try { siteServers.values().forEach(servers -> - servers.forEach(HotRodClientTestingUtil::killServers)); + servers.forEach(HotRodClientTestingUtil::killServers)); siteServers.clear(); } finally { super.destroy(); @@ -104,55 +105,55 @@ protected void createHotRodSite(String siteName, String backupSiteName, Optional serverPort) { ConfigurationBuilder builder = hotRodCacheConfiguration( - getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC, false)); + getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC, false)); BackupConfigurationBuilder backup = builder.sites().addBackup(); backup.site(backupSiteName).strategy(BackupStrategy.SYNC); GlobalConfigurationBuilder globalBuilder = GlobalConfigurationBuilder.defaultClusteredBuilder(); - TestSite site = createSite(siteName, NODES_PER_SITE, globalBuilder, builder); + TestSite site = createSite(siteName, NODES_PER_SITE, globalBuilder, CACHE_NAME, builder); Collection cacheManagers = site.cacheManagers(); List servers = cacheManagers.stream().map(cm -> serverPort - .map(port -> HotRodClientTestingUtil.startHotRodServer(cm, port, new HotRodServerConfigurationBuilder())) - .orElseGet(() -> HotRodClientTestingUtil.startHotRodServer(cm, new HotRodServerConfigurationBuilder()))).collect(Collectors.toList()); + .map(port -> HotRodClientTestingUtil.startHotRodServer(cm, port, new HotRodServerConfigurationBuilder())) + .orElseGet(() -> HotRodClientTestingUtil.startHotRodServer(cm, new HotRodServerConfigurationBuilder()))).collect(Collectors.toList()); siteServers.put(siteName, servers); log.debugf("Create site '%s' with ports: %s", siteName, - servers.stream().map(s -> String.valueOf(s.getPort())).collect(Collectors.joining(", "))); + servers.stream().map(s -> String.valueOf(s.getPort())).collect(Collectors.joining(", "))); } protected void addHitCountInterceptors() { siteServers.forEach((name, servers) -> - servers.forEach(server -> { - HitCountInterceptor interceptor = new HitCountInterceptor(); - server.getCacheManager().getCache().getAdvancedCache().getAsyncInterceptorChain() - .addInterceptor(interceptor, 1); - }) + servers.forEach(server -> { + HitCountInterceptor interceptor = new HitCountInterceptor(); + server.getCacheManager().getCache(CACHE_NAME).getAdvancedCache().getAsyncInterceptorChain() + .addInterceptor(interceptor, 1); + }) ); } protected void assertNoHits() { siteServers.forEach((name, servers) -> - servers.forEach(server -> { - Cache cache = server.getCacheManager().getCache(); - HitCountInterceptor interceptor = getHitCountInterceptor(cache); - assertEquals(0, interceptor.getHits()); - }) + servers.forEach(server -> { + Cache cache = server.getCacheManager().getCache(CACHE_NAME); + HitCountInterceptor interceptor = getHitCountInterceptor(cache); + assertEquals(0, interceptor.getHits()); + }) ); } protected void resetHitCounters() { siteServers.forEach((name, servers) -> - servers.forEach(server -> { - Cache cache = server.getCacheManager().getCache(); - HitCountInterceptor interceptor = getHitCountInterceptor(cache); - interceptor.reset(); - }) + servers.forEach(server -> { + Cache cache = server.getCacheManager().getCache(CACHE_NAME); + HitCountInterceptor interceptor = getHitCountInterceptor(cache); + interceptor.reset(); + }) ); } protected void assertSiteHit(String siteName, int expectedHits) { Stream serversHit = siteServers.get(siteName).stream().filter(server -> { - Cache cache = server.getCacheManager().getCache(); + Cache cache = server.getCacheManager().getCache(CACHE_NAME); HitCountInterceptor interceptor = getHitCountInterceptor(cache); return interceptor.getHits() == expectedHits; }); @@ -161,7 +162,7 @@ protected void assertSiteNotHit(String siteName) { siteServers.get(siteName).forEach(server -> { - Cache cache = server.getCacheManager().getCache(); + Cache cache = server.getCacheManager().getCache(CACHE_NAME); HitCountInterceptor interceptor = getHitCountInterceptor(cache); assertEquals(0, interceptor.getHits()); }); Index: core/src/test/java/org/infinispan/xsite/AbstractXSiteTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- core/src/test/java/org/infinispan/xsite/AbstractXSiteTest.java (revision 5b85da93ae5cb022eacf6e5b25228565d876c649) +++ core/src/test/java/org/infinispan/xsite/AbstractXSiteTest.java (date 1636656234190) @@ -117,9 +117,15 @@ protected abstract void createSites(); - protected TestSite createSite(String siteName, int numNodes, GlobalConfigurationBuilder gcb, ConfigurationBuilder defaultCacheConfig) { + protected TestSite createSite(String siteName, int numNodes, GlobalConfigurationBuilder gcb, + ConfigurationBuilder cb) { + return createSite(siteName, numNodes, gcb, null, cb); + } + + protected TestSite createSite(String siteName, int numNodes, GlobalConfigurationBuilder gcb, + String cacheName, ConfigurationBuilder cb) { TestSite testSite = addSite(siteName); - testSite.createClusteredCaches(numNodes, null, gcb, defaultCacheConfig); + testSite.createClusteredCaches(numNodes, cacheName, gcb, cb); return testSite; } @@ -150,7 +156,7 @@ sites.forEach(site -> { site.cacheManagers.forEach(manager -> { RELAY2 relay2 = ((JGroupsTransport) manager.getTransport()).getChannel().getProtocolStack() - .findProtocol(RELAY2.class); + .findProtocol(RELAY2.class); if (!relay2.isSiteMaster()) return; while (System.nanoTime() - deadlineNanos < 0) { @@ -238,7 +244,7 @@ } protected final void assertEventuallyInSite(final String siteName, final EventuallyAssertCondition condition, - long timeout, TimeUnit timeUnit) { + long timeout, TimeUnit timeUnit) { eventually(() -> { for (Cache cache : AbstractXSiteTest.this.caches(siteName)) { if (!condition.assertInCache(cache)) { @@ -307,7 +313,13 @@ builder.read(cacheTemplate.build()); decorateCacheConfiguration(builder, siteIndex, i); - EmbeddedCacheManager cm = addClusterEnabledCacheManager(flags, gcb, builder); + + ConfigurationBuilder defaultBuilder = cacheName == null ? builder : null; + EmbeddedCacheManager cm = addClusterEnabledCacheManager(flags, gcb, defaultBuilder); + if (cacheName != null) { + cm.defineConfiguration(cacheName, builder.build()); + cm.getCache(cacheName); + } if (waitForCluster) { waitForClusterToForm(cacheName); } Index: client/hotrod-client/src/test/java/org/infinispan/client/hotrod/xsite/SiteManualSwitchTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- client/hotrod-client/src/test/java/org/infinispan/client/hotrod/xsite/SiteManualSwitchTest.java (revision 5b85da93ae5cb022eacf6e5b25228565d876c649) +++ client/hotrod-client/src/test/java/org/infinispan/client/hotrod/xsite/SiteManualSwitchTest.java (date 1636656234180) @@ -38,8 +38,8 @@ clientA = client(SITE_A, Optional.of(SITE_B)); clientB = client(SITE_B, Optional.empty()); - RemoteCache cacheA = clientA.getCache(); - RemoteCache cacheB = clientB.getCache(); + RemoteCache cacheA = clientA.getCache(CACHE_NAME); + RemoteCache cacheB = clientB.getCache(CACHE_NAME); assertNoHits(); assertSingleSiteHit(SITE_A, SITE_B, () -> assertNull(cacheA.put(1, "v1"))); @@ -56,7 +56,6 @@ assertSingleSiteHit(SITE_A, SITE_B, () -> assertEquals("v4", cacheA.get(4))); } - @Test(enabled = false) public void testManualClusterSwitchViaJMX() throws Exception { clientA = client(SITE_A, Optional.of(SITE_B)); clientB = client(SITE_B, Optional.empty()); @@ -64,8 +63,8 @@ MBeanServer mbeanServer = mBeanServerLookup.getMBeanServer(); ObjectName objectName = remoteCacheManagerObjectName(clientA); - RemoteCache cacheA = clientA.getCache(); - RemoteCache cacheB = clientB.getCache(); + RemoteCache cacheA = clientA.getCache(CACHE_NAME); + RemoteCache cacheB = clientB.getCache(CACHE_NAME); assertNoHits();