Add rolling upgrade test.
Change-Id: Id1b09361aa69f1665f19c312933798b5206d46ac
diff --git a/core/api/src/main/java/org/onosproject/core/Version.java b/core/api/src/main/java/org/onosproject/core/Version.java
index ec0ea6d..379eda2 100644
--- a/core/api/src/main/java/org/onosproject/core/Version.java
+++ b/core/api/src/main/java/org/onosproject/core/Version.java
@@ -100,8 +100,9 @@
public static Version fromInt(int version) {
int major = (version >> 24) & 0xff;
int minor = (version >> 16) & 0xff;
- int patch = (version) & 0xffff;
- return new Version(major, minor, String.valueOf(patch), null);
+ int patch = (version >> 8) & 0xff;
+ int build = version & 0xff;
+ return new Version(major, minor, String.valueOf(patch), String.valueOf(build));
}
/**
@@ -157,13 +158,30 @@
public int toInt() {
byte major = (byte) this.major;
byte minor = (byte) this.minor;
- short patch;
- try {
- patch = (short) Integer.parseInt(this.patch);
- } catch (NumberFormatException e) {
+
+ byte patch;
+ if (this.patch != null) {
+ try {
+ patch = (byte) Integer.parseInt(this.patch.replaceAll("[^0-9]", ""));
+ } catch (NumberFormatException e) {
+ patch = 0;
+ }
+ } else {
patch = 0;
}
- return major << 24 | (minor & 0xff) << 16 | (patch & 0xffff);
+
+ byte build;
+ if (this.build != null) {
+ try {
+ build = (byte) Integer.parseInt(this.build.replaceAll("[^0-9]", ""));
+ } catch (NumberFormatException e) {
+ build = 0;
+ }
+ } else {
+ build = 0;
+ }
+
+ return major << 24 | (minor & 0xff) << 16 | (patch & 0xff) << 8 | (build & 0xff);
}
@Override
diff --git a/core/api/src/test/java/org/onosproject/VersionTest.java b/core/api/src/test/java/org/onosproject/VersionTest.java
index 1c972ee..482d798 100644
--- a/core/api/src/test/java/org/onosproject/VersionTest.java
+++ b/core/api/src/test/java/org/onosproject/VersionTest.java
@@ -83,25 +83,30 @@
version1 = version("1.2");
version2 = Version.fromInt(version1.toInt());
- assertEquals(version2, version(1, 2, "0", null));
+ assertEquals(version2, version(1, 2, "0", "0"));
version1 = version("1.2.foo.bar");
version2 = Version.fromInt(version1.toInt());
- assertEquals(version2, version(1, 2, "0", null));
+ assertEquals(version2, version(1, 2, "0", "0"));
version1 = version("1.2.3");
version2 = Version.fromInt(version1.toInt());
- assertEquals(version2, version(1, 2, "3", null));
+ assertEquals(version2, version(1, 2, "3", "0"));
- version1 = version("255.254.65535.252");
+ version1 = version("1.2.3-SNAPSHOT");
version2 = Version.fromInt(version1.toInt());
- assertEquals(version2, version(255, 254, "65535", null));
+ assertEquals(version2, version(1, 2, "3", "0"));
+
+ version1 = version("255.254.253.252");
+ version2 = Version.fromInt(version1.toInt());
+ assertEquals(version2, version(255, 254, "253", "252"));
assertTrue(version("0.0.2").toInt() > version("0.0.1").toInt());
assertTrue(version("0.1.0").toInt() > version("0.0.1").toInt());
assertTrue(version("1.0.0").toInt() > version("0.1.0").toInt());
assertTrue(version("1.1.0").toInt() > version("1.0.1").toInt());
assertTrue(version("2.1.1").toInt() > version("1.10.10").toInt());
+ assertTrue(version("0.1.0-rc2").toInt() > version("0.1.0-rc1").toInt());
}
@Test
diff --git a/core/net/src/main/java/org/onosproject/upgrade/impl/UpgradeManager.java b/core/net/src/main/java/org/onosproject/upgrade/impl/UpgradeManager.java
index 218a357..3910f4b 100644
--- a/core/net/src/main/java/org/onosproject/upgrade/impl/UpgradeManager.java
+++ b/core/net/src/main/java/org/onosproject/upgrade/impl/UpgradeManager.java
@@ -105,13 +105,6 @@
Upgrade upgrade = getState();
- // If the upgrade state is not initialized, ensure this node matches the version of the cluster.
- if (!upgrade.status().active() && !Objects.equals(upgrade.source(), localVersion)) {
- log.error("Node version {} inconsistent with cluster version {}", localVersion, upgrade.source());
- throw new IllegalStateException("Node version " + localVersion +
- " inconsistent with cluster version " + upgrade.source());
- }
-
// If the upgrade state is initialized then check the node version.
if (upgrade.status() == Upgrade.Status.INITIALIZED) {
// If the source version equals the target version, attempt to update the target version.
diff --git a/core/store/primitives/src/test/java/org/onosproject/store/primitives/resources/impl/AtomixConsistentMapTest.java b/core/store/primitives/src/test/java/org/onosproject/store/primitives/resources/impl/AtomixConsistentMapTest.java
index 23f9a1f..3e7a872 100644
--- a/core/store/primitives/src/test/java/org/onosproject/store/primitives/resources/impl/AtomixConsistentMapTest.java
+++ b/core/store/primitives/src/test/java/org/onosproject/store/primitives/resources/impl/AtomixConsistentMapTest.java
@@ -19,11 +19,17 @@
import io.atomix.protocols.raft.proxy.RaftProxy;
import io.atomix.protocols.raft.service.RaftService;
import org.junit.Test;
+import org.onlab.util.HexString;
import org.onlab.util.Tools;
import org.onosproject.store.primitives.MapUpdate;
import org.onosproject.store.primitives.TransactionId;
+import org.onosproject.store.primitives.impl.CompatibleValue;
+import org.onosproject.store.primitives.impl.DistributedPrimitives;
+import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.service.AsyncConsistentMap;
import org.onosproject.store.service.MapEvent;
import org.onosproject.store.service.MapEventListener;
+import org.onosproject.store.service.Serializer;
import org.onosproject.store.service.TransactionLog;
import org.onosproject.store.service.Version;
import org.onosproject.store.service.Versioned;
@@ -584,6 +590,50 @@
assertTrue(Arrays.equals(value2, event.newValue().value()));
}
+ @Test
+ public void testCompatibilityFunction() throws Throwable {
+ AtomixConsistentMap atomixMap = newPrimitive("testCompatibilityFunction");
+
+ Serializer rawSerializer = Serializer.using(KryoNamespaces.API, CompatibleValue.class);
+ Serializer valueSerializer = Serializer.using(KryoNamespaces.BASIC);
+
+ // Convert the byte[] value to CompatibleValue<byte[]>
+ AsyncConsistentMap<String, CompatibleValue<byte[]>> rawMap = DistributedPrimitives.newTranscodingMap(
+ atomixMap,
+ key -> HexString.toHexString(rawSerializer.encode(key)),
+ string -> rawSerializer.decode(HexString.fromHexString(string)),
+ value -> value == null ? null : rawSerializer.encode(value),
+ bytes -> rawSerializer.decode(bytes));
+
+ // Convert the CompatibleValue<byte[]> value to CompatibleValue<V> using the user-provided serializer.
+ AsyncConsistentMap<String, CompatibleValue<String>> compatibleMap =
+ DistributedPrimitives.newTranscodingMap(
+ rawMap,
+ key -> key,
+ key -> key,
+ value -> value == null ? null :
+ new CompatibleValue<byte[]>(valueSerializer.encode(value.value()), value.version()),
+ value -> value == null ? null :
+ new CompatibleValue<String>(valueSerializer.decode(value.value()), value.version()));
+
+ AsyncConsistentMap<String, String> map1 = DistributedPrimitives.newCompatibleMap(
+ compatibleMap,
+ (value, version) -> version + ":" + value,
+ org.onosproject.core.Version.version("1.0.0"));
+ AsyncConsistentMap<String, String> map2 = DistributedPrimitives.newCompatibleMap(
+ compatibleMap,
+ (value, version) -> version + ":" + value,
+ org.onosproject.core.Version.version("1.0.1"));
+
+ map1.put("foo", "Hello world!").join();
+ assertEquals("Hello world!", map1.get("foo").join().value());
+ assertEquals("1.0.0:Hello world!", map2.get("foo").join().value());
+
+ map2.put("bar", "Hello world again!").join();
+ assertEquals("Hello world again!", map2.get("bar").join().value());
+ assertEquals("1.0.1:Hello world again!", map1.get("bar").join().value());
+ }
+
private static class TestMapEventListener implements MapEventListener<String, byte[]> {
private final BlockingQueue<MapEvent<String, byte[]>> queue = new ArrayBlockingQueue<>(1);