diff --git a/build.xml b/build.xml
index 064d16dd39..7d1cc58b93 100644
--- a/build.xml
+++ b/build.xml
@@ -393,7 +393,7 @@
-
+
diff --git a/test/distributed/org/apache/cassandra/distributed/impl/InstanceConfig.java b/test/distributed/org/apache/cassandra/distributed/impl/InstanceConfig.java
index b71f22cebd..f4ef623950 100644
--- a/test/distributed/org/apache/cassandra/distributed/impl/InstanceConfig.java
+++ b/test/distributed/org/apache/cassandra/distributed/impl/InstanceConfig.java
@@ -19,10 +19,8 @@
package org.apache.cassandra.distributed.impl;
import java.io.File;
-import java.lang.reflect.Field;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
-import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Map;
@@ -30,15 +28,16 @@ import java.util.TreeMap;
import java.util.UUID;
import java.util.function.Function;
-import org.apache.cassandra.config.YamlConfigurationLoader;
+import com.vdurmont.semver4j.Semver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.apache.cassandra.config.YamlConfigurationLoader;
import org.apache.cassandra.distributed.api.Feature;
import org.apache.cassandra.distributed.api.IInstanceConfig;
import org.apache.cassandra.distributed.shared.NetworkTopology;
import org.apache.cassandra.distributed.shared.Shared;
-import org.apache.cassandra.distributed.shared.Versions;
+import org.apache.cassandra.distributed.upgrade.UpgradeTestBase;
import org.apache.cassandra.locator.InetAddressAndPort;
import org.apache.cassandra.locator.SimpleSeedProvider;
@@ -266,15 +265,11 @@ public class InstanceConfig implements IInstanceConfig
return datadirs;
}
- public InstanceConfig forVersion(Versions.Major major)
+ public InstanceConfig forVersion(Semver version)
{
- switch (major)
- {
- case v4: return this;
- default: return new InstanceConfig(this)
+ return new InstanceConfig(this)
.set("seed_provider", new ParameterizedClass(SimpleSeedProvider.class.getName(),
Collections.singletonMap("seeds", "127.0.0.1")));
- }
}
public String toString()
diff --git a/test/distributed/org/apache/cassandra/distributed/upgrade/MixedModeReadRepairTest.java b/test/distributed/org/apache/cassandra/distributed/upgrade/MixedModeReadRepairTest.java
index fabf172b64..549596b086 100644
--- a/test/distributed/org/apache/cassandra/distributed/upgrade/MixedModeReadRepairTest.java
+++ b/test/distributed/org/apache/cassandra/distributed/upgrade/MixedModeReadRepairTest.java
@@ -32,7 +32,7 @@ public class MixedModeReadRepairTest extends UpgradeTestBase
{
new TestCase()
.nodes(2)
- .upgrade(Versions.Major.v22, Versions.Major.v30)
+ .upgradesFrom(v22)
.setup((cluster) -> cluster.schemaChange("CREATE TABLE " + DistributedTestBase.KEYSPACE + ".tbl (pk ascii, b boolean, v blob, PRIMARY KEY (pk)) WITH COMPACT STORAGE"))
.runAfterNodeUpgrade((cluster, node) -> {
if (node != 1)
diff --git a/test/distributed/org/apache/cassandra/distributed/upgrade/PagingTest.java b/test/distributed/org/apache/cassandra/distributed/upgrade/PagingTest.java
index 1af5856806..7b958a7595 100644
--- a/test/distributed/org/apache/cassandra/distributed/upgrade/PagingTest.java
+++ b/test/distributed/org/apache/cassandra/distributed/upgrade/PagingTest.java
@@ -48,7 +48,7 @@ public class PagingTest extends UpgradeTestBase
{
new UpgradeTestBase.TestCase()
.nodes(2)
- .upgrade(Versions.Major.v22, Versions.Major.v30)
+ .upgradesFrom(v22)
.nodesToUpgrade(2)
.withConfig(config -> config.with(GOSSIP, NETWORK, NATIVE_PROTOCOL))
.setup((cluster) -> {
diff --git a/test/distributed/org/apache/cassandra/distributed/upgrade/UpgradeTest.java b/test/distributed/org/apache/cassandra/distributed/upgrade/UpgradeTest.java
index 93ae78eb24..f1a4ffd763 100644
--- a/test/distributed/org/apache/cassandra/distributed/upgrade/UpgradeTest.java
+++ b/test/distributed/org/apache/cassandra/distributed/upgrade/UpgradeTest.java
@@ -33,7 +33,7 @@ public class UpgradeTest extends UpgradeTestBase
public void upgradeTest() throws Throwable
{
new TestCase()
- .upgrade(Versions.Major.v22, Versions.Major.v30, Versions.Major.v3X)
+ .upgradesFrom(v22)
.setup((cluster) -> {
cluster.schemaChange("CREATE TABLE " + KEYSPACE + ".tbl (pk int, ck int, v int, PRIMARY KEY (pk, ck))");
diff --git a/test/distributed/org/apache/cassandra/distributed/upgrade/UpgradeTestBase.java b/test/distributed/org/apache/cassandra/distributed/upgrade/UpgradeTestBase.java
index d5404421b9..f81139dae6 100644
--- a/test/distributed/org/apache/cassandra/distributed/upgrade/UpgradeTestBase.java
+++ b/test/distributed/org/apache/cassandra/distributed/upgrade/UpgradeTestBase.java
@@ -19,12 +19,16 @@
package org.apache.cassandra.distributed.upgrade;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
+import com.google.common.collect.ImmutableList;
+import com.vdurmont.semver4j.Semver;
+import com.vdurmont.semver4j.Semver.SemverType;
+
+import com.google.common.collect.ImmutableList;
import org.junit.After;
import org.junit.BeforeClass;
@@ -34,11 +38,13 @@ import org.apache.cassandra.distributed.api.IInstanceConfig;
import org.apache.cassandra.distributed.impl.Instance;
import org.apache.cassandra.distributed.shared.DistributedTestBase;
import org.apache.cassandra.distributed.shared.Versions;
+import org.apache.cassandra.utils.ByteBufferUtil;
+import org.apache.cassandra.utils.Pair;
-import static org.apache.cassandra.distributed.shared.Versions.Major;
import static org.apache.cassandra.distributed.shared.Versions.Version;
import static org.apache.cassandra.distributed.shared.Versions.find;
+
public class UpgradeTestBase extends DistributedTestBase
{
@After
@@ -70,12 +76,19 @@ public class UpgradeTestBase extends DistributedTestBase
public void run(UpgradeableCluster cluster, int node) throws Throwable;
}
+ public static final Semver v22 = new Semver("2.2.0-beta1", SemverType.LOOSE);
+
+ protected static final List> SUPPORTED_UPGRADE_PATHS = ImmutableList.of(Pair.create(v22, v22));
+
+ // the last is always the current
+ public static final Semver CURRENT = SUPPORTED_UPGRADE_PATHS.get(SUPPORTED_UPGRADE_PATHS.size() - 1).right;
+
public static class TestVersions
{
final Version initial;
- final Version[] upgrade;
+ final Version upgrade;
- public TestVersions(Version initial, Version ... upgrade)
+ public TestVersions(Version initial, Version upgrade)
{
this.initial = initial;
this.upgrade = upgrade;
@@ -109,18 +122,29 @@ public class UpgradeTestBase extends DistributedTestBase
return this;
}
- public TestCase upgrade(Major initial, Major ... upgrade)
+ /** performs all supported upgrade paths that exist in between from and CURRENT (inclusive) **/
+ public TestCase upgradesFrom(Semver from)
{
- this.upgrade.add(new TestVersions(versions.getLatest(initial),
- Arrays.stream(upgrade)
- .map(versions::getLatest)
- .toArray(Version[]::new)));
+ return upgrades(from, CURRENT);
+ }
+
+ /** performs all supported upgrade paths that exist in between from and to (inclusive) **/
+ public TestCase upgrades(Semver from, Semver to)
+ {
+ SUPPORTED_UPGRADE_PATHS.stream()
+ .filter(upgradePath -> (upgradePath.left.compareTo(from) >= 0 && upgradePath.right.compareTo(to) <= 0))
+ .forEachOrdered(upgradePath ->
+ {
+ this.upgrade.add(
+ new TestVersions(versions.getLatest(upgradePath.left), versions.getLatest(upgradePath.right)));
+ });
return this;
}
- public TestCase upgrade(Version initial, Version ... upgrade)
+ /** Will test this specific upgrade path **/
+ public TestCase singleUpgrade(Semver from, Semver to)
{
- this.upgrade.add(new TestVersions(initial, upgrade));
+ this.upgrade.add(new TestVersions(versions.getLatest(from), versions.getLatest(to)));
return this;
}
@@ -153,7 +177,7 @@ public class UpgradeTestBase extends DistributedTestBase
if (setup == null)
throw new AssertionError();
if (upgrade.isEmpty())
- throw new AssertionError();
+ throw new AssertionError("no upgrade paths have been specified (or exist)");
if (runAfterClusterUpgrade == null && runAfterNodeUpgrade == null)
throw new AssertionError();
if (runAfterClusterUpgrade == null)
@@ -166,22 +190,20 @@ public class UpgradeTestBase extends DistributedTestBase
for (TestVersions upgrade : this.upgrade)
{
+ System.out.printf("testing upgrade from %s to %s%n", upgrade.initial.version, upgrade.upgrade.version);
try (UpgradeableCluster cluster = init(UpgradeableCluster.create(nodeCount, upgrade.initial, configConsumer)))
{
setup.run(cluster);
- for (Version version : upgrade.upgrade)
+ for (int n : nodesToUpgrade)
{
- for (int n : nodesToUpgrade)
- {
- cluster.get(n).shutdown().get();
- cluster.get(n).setVersion(version);
- cluster.get(n).startup();
- runAfterNodeUpgrade.run(cluster, n);
- }
-
- runAfterClusterUpgrade.run(cluster);
+ cluster.get(n).shutdown().get();
+ cluster.get(n).setVersion(upgrade.upgrade);
+ cluster.get(n).startup();
+ runAfterNodeUpgrade.run(cluster, n);
}
+
+ runAfterClusterUpgrade.run(cluster);
}
}
@@ -194,6 +216,13 @@ public class UpgradeTestBase extends DistributedTestBase
}
return this;
}
+ }
+
+ protected TestCase allUpgrades(int nodes, int... toUpgrade)
+ {
+ return new TestCase().nodes(nodes)
+ .upgradesFrom(v22)
+ .nodesToUpgrade(toUpgrade);
}
}
\ No newline at end of file