sijie closed pull request #1028: Test upgrade from old server version to new 
version
URL: https://github.com/apache/bookkeeper/pull/1028
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/tests/backward-compat-upgrade-direct/pom.xml 
b/tests/backward-compat-upgrade-direct/pom.xml
new file mode 100644
index 000000000..8749975af
--- /dev/null
+++ b/tests/backward-compat-upgrade-direct/pom.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="
+  http://maven.apache.org/POM/4.0.0
+  http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.bookkeeper.tests</groupId>
+    <artifactId>integration-tests-base-groovy</artifactId>
+    <version>4.7.0-SNAPSHOT</version>
+    <relativePath>../integration-tests-base-groovy</relativePath>
+  </parent>
+
+  <groupId>org.apache.bookkeeper.tests</groupId>
+  <artifactId>backward-compat-upgrade-direct</artifactId>
+  <packaging>jar</packaging>
+  <name>Apache BookKeeper :: Tests :: Test upgrade between 4.1.0 and current 
version</name>
+
+</project>
diff --git 
a/tests/backward-compat-upgrade-direct/src/test/groovy/org/apache/bookkeeper/tests/TestCompatUpgradeDirect.groovy
 
b/tests/backward-compat-upgrade-direct/src/test/groovy/org/apache/bookkeeper/tests/TestCompatUpgradeDirect.groovy
new file mode 100644
index 000000000..cc32991de
--- /dev/null
+++ 
b/tests/backward-compat-upgrade-direct/src/test/groovy/org/apache/bookkeeper/tests/TestCompatUpgradeDirect.groovy
@@ -0,0 +1,123 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.bookkeeper.tests
+
+import com.github.dockerjava.api.DockerClient
+
+import org.jboss.arquillian.junit.Arquillian
+import org.jboss.arquillian.test.api.ArquillianResource
+
+import org.junit.Assert
+import org.junit.FixMethodOrder
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.MethodSorters
+
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+@RunWith(Arquillian.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+class TestCompatUpgradeDirect {
+    private static final Logger LOG = 
LoggerFactory.getLogger(TestCompatUpgradeDirect.class)
+    private static byte[] PASSWD = "foobar".getBytes()
+
+    @ArquillianResource
+    DockerClient docker
+
+    @Test
+    public void test0_upgradeDirect410toCurrent() throws Exception {
+        BookKeeperClusterUtils.legacyMetadataFormat(docker)
+        String zookeeper = 
BookKeeperClusterUtils.zookeeperConnectString(docker)
+        String currentVersion = System.getProperty("currentVersion")
+        int numEntries = 10
+
+        
Assert.assertTrue(BookKeeperClusterUtils.startAllBookiesWithVersion(docker, 
"4.1.0"))
+        def v410CL = MavenClassLoader.forBookKeeperVersion("4.1.0")
+        def v410BK = v410CL.newBookKeeper(zookeeper)
+
+        def ledger0 = v410BK.createLedger(3, 2,
+                                          v410CL.digestType("CRC32"),
+                                          PASSWD)
+        for (int i = 0; i < numEntries; i++) {
+            ledger0.addEntry(("foobar" + i).getBytes())
+        }
+        ledger0.close()
+
+        // Current client shouldn't be able to write to 4.1.0 server
+        def currentCL = MavenClassLoader.forBookKeeperVersion(currentVersion)
+        def currentBK = currentCL.newBookKeeper(zookeeper)
+        def ledger1 = currentBK.createLedger(3, 2, 
currentCL.digestType("CRC32"), PASSWD)
+        try {
+            ledger1.addEntry("foobar".getBytes())
+
+            Assert.fail("Shouldn't have been able to write")
+        } catch (Exception e) {
+            // correct behaviour
+        }
+
+        Assert.assertTrue(BookKeeperClusterUtils.stopAllBookies(docker))
+        
Assert.assertTrue(BookKeeperClusterUtils.startAllBookiesWithVersion(docker, 
currentVersion))
+
+        // check that old client can read its old ledgers on new server
+        def ledger2 = v410BK.openLedger(ledger0.getId(), 
v410CL.digestType("CRC32"), PASSWD)
+        Assert.assertEquals(numEntries, ledger2.getLastAddConfirmed() + 1 /* 
counts from 0 */)
+        def entries = ledger2.readEntries(0, ledger2.getLastAddConfirmed())
+        int j = 0
+        while (entries.hasMoreElements()) {
+            def e = entries.nextElement()
+            Assert.assertEquals(new String(e.getEntry()), "foobar"+ j)
+            j++
+        }
+        ledger2.close()
+
+        v410BK.close()
+        currentBK.close()
+    }
+
+    @Test
+    public void test1_v410ClientCantFenceLedgerFromCurrent() throws Exception {
+        String currentVersion = System.getProperty("currentVersion")
+        String zookeeper = 
BookKeeperClusterUtils.zookeeperConnectString(docker)
+
+        def currentCL = MavenClassLoader.forBookKeeperVersion(currentVersion)
+        def currentBK = currentCL.newBookKeeper(zookeeper)
+
+        def numEntries = 5
+        def ledger0 = currentBK.createLedger(3, 2,
+                                             currentCL.digestType("CRC32"),
+                                             PASSWD)
+        for (int i = 0; i < numEntries; i++) {
+            ledger0.addEntry(("foobar" + i).getBytes())
+        }
+        ledger0.close()
+
+        def v410CL = MavenClassLoader.forBookKeeperVersion("4.1.0")
+        def v410BK = v410CL.newBookKeeper(zookeeper)
+
+        try {
+            def ledger1 = v410BK.openLedger(ledger0.getId(), 
v410CL.digestType("CRC32"), PASSWD)
+            Assert.fail("Shouldn't have been able to open")
+        } catch (Exception e) {
+            // correct behaviour
+        }
+
+        currentBK.close()
+        v410BK.close()
+    }
+}
diff --git 
a/tests/backward-compat-upgrade-direct/src/test/resources/arquillian.xml 
b/tests/backward-compat-upgrade-direct/src/test/resources/arquillian.xml
new file mode 100644
index 000000000..f914ff2c2
--- /dev/null
+++ b/tests/backward-compat-upgrade-direct/src/test/resources/arquillian.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+            xmlns="http://jboss.org/schema/arquillian";
+            xsi:schemaLocation="http://jboss.org/schema/arquillian
+                                
http://jboss.org/schema/arquillian/arquillian_1_0.xsd";>
+
+  <extension qualifier="docker">
+    <property name="definitionFormat">CUBE</property>
+    <property 
name="dockerContainersResource">cube-definitions/3-node-all-version-unstarted.yaml</property>
+  </extension>
+
+</arquillian>
diff --git a/tests/backward-compat-upgrade/pom.xml 
b/tests/backward-compat-upgrade/pom.xml
new file mode 100644
index 000000000..9e9f4f700
--- /dev/null
+++ b/tests/backward-compat-upgrade/pom.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="
+  http://maven.apache.org/POM/4.0.0
+  http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.bookkeeper.tests</groupId>
+    <artifactId>integration-tests-base-groovy</artifactId>
+    <version>4.7.0-SNAPSHOT</version>
+    <relativePath>../integration-tests-base-groovy</relativePath>
+  </parent>
+
+  <groupId>org.apache.bookkeeper.tests</groupId>
+  <artifactId>backward-compat-upgrade</artifactId>
+  <packaging>jar</packaging>
+  <name>Apache BookKeeper :: Tests :: Test upgrade between all released 
versions and current version</name>
+
+</project>
diff --git 
a/tests/backward-compat-upgrade/src/test/groovy/org/apache/bookkeeper/tests/TestCompatUpgrade.groovy
 
b/tests/backward-compat-upgrade/src/test/groovy/org/apache/bookkeeper/tests/TestCompatUpgrade.groovy
new file mode 100644
index 000000000..911afb8a1
--- /dev/null
+++ 
b/tests/backward-compat-upgrade/src/test/groovy/org/apache/bookkeeper/tests/TestCompatUpgrade.groovy
@@ -0,0 +1,165 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.bookkeeper.tests
+
+import com.github.dockerjava.api.DockerClient
+
+import org.jboss.arquillian.junit.Arquillian
+import org.jboss.arquillian.test.api.ArquillianResource
+
+import org.junit.Assert
+import org.junit.FixMethodOrder
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.MethodSorters
+
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+@RunWith(Arquillian.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+class TestCompatUpgrade {
+    private static final Logger LOG = 
LoggerFactory.getLogger(TestCompatUpgrade.class)
+    private static byte[] PASSWD = "foobar".getBytes()
+
+    @ArquillianResource
+    DockerClient docker
+
+    private void testUpgrade(String currentlyRunning, String upgradeTo, 
boolean clientCompatBroken = false) {
+        String zookeeper = 
BookKeeperClusterUtils.zookeeperConnectString(docker)
+        LOG.info("Upgrading from {} to {}", currentlyRunning, upgradeTo)
+        int numEntries = 10
+        def currentRunningCL = 
MavenClassLoader.forBookKeeperVersion(currentlyRunning)
+
+        def currentRunningBK = currentRunningCL.newBookKeeper(zookeeper)
+
+        def ledger0 = currentRunningBK.createLedger(3, 2,
+                                                    
currentRunningCL.digestType("CRC32"),
+                                                    PASSWD)
+        for (int i = 0; i < numEntries; i++) {
+            ledger0.addEntry(("foobar" + i).getBytes())
+        }
+        ledger0.close()
+
+        // Check whether current client can write to old server
+        def upgradedCL = MavenClassLoader.forBookKeeperVersion(upgradeTo)
+        def upgradedBK = upgradedCL.newBookKeeper(zookeeper)
+        def ledger1 = upgradedBK.createLedger(3, 2, 
upgradedCL.digestType("CRC32"), PASSWD)
+        try {
+            ledger1.addEntry("foobar".getBytes())
+
+            if (clientCompatBroken) {
+                Assert.fail("Shouldn't have been able to write")
+            }
+        } catch (Exception e) {
+            if (!clientCompatBroken) {
+                throw e;
+            }
+        }
+
+        Assert.assertTrue(BookKeeperClusterUtils.stopAllBookies(docker))
+        
Assert.assertTrue(BookKeeperClusterUtils.startAllBookiesWithVersion(docker, 
upgradeTo))
+
+        // check that old client can read its old ledgers on new server
+        def ledger2 = currentRunningBK.openLedger(ledger0.getId(), 
currentRunningCL.digestType("CRC32"),
+                                                  PASSWD)
+        Assert.assertEquals(numEntries, ledger2.getLastAddConfirmed() + 1 /* 
counts from 0 */)
+        def entries = ledger2.readEntries(0, ledger2.getLastAddConfirmed())
+        int j = 0
+        while (entries.hasMoreElements()) {
+            def e = entries.nextElement()
+            Assert.assertEquals(new String(e.getEntry()), "foobar"+ j)
+            j++
+        }
+        ledger2.close()
+
+        currentRunningBK.close()
+        upgradedBK.close()
+    }
+
+    @Test
+    public void test0() throws Exception {
+        BookKeeperClusterUtils.legacyMetadataFormat(docker)
+        
Assert.assertTrue(BookKeeperClusterUtils.startAllBookiesWithVersion(docker, 
"4.1.0"))
+    }
+
+    @Test
+    public void test410to420() throws Exception {
+        testUpgrade("4.1.0", "4.2.0")
+    }
+
+    @Test
+    public void test420to421() throws Exception {
+        testUpgrade("4.2.0", "4.2.1")
+    }
+
+    @Test
+    public void test421to422() throws Exception {
+        testUpgrade("4.2.1", "4.2.2")
+    }
+
+    @Test
+    public void test422to423() throws Exception {
+        testUpgrade("4.2.2", "4.2.3")
+    }
+
+    @Test
+    public void test423to424() throws Exception {
+        testUpgrade("4.2.3", "4.2.4")
+    }
+
+    @Test
+    public void test424to430() throws Exception {
+        testUpgrade("4.2.4", "4.3.0", true)
+    }
+
+    @Test
+    public void test430to431() throws Exception {
+        testUpgrade("4.3.0", "4.3.1")
+    }
+
+    @Test
+    public void test431to432() throws Exception {
+        testUpgrade("4.3.1", "4.3.2")
+    }
+
+    @Test
+    public void test432to440() throws Exception {
+        testUpgrade("4.3.2", "4.4.0")
+    }
+
+    @Test
+    public void test440to450() throws Exception {
+        testUpgrade("4.4.0", "4.5.0")
+    }
+
+    @Test
+    public void test450to451() throws Exception {
+        testUpgrade("4.5.0", "4.5.1")
+    }
+
+    @Test
+    public void test451to460() throws Exception {
+        testUpgrade("4.5.1", "4.6.0")
+    }
+
+    @Test
+    public void test460toCurrentMaster() throws Exception {
+        testUpgrade("4.6.0", System.getProperty("currentVersion"))
+    }
+}
diff --git a/tests/backward-compat-upgrade/src/test/resources/arquillian.xml 
b/tests/backward-compat-upgrade/src/test/resources/arquillian.xml
new file mode 100644
index 000000000..f914ff2c2
--- /dev/null
+++ b/tests/backward-compat-upgrade/src/test/resources/arquillian.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+            xmlns="http://jboss.org/schema/arquillian";
+            xsi:schemaLocation="http://jboss.org/schema/arquillian
+                                
http://jboss.org/schema/arquillian/arquillian_1_0.xsd";>
+
+  <extension qualifier="docker">
+    <property name="definitionFormat">CUBE</property>
+    <property 
name="dockerContainersResource">cube-definitions/3-node-all-version-unstarted.yaml</property>
+  </extension>
+
+</arquillian>
diff --git 
a/tests/backward/src/test/java/org/apache/bookkeeper/tests/backward/TestBackwardCompat.java
 
b/tests/backward/src/test/java/org/apache/bookkeeper/tests/backward/TestBackwardCompat.java
index c6a904e21..cd8fd5a5f 100644
--- 
a/tests/backward/src/test/java/org/apache/bookkeeper/tests/backward/TestBackwardCompat.java
+++ 
b/tests/backward/src/test/java/org/apache/bookkeeper/tests/backward/TestBackwardCompat.java
@@ -439,125 +439,6 @@ public void testOldCookieAccessingNewCluster() throws 
Exception {
         }
     }
 
-    /**
-     * Test compatability between version 4.1.0 and the current version.
-     *  - A 4.1.0 client is not able to open a ledger created by the current
-     *    version due to a change in the ledger metadata format.
-     *  - Otherwise, they should be compatible.
-     */
-    @Test
-    public void testCompat410() throws Exception {
-        File journalDir = createTempDir("bookie", "journal");
-        File ledgerDir = createTempDir("bookie", "ledger");
-
-        int port = PortManager.nextFreePort();
-        // start server, upgrade
-        Server410 s410 = new Server410(journalDir, ledgerDir, port);
-        s410.start();
-
-        Ledger410 l410 = Ledger410.newLedger();
-        l410.write100();
-        long oldLedgerId = l410.getId();
-        l410.close();
-
-        // Check that current client can to write to old server
-        LedgerCurrent lcur = LedgerCurrent.newLedger();
-        try {
-            lcur.write100();
-            fail("Shouldn't be able to write");
-        } catch (Exception e) {
-            // correct behaviour
-        }
-        lcur.close();
-
-        s410.stop();
-
-        // Start the current server, will not require a filesystem upgrade
-        ServerCurrent scur = new ServerCurrent(journalDir, ledgerDir, port, 
false);
-        scur.start();
-
-        // check that old client can read its old ledgers on new server
-        l410 = Ledger410.openLedger(oldLedgerId);
-        assertEquals(100, l410.readAll());
-        l410.close();
-
-        // check that old client can create ledgers on new server
-        l410 = Ledger410.newLedger();
-        l410.write100();
-        l410.close();
-
-        // check that an old client can fence an old client
-        l410 = Ledger410.newLedger();
-        l410.write100();
-
-        Ledger410 l410f = Ledger410.openLedger(l410.getId());
-        try {
-            l410.write100();
-            fail("Shouldn't be able to write");
-        } catch (Exception e) {
-            // correct behaviour
-        }
-        l410f.close();
-        try {
-            l410.close();
-            fail("Shouldn't be able to close");
-        } catch (Exception e) {
-            // correct
-        }
-
-        // check that a new client can fence an old client
-        // and the old client can continue to read that ledger
-        l410 = Ledger410.newLedger();
-        l410.write100();
-
-        oldLedgerId = l410.getId();
-        lcur = LedgerCurrent.openLedger(oldLedgerId);
-        try {
-            l410.write100();
-            fail("Shouldn't be able to write");
-        } catch (Exception e) {
-            // correct behaviour
-        }
-        try {
-            l410.close();
-            fail("Shouldn't be able to close");
-        } catch (Exception e) {
-            // correct
-        }
-        lcur.close();
-
-        l410 = Ledger410.openLedger(oldLedgerId);
-
-        assertEquals(100, l410.readAll());
-        l410.close();
-
-        // check that current client can read old ledger
-        lcur = LedgerCurrent.openLedger(oldLedgerId);
-        assertEquals(100, lcur.readAll());
-        lcur.close();
-
-        // check that old client can read current client's ledgers
-        lcur = LedgerCurrent.openLedger(oldLedgerId);
-        assertEquals(100, lcur.readAll());
-        lcur.close();
-
-        // check that old client can not fence a current client
-        // since it cannot open a new ledger due to the format changes
-        lcur = LedgerCurrent.newLedger();
-        lcur.write100();
-        long fenceLedgerId = lcur.getId();
-        try {
-            l410 = Ledger410.openLedger(fenceLedgerId);
-            fail("Shouldn't be able to open ledger");
-        } catch (Exception e) {
-            // correct behaviour
-        }
-        lcur.write100();
-        lcur.close();
-
-        scur.stop();
-    }
-
     /**
      * Test compatability between old versions and the current version.
      * - old server restarts with useHostNameAsBookieID=true.
diff --git a/tests/pom.xml b/tests/pom.xml
index daa2fc758..4d639f70d 100644
--- a/tests/pom.xml
+++ b/tests/pom.xml
@@ -40,6 +40,8 @@
     <module>integration-tests-base-groovy</module>
     <module>integration-tests-utils</module>
     <module>integration-tests-topologies</module>
+    <module>backward-compat-upgrade</module>
+    <module>backward-compat-upgrade-direct</module>
   </modules>
   <build>
     <plugins>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to