Skip to content

Commit

Permalink
ISPN-7584 Rolling upgrade fails with java.lang.ClassCastException
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavonalle authored and tristantarrant committed Mar 14, 2017
1 parent bae252b commit 104b188
Show file tree
Hide file tree
Showing 7 changed files with 330 additions and 166 deletions.
Expand Up @@ -32,6 +32,10 @@ public SimpleClusteredVersion(int topologyId, long version) {
this.topologyId = topologyId;
}

public long getVersion() {
return version;
}

@Override
public InequalVersionComparisonResult compareTo(EntryVersion other) {
if (other instanceof SimpleClusteredVersion) {
Expand Down
@@ -1,28 +1,12 @@
package org.infinispan.persistence.remote.upgrade;

import static org.infinispan.server.hotrod.test.HotRodTestingUtil.hotRodCacheConfiguration;
import static org.testng.AssertJUnit.assertEquals;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.infinispan.Cache;
import org.infinispan.client.hotrod.MetadataValue;
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.configuration.Configuration;
import org.infinispan.client.hotrod.test.HotRodClientTestingUtil;
import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.configuration.global.GlobalConfigurationBuilder;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.persistence.remote.configuration.RemoteStoreConfigurationBuilder;
import org.infinispan.server.hotrod.HotRodServer;
import org.infinispan.test.AbstractCacheTest;
import org.infinispan.test.AbstractInfinispanTest;
import org.infinispan.test.TestingUtil;
import org.infinispan.test.fwk.TestCacheManagerFactory;
import org.infinispan.upgrade.RollingUpgradeManager;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
Expand All @@ -31,18 +15,22 @@
@Test(testName = "upgrade.hotrod.HotRodMultiServerUpdateSynchronizerTest", groups = "functional")
public class HotRodMultiServerUpdateSynchronizerTest extends AbstractInfinispanTest {

private Cluster sourceCluster;
private Cluster targetCluster;
private TestCluster sourceCluster, targetCluster;
private static final String CACHE_NAME = HotRodMultiServerUpdateSynchronizerTest.class.getName();

@BeforeClass
public void setup() throws Exception {
sourceCluster = buildCluster("sourceCluster", 2, null);
targetCluster = buildCluster("targetCluster", 2, sourceCluster.hotRodServers.get(0).getPort());
sourceCluster = new TestCluster.Builder().setName("sourceCluster").setNumMembers(2)
.cache().name(CACHE_NAME)
.build();
targetCluster = new TestCluster.Builder().setName("targetCluster").setNumMembers(2)
.cache().name(CACHE_NAME).remotePort(sourceCluster.getHotRodPort())
.build();
}

public void testSynchronization() throws Exception {
RemoteCache<String, String> sourceRemoteCache = sourceCluster.remoteCache;
RemoteCache<String, String> targetRemoteCache = targetCluster.remoteCache;
RemoteCache<String, String> sourceRemoteCache = sourceCluster.getRemoteCache(CACHE_NAME);
RemoteCache<String, String> targetRemoteCache = targetCluster.getRemoteCache(CACHE_NAME);

for (char ch = 'A'; ch <= 'Z'; ch++) {
String s = Character.toString(ch);
Expand All @@ -52,11 +40,11 @@ public void testSynchronization() throws Exception {
// Verify access to some of the data from the new cluster
assertEquals("A", targetRemoteCache.get("A"));

RollingUpgradeManager upgradeManager = targetCluster.getRollingUpgradeManager();
RollingUpgradeManager upgradeManager = targetCluster.getRollingUpgradeManager(CACHE_NAME);
long count = upgradeManager.synchronizeData("hotrod");

assertEquals(26, count);
assertEquals(sourceCluster.cache.size(), targetCluster.cache.size());
assertEquals(sourceCluster.getEmbeddedCache(CACHE_NAME).size(), targetCluster.getEmbeddedCache(CACHE_NAME).size());

upgradeManager.disconnectSource("hotrod");

Expand All @@ -72,54 +60,4 @@ public void tearDown() {
sourceCluster.destroy();
}


private static class Cluster {
private final RemoteCache<String, String> remoteCache;
List<HotRodServer> hotRodServers;
List<EmbeddedCacheManager> embeddedCacheManagers;
RemoteCacheManager remoteCacheManager;
private final Cache<String, String> cache;

public Cluster(List<HotRodServer> hotRodServers, List<EmbeddedCacheManager> embeddedCacheManagers, RemoteCacheManager remoteCacheManager) {
this.hotRodServers = hotRodServers;
this.embeddedCacheManagers = embeddedCacheManagers;
this.remoteCacheManager = remoteCacheManager;
this.cache = embeddedCacheManagers.get(0).getCache();
this.remoteCache = remoteCacheManager.getCache();
}

private void destroy() {
embeddedCacheManagers.forEach(TestingUtil::killCacheManagers);
hotRodServers.forEach(HotRodClientTestingUtil::killServers);
HotRodClientTestingUtil.killRemoteCacheManagers(remoteCacheManager);
}

private RollingUpgradeManager getRollingUpgradeManager() {
return embeddedCacheManagers.get(0).getCache().getAdvancedCache().getComponentRegistry().getComponent(RollingUpgradeManager.class);
}

}

private Cluster buildCluster(String name, int numMembers, Integer remoteCachePort) {
List<HotRodServer> hotRodServers = new ArrayList<>();
List<EmbeddedCacheManager> embeddedCacheManagers = new ArrayList<>();
RemoteCacheManager remoteCacheManager;
for (int i = 0; i < numMembers; i++) {
GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder();
gcb.transport().defaultTransport().clusterName(name);
ConfigurationBuilder defaultClusteredCacheConfig = AbstractCacheTest.getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC);
if (remoteCachePort != null) {
defaultClusteredCacheConfig.persistence().addStore(RemoteStoreConfigurationBuilder.class).hotRodWrapping(true)
.ignoreModifications(true).addServer().host("localhost").port(remoteCachePort);
}
EmbeddedCacheManager clusteredCacheManager = TestCacheManagerFactory.createClusteredCacheManager(gcb, hotRodCacheConfiguration(defaultClusteredCacheConfig));
embeddedCacheManagers.add(clusteredCacheManager);
hotRodServers.add(HotRodClientTestingUtil.startHotRodServer(clusteredCacheManager));
}
int port = hotRodServers.get(0).getPort();
Configuration build = new org.infinispan.client.hotrod.configuration.ConfigurationBuilder().addServer().port(port).host("localhost").build();
remoteCacheManager = new RemoteCacheManager(build);
return new Cluster(hotRodServers, embeddedCacheManagers, remoteCacheManager);
}

}
@@ -1,23 +1,12 @@
package org.infinispan.persistence.remote.upgrade;

import static org.infinispan.server.hotrod.test.HotRodTestingUtil.hotRodCacheConfiguration;
import static org.infinispan.client.hotrod.ProtocolVersion.DEFAULT_PROTOCOL_VERSION;
import static org.testng.AssertJUnit.assertEquals;

import java.util.concurrent.TimeUnit;

import org.infinispan.Cache;
import org.infinispan.client.hotrod.MetadataValue;
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.test.HotRodClientTestingUtil;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.context.Flag;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.persistence.remote.configuration.RemoteStoreConfigurationBuilder;
import org.infinispan.server.hotrod.HotRodServer;
import org.infinispan.test.AbstractInfinispanTest;
import org.infinispan.test.TestingUtil;
import org.infinispan.test.fwk.TestCacheManagerFactory;
import org.infinispan.upgrade.RollingUpgradeManager;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
Expand All @@ -27,81 +16,43 @@
@Test(testName = "upgrade.hotrod.HotRodUpgradeSynchronizerTest", groups = "functional")
public class HotRodUpgradeSynchronizerTest extends AbstractInfinispanTest {

private HotRodServer sourceServer;
private HotRodServer targetServer;
private EmbeddedCacheManager sourceContainer;
private Cache<byte[], byte[]> sourceServerDefaultCache;
private Cache<byte[], byte[]> sourceServerAltCache;
private EmbeddedCacheManager targetContainer;
private Cache<byte[], byte[]> targetServerDefaultCache;
private Cache<byte[], byte[]> targetServerAltCache;
private RemoteCacheManager sourceRemoteCacheManager;
private RemoteCache<String, String> sourceRemoteDefaultCache;
private RemoteCache<String, String> sourceRemoteAltCache;
private RemoteCacheManager targetRemoteCacheManager;
private RemoteCache<String, String> targetRemoteDefaultCache;
private RemoteCache<String, String> targetRemoteAltCache;

private static final String ALT_CACHE_NAME = "whatever";
private TestCluster sourceCluster, targetCluster;

private static final String OLD_CACHE = "old-cache";
private static final String TEST_CACHE = HotRodUpgradeSynchronizerTest.class.getName();

private static final String OLD_PROTOCOL_VERSION = "2.0";
private static final String NEW_PROTOCOL_VERSION = DEFAULT_PROTOCOL_VERSION.toString();

@BeforeClass
public void setup() throws Exception {
ConfigurationBuilder serverBuilder = TestCacheManagerFactory.getDefaultCacheConfiguration(false);
sourceContainer = TestCacheManagerFactory
.createCacheManager(hotRodCacheConfiguration(serverBuilder));
sourceServerDefaultCache = sourceContainer.getCache();
sourceContainer.defineConfiguration(ALT_CACHE_NAME, sourceContainer.getDefaultCacheConfiguration());
sourceServerAltCache = sourceContainer.getCache(ALT_CACHE_NAME);
sourceServer = HotRodClientTestingUtil.startHotRodServer(sourceContainer);

ConfigurationBuilder targetConfigurationBuilder = TestCacheManagerFactory.getDefaultCacheConfiguration(false);
targetConfigurationBuilder.persistence().addStore(RemoteStoreConfigurationBuilder.class).hotRodWrapping(true)
.ignoreModifications(true).addServer().host("localhost").port(sourceServer.getPort());

ConfigurationBuilder builderOldVersion = new ConfigurationBuilder();
builderOldVersion.persistence().addStore(RemoteStoreConfigurationBuilder.class).hotRodWrapping(true)
.ignoreModifications(true).remoteCacheName(ALT_CACHE_NAME).protocolVersion(OLD_PROTOCOL_VERSION).addServer().host("localhost").port(sourceServer.getPort());

targetContainer = TestCacheManagerFactory.createCacheManager(hotRodCacheConfiguration(targetConfigurationBuilder));
targetContainer.defineConfiguration(ALT_CACHE_NAME, hotRodCacheConfiguration(builderOldVersion).build());

targetServerDefaultCache = targetContainer.getCache();
targetServerAltCache = targetContainer.getCache(ALT_CACHE_NAME);
targetServer = HotRodClientTestingUtil.startHotRodServer(targetContainer);

org.infinispan.client.hotrod.configuration.ConfigurationBuilder clientBuilderSource =
new org.infinispan.client.hotrod.configuration.ConfigurationBuilder();
clientBuilderSource.addServer().host("localhost").port(sourceServer.getPort());
sourceRemoteCacheManager = new RemoteCacheManager(clientBuilderSource.build());
sourceRemoteCacheManager.start();
sourceRemoteDefaultCache = sourceRemoteCacheManager.getCache();
sourceRemoteAltCache = sourceRemoteCacheManager.getCache(ALT_CACHE_NAME);
org.infinispan.client.hotrod.configuration.ConfigurationBuilder clientBuilderTarget =
new org.infinispan.client.hotrod.configuration.ConfigurationBuilder();
clientBuilderTarget.addServer().host("localhost").port(targetServer.getPort());
targetRemoteCacheManager = new RemoteCacheManager(clientBuilderTarget.build());
targetRemoteCacheManager.start();
targetRemoteDefaultCache = targetRemoteCacheManager.getCache();
targetRemoteAltCache = targetRemoteCacheManager.getCache(ALT_CACHE_NAME);
sourceCluster = new TestCluster.Builder().setName("sourceCluster").setNumMembers(1)
.cache().name(OLD_CACHE)
.cache().name(TEST_CACHE)
.build();

targetCluster = new TestCluster.Builder().setName("targetCluster").setNumMembers(1)
.cache().name(OLD_CACHE).remotePort(sourceCluster.getHotRodPort()).remoteProtocolVersion(OLD_PROTOCOL_VERSION)
.cache().name(TEST_CACHE).remotePort(sourceCluster.getHotRodPort()).remoteProtocolVersion(NEW_PROTOCOL_VERSION)
.build();
}

public void testSynchronizationViaIterator() throws Exception {
// Fill the old cluster with data
for (char ch = 'A'; ch <= 'Z'; ch++) {
String s = Character.toString(ch);
sourceRemoteDefaultCache.put(s, s, 20, TimeUnit.SECONDS, 30, TimeUnit.SECONDS);
sourceCluster.getRemoteCache(TEST_CACHE).put(s, s, 20, TimeUnit.SECONDS, 30, TimeUnit.SECONDS);
}
// Verify access to some of the data from the new cluster
assertEquals("A", targetRemoteDefaultCache.get("A"));
assertEquals("A", targetCluster.getRemoteCache(TEST_CACHE).get("A"));

RollingUpgradeManager targetUpgradeManager = targetServerDefaultCache.getAdvancedCache().getComponentRegistry().getComponent(RollingUpgradeManager.class);
RollingUpgradeManager targetUpgradeManager = targetCluster.getRollingUpgradeManager(TEST_CACHE);
targetUpgradeManager.synchronizeData("hotrod");
assertEquals(sourceServerDefaultCache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD).size(), targetServerDefaultCache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD).size());

targetUpgradeManager.disconnectSource("hotrod");

MetadataValue<String> metadataValue = targetRemoteDefaultCache.getWithMetadata("B");
assertEquals(sourceCluster.getRemoteCache(TEST_CACHE).size(), targetCluster.getRemoteCache(TEST_CACHE).size());

MetadataValue<String> metadataValue = targetCluster.getRemoteCache(TEST_CACHE).getWithMetadata("B");
assertEquals(20, metadataValue.getLifespan());
assertEquals(30, metadataValue.getMaxIdle());
}
Expand All @@ -110,39 +61,35 @@ public void testSynchronizationViaKeyRecording() throws Exception {
// Fill the old cluster with data
for (char ch = 'A'; ch <= 'Z'; ch++) {
String s = Character.toString(ch);
sourceRemoteAltCache.put(s, s, 20, TimeUnit.SECONDS, 30, TimeUnit.SECONDS);
sourceCluster.getRemoteCache(OLD_CACHE).put(s, s, 20, TimeUnit.SECONDS, 30, TimeUnit.SECONDS);
}
// Verify access to some of the data from the new cluster
assertEquals("A", targetRemoteAltCache.get("A"));
assertEquals("A", targetCluster.getRemoteCache(OLD_CACHE).get("A"));

RollingUpgradeManager sourceUpgradeManager = sourceServerAltCache.getAdvancedCache().getComponentRegistry().getComponent(RollingUpgradeManager.class);
sourceUpgradeManager.recordKnownGlobalKeyset();
RollingUpgradeManager targetUpgradeManager = targetServerAltCache.getAdvancedCache().getComponentRegistry().getComponent(RollingUpgradeManager.class);
targetUpgradeManager.synchronizeData("hotrod");
assertEquals(sourceServerAltCache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD).size() - 1, targetServerAltCache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD).size());
sourceCluster.getRollingUpgradeManager(OLD_CACHE).recordKnownGlobalKeyset();

RollingUpgradeManager targetUpgradeManager = targetCluster.getRollingUpgradeManager(OLD_CACHE);
targetUpgradeManager.synchronizeData("hotrod");
targetUpgradeManager.disconnectSource("hotrod");

MetadataValue<String> metadataValue = targetRemoteAltCache.getWithMetadata("A");
assertEquals(sourceCluster.getRemoteCache(OLD_CACHE).size() - 1, targetCluster.getRemoteCache(OLD_CACHE).size());

MetadataValue<String> metadataValue = targetCluster.getRemoteCache(OLD_CACHE).getWithMetadata("A");
assertEquals(20, metadataValue.getLifespan());
assertEquals(30, metadataValue.getMaxIdle());

}


@BeforeMethod
public void cleanup() {
sourceServerDefaultCache.clear();
sourceServerAltCache.clear();
targetServerDefaultCache.clear();
targetServerAltCache.clear();
sourceCluster.cleanAllCaches();
targetCluster.cleanAllCaches();
}

@AfterClass
public void tearDown() {
HotRodClientTestingUtil.killRemoteCacheManagers(sourceRemoteCacheManager, targetRemoteCacheManager);
HotRodClientTestingUtil.killServers(sourceServer, targetServer);
TestingUtil.killCacheManagers(targetContainer, sourceContainer);
sourceCluster.destroy();
targetCluster.destroy();
}

}

0 comments on commit 104b188

Please sign in to comment.