|
| 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.assertEquals; |
| 22 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 23 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 24 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 25 | + |
| 26 | +import java.util.UUID; |
| 27 | + |
| 28 | +import org.apache.accumulo.core.Constants; |
| 29 | +import org.apache.accumulo.core.fate.zookeeper.ZooUtil.NodeExistsPolicy; |
| 30 | +import org.apache.accumulo.harness.AccumuloClusterHarness; |
| 31 | +import org.apache.accumulo.minicluster.ServerType; |
| 32 | +import org.apache.accumulo.server.ServerContext; |
| 33 | +import org.apache.accumulo.server.util.UpgradeUtil; |
| 34 | +import org.apache.accumulo.test.util.Wait; |
| 35 | +import org.junit.jupiter.api.Test; |
| 36 | + |
| 37 | +public class UpgradeUtilIT extends AccumuloClusterHarness { |
| 38 | + |
| 39 | + @Test |
| 40 | + public void testPrepareFailsDueToManagerUp() throws Exception { |
| 41 | + ServerContext ctx = getCluster().getServerContext(); |
| 42 | + |
| 43 | + ctx.getZooReaderWriter().putPersistentData( |
| 44 | + ctx.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE, new byte[0], |
| 45 | + NodeExistsPolicy.SKIP); |
| 46 | + assertTrue(ctx.getZooReader().exists(ctx.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE)); |
| 47 | + |
| 48 | + System.setProperty("accumulo.properties", "file://" + getCluster().getAccumuloPropertiesPath()); |
| 49 | + IllegalStateException ise = assertThrows(IllegalStateException.class, |
| 50 | + () -> new UpgradeUtil().execute(new String[] {"--prepare"})); |
| 51 | + assertEquals("Manager is running, shut it down and retry this operation", ise.getMessage()); |
| 52 | + assertFalse(ctx.getZooReader().exists(ctx.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE)); |
| 53 | + |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void testPrepareFailsDueToFateTransactions() throws Exception { |
| 58 | + ServerContext ctx = getCluster().getServerContext(); |
| 59 | + |
| 60 | + ctx.getZooReaderWriter().putPersistentData( |
| 61 | + ctx.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE, new byte[0], |
| 62 | + NodeExistsPolicy.SKIP); |
| 63 | + assertTrue(ctx.getZooReader().exists(ctx.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE)); |
| 64 | + |
| 65 | + assertTrue(ctx.getZooReader().getChildren(ctx.getZooKeeperRoot() + Constants.ZFATE).isEmpty()); |
| 66 | + ctx.getZooReaderWriter().putEphemeralData( |
| 67 | + ctx.getZooKeeperRoot() + Constants.ZFATE + "/" + UUID.randomUUID(), new byte[0]); |
| 68 | + assertFalse(ctx.getZooReader().getChildren(ctx.getZooKeeperRoot() + Constants.ZFATE).isEmpty()); |
| 69 | + |
| 70 | + getCluster().getClusterControl().stopAllServers(ServerType.MANAGER); |
| 71 | + Wait.waitFor(() -> ctx.getZooReader() |
| 72 | + .getChildren(ctx.getZooKeeperRoot() + Constants.ZMANAGER_LOCK).isEmpty()); |
| 73 | + |
| 74 | + System.setProperty("accumulo.properties", "file://" + getCluster().getAccumuloPropertiesPath()); |
| 75 | + IllegalStateException ise = assertThrows(IllegalStateException.class, |
| 76 | + () -> new UpgradeUtil().execute(new String[] {"--prepare"})); |
| 77 | + assertTrue(ise.getMessage() |
| 78 | + .startsWith("Cannot complete upgrade preparation because FATE transactions exist.")); |
| 79 | + assertFalse(ctx.getZooReader().exists(ctx.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE)); |
| 80 | + |
| 81 | + } |
| 82 | + |
| 83 | + @Test |
| 84 | + public void testPrepareSucceeds() throws Exception { |
| 85 | + ServerContext ctx = getCluster().getServerContext(); |
| 86 | + |
| 87 | + ctx.getZooReaderWriter().putPersistentData( |
| 88 | + ctx.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE, new byte[0], |
| 89 | + NodeExistsPolicy.SKIP); |
| 90 | + assertTrue(ctx.getZooReader().exists(ctx.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE)); |
| 91 | + |
| 92 | + getCluster().getClusterControl().stopAllServers(ServerType.MANAGER); |
| 93 | + Wait.waitFor(() -> ctx.getZooReader() |
| 94 | + .getChildren(ctx.getZooKeeperRoot() + Constants.ZMANAGER_LOCK).isEmpty()); |
| 95 | + |
| 96 | + System.setProperty("accumulo.properties", "file://" + getCluster().getAccumuloPropertiesPath()); |
| 97 | + new UpgradeUtil().execute(new String[] {"--prepare"}); |
| 98 | + assertTrue(ctx.getZooReader().exists(ctx.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE)); |
| 99 | + |
| 100 | + } |
| 101 | + |
| 102 | +} |
0 commit comments