diff --git a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/MockLayoutFeature.java b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/MockLayoutFeature.java new file mode 100644 index 000000000000..64702b3bda83 --- /dev/null +++ b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/MockLayoutFeature.java @@ -0,0 +1,55 @@ +/* + * 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.hadoop.ozone.upgrade; + +import java.util.Optional; + +/** + * Mock Layout Feature list. + */ +enum MockLayoutFeature implements LayoutFeature { + VERSION_1(1), + VERSION_2(2), + VERSION_3(3); + + private int layoutVersion; + private UpgradeAction action; + + MockLayoutFeature(final int layoutVersion) { + this.layoutVersion = layoutVersion; + } + + @Override + public int layoutVersion() { + return layoutVersion; + } + + @Override + public String description() { + return null; + } + + public void addAction(UpgradeAction upgradeAction) { + this.action = upgradeAction; + } + + @Override + public Optional action() { + return Optional.ofNullable(action); + } +} diff --git a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/MockLayoutVersionManager.java b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/MockLayoutVersionManager.java new file mode 100644 index 000000000000..0cba90d99511 --- /dev/null +++ b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/MockLayoutVersionManager.java @@ -0,0 +1,28 @@ +/* + * 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.hadoop.ozone.upgrade; + +import java.io.IOException; + +class MockLayoutVersionManager extends + AbstractLayoutVersionManager { + + MockLayoutVersionManager(int lV) throws IOException { + init(lV, MockLayoutFeature.values()); + } +} diff --git a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/TestBasicUpgradeFinalizer.java b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/TestBasicUpgradeFinalizer.java index 00ac2411fe11..80aea0a3c37f 100644 --- a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/TestBasicUpgradeFinalizer.java +++ b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/TestBasicUpgradeFinalizer.java @@ -17,8 +17,8 @@ package org.apache.hadoop.ozone.upgrade; -import static org.apache.hadoop.ozone.upgrade.TestUpgradeFinalizerActions.MockLayoutFeature.VERSION_1; -import static org.apache.hadoop.ozone.upgrade.TestUpgradeFinalizerActions.MockLayoutFeature.VERSION_3; +import static org.apache.hadoop.ozone.upgrade.MockLayoutFeature.VERSION_1; +import static org.apache.hadoop.ozone.upgrade.MockLayoutFeature.VERSION_3; import static org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status.ALREADY_FINALIZED; import static org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status.FINALIZATION_DONE; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -40,7 +40,6 @@ import java.util.concurrent.Future; import org.apache.hadoop.ozone.common.Storage; import org.apache.hadoop.ozone.upgrade.InjectedUpgradeFinalizationExecutor.UpgradeTestInjectionPoints; -import org.apache.hadoop.ozone.upgrade.TestUpgradeFinalizerActions.MockLayoutVersionManager; import org.apache.hadoop.ozone.upgrade.UpgradeFinalization.StatusAndMessages; import org.junit.jupiter.api.Test; import org.mockito.InOrder; @@ -72,11 +71,11 @@ public void testFinalizerPhasesAreInvokedInOrder() throws IOException { inOrder.verify(finalizer).preFinalizeUpgrade(eq(mockObj)); inOrder.verify(finalizer).finalizeLayoutFeature( eq( - TestUpgradeFinalizerActions.MockLayoutFeature.VERSION_2), + MockLayoutFeature.VERSION_2), eq(mockObj)); inOrder.verify(finalizer).finalizeLayoutFeature( eq( - TestUpgradeFinalizerActions.MockLayoutFeature.VERSION_3), + MockLayoutFeature.VERSION_3), eq(mockObj)); inOrder.verify(finalizer).postFinalizeUpgrade(eq(mockObj)); diff --git a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/TestUpgradeFinalizerActions.java b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/TestUpgradeFinalizerActions.java deleted file mode 100644 index 02589de7d71f..000000000000 --- a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/TestUpgradeFinalizerActions.java +++ /dev/null @@ -1,109 +0,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. - */ - -package org.apache.hadoop.ozone.upgrade; - -import java.io.IOException; -import java.util.Optional; -import org.apache.hadoop.hdds.upgrade.HDDSUpgradeAction; -import org.apache.hadoop.hdds.upgrade.test.MockComponent; - -/** - * Class to test upgrade related actions. - */ -public class TestUpgradeFinalizerActions { - - /** - * Mock upgrade finalizer. - */ - static class MockUpgradeFinalizer extends - BasicUpgradeFinalizer { - - MockUpgradeFinalizer(MockLayoutVersionManager versionManager) { - super(versionManager); - } - - @Override - public void postFinalizeUpgrade(MockComponent c) { - return; - } - - @Override - public void finalizeLayoutFeature(LayoutFeature lf, MockComponent c) { - return; - } - - @Override - public void preFinalizeUpgrade(MockComponent c) { - return; - } - } - - static class MockLayoutVersionManager extends - AbstractLayoutVersionManager { - - MockLayoutVersionManager(int lV) throws IOException { - init(lV, MockLayoutFeature.values()); - } - } - - /** - * Mock Layout Feature list. - */ - enum MockLayoutFeature implements LayoutFeature { - VERSION_1(1), - VERSION_2(2), - VERSION_3(3); - - private int layoutVersion; - private UpgradeAction action; - - MockLayoutFeature(final int layoutVersion) { - this.layoutVersion = layoutVersion; - } - - @Override - public int layoutVersion() { - return layoutVersion; - } - - @Override - public String description() { - return null; - } - - public void addAction(UpgradeAction upgradeAction) { - this.action = upgradeAction; - } - - @Override - public Optional action() { - return Optional.ofNullable(action); - } - } - - /** - * Mock DN Upgrade Action that fails. - */ - public static class MockFailingUpgradeAction implements - HDDSUpgradeAction { - @Override - public void execute(MockComponent arg) throws Exception { - throw new IllegalStateException("Failed action!!"); - } - } -}