Skip to content

Commit 6c7480c

Browse files
committed
Fix UpgradeProgressTrackerIT, add UpgradeIT
1 parent fd0c41b commit 6c7480c

File tree

3 files changed

+90
-5
lines changed

3 files changed

+90
-5
lines changed

server/base/src/main/java/org/apache/accumulo/server/util/upgrade/UpgradeProgressTracker.java

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ public synchronized void continueUpgrade() {
8080
oldProgress.getUpgradeTargetVersion(), AccumuloDataVersion.get());
8181
progress = oldProgress;
8282
znodeVersion = stat.getVersion();
83+
} catch (KeeperException.NoNodeException e) {
84+
throw new IllegalStateException(
85+
"initialize not called, " + getZPath() + " node does not exist");
8386
} catch (KeeperException e) {
8487
throw new IllegalStateException("Error initializing upgrade progress", e);
8588
} catch (InterruptedException e) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.accumulo.test.upgrade;
20+
21+
import static org.junit.jupiter.api.Assertions.assertThrows;
22+
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
24+
25+
import java.time.Duration;
26+
27+
import org.apache.accumulo.core.Constants;
28+
import org.apache.accumulo.core.fate.zookeeper.ZooReader;
29+
import org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter;
30+
import org.apache.accumulo.core.fate.zookeeper.ZooUtil.NodeExistsPolicy;
31+
import org.apache.accumulo.core.zookeeper.ZooSession;
32+
import org.apache.accumulo.harness.AccumuloClusterHarness;
33+
import org.junit.jupiter.api.Test;
34+
35+
public class UpgradeIT extends AccumuloClusterHarness {
36+
37+
@Override
38+
protected Duration defaultTimeout() {
39+
return Duration.ofMinutes(5);
40+
}
41+
42+
@Test
43+
public void testServersWontStart() throws Exception {
44+
// Constants.ZPREPARE_FOR_UPGRADE is created by 'ZooZap -prepare-for-upgrade'
45+
// which is run when the user wants to shutdown an instance in preparation
46+
// to upgrade it. When this node exists, no servers should start. There is
47+
// no ability to create this node in ZooKeeper before MAC starts for this
48+
// test, so we will create the node after MAC starts, then try to restart
49+
// MAC.
50+
51+
final ZooSession zs = getServerContext().getZooSession();
52+
final String zkRoot = getServerContext().getZooKeeperRoot();
53+
final ZooReaderWriter zrw = zs.asReaderWriter();
54+
final String upgradePath = zkRoot + Constants.ZPREPARE_FOR_UPGRADE;
55+
zrw.putPersistentData(upgradePath, new byte[0], NodeExistsPolicy.SKIP);
56+
57+
getCluster().stop();
58+
59+
assertThrows(AssertionError.class,
60+
() -> assertTimeoutPreemptively(Duration.ofMinutes(2), () -> getCluster().start()));
61+
62+
final ZooReader zr = zs.asReader();
63+
assertTrue(zr.getChildren(zkRoot + Constants.ZCOMPACTORS).isEmpty());
64+
assertTrue(zr.getChildren(zkRoot + Constants.ZCOORDINATOR_LOCK).isEmpty());
65+
assertTrue(zr.getChildren(zkRoot + Constants.ZGC_LOCK).isEmpty());
66+
assertTrue(zr.getChildren(zkRoot + Constants.ZMANAGER_LOCK).isEmpty());
67+
assertTrue(zr.getChildren(zkRoot + Constants.ZSSERVERS).isEmpty());
68+
assertTrue(zr.getChildren(zkRoot + Constants.ZTSERVERS).isEmpty());
69+
}
70+
71+
}

test/src/main/java/org/apache/accumulo/test/upgrade/UpgradeProgressTrackerIT.java

+16-5
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,16 @@ public void testUpgradeAlreadyStarted() throws KeeperException, InterruptedExcep
143143
assertTrue(ise.getMessage()
144144
.startsWith("Upgrade was already started with a different version of software"));
145145
var npe = assertThrows(NullPointerException.class, () -> progressTracker.getProgress());
146-
assertEquals("Must call startOrContinueUpgrade() before checking the progress",
147-
npe.getMessage());
146+
assertEquals("Must call continueUpgrade() before checking the progress", npe.getMessage());
147+
}
148+
149+
@Test
150+
public void testInitializationNotDone() throws KeeperException, InterruptedException {
151+
expectVersion(AccumuloDataVersion.get());
152+
assertFalse(upgradeNodeExists());
153+
IllegalStateException ise =
154+
assertThrows(IllegalStateException.class, () -> progressTracker.continueUpgrade());
155+
assertTrue(ise.getMessage().startsWith("initialize not called,"));
148156
}
149157

150158
@Test
@@ -153,8 +161,9 @@ public void testGetInitial() throws KeeperException, InterruptedException {
153161
assertFalse(upgradeNodeExists());
154162
assertThrows(NullPointerException.class, () -> progressTracker.getProgress());
155163
assertFalse(upgradeNodeExists());
156-
progressTracker.continueUpgrade();
164+
progressTracker.initialize();
157165
assertTrue(upgradeNodeExists());
166+
progressTracker.continueUpgrade();
158167
final var progress = progressTracker.getProgress();
159168
assertNotNull(progress);
160169
assertEquals(AccumuloDataVersion.get(), progress.getZooKeeperVersion());
@@ -168,8 +177,9 @@ public void testGetInitial() throws KeeperException, InterruptedException {
168177
public void testUpdates() throws KeeperException, InterruptedException {
169178
expectVersion(AccumuloDataVersion.get() - 1);
170179
assertFalse(upgradeNodeExists());
171-
progressTracker.continueUpgrade();
180+
progressTracker.initialize();
172181
assertTrue(upgradeNodeExists());
182+
progressTracker.continueUpgrade();
173183
final var progress = progressTracker.getProgress();
174184
assertNotNull(progress);
175185
assertEquals(AccumuloDataVersion.get() - 1, progress.getZooKeeperVersion());
@@ -224,8 +234,9 @@ public void testUpdates() throws KeeperException, InterruptedException {
224234
public void testCompleteUpgrade() throws KeeperException, InterruptedException {
225235
expectVersion(AccumuloDataVersion.get());
226236
assertFalse(upgradeNodeExists());
227-
progressTracker.continueUpgrade();
237+
progressTracker.initialize();
228238
assertTrue(upgradeNodeExists());
239+
progressTracker.continueUpgrade();
229240
final var progress = progressTracker.getProgress();
230241
assertNotNull(progress);
231242
assertEquals(AccumuloDataVersion.get(), progress.getZooKeeperVersion());

0 commit comments

Comments
 (0)