|
| 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 | +} |
0 commit comments