|
| 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 | + * <p> |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * <p> |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package org.apache.hadoop.fs.viewfs; |
| 19 | + |
| 20 | +import org.apache.hadoop.conf.Configuration; |
| 21 | +import org.apache.hadoop.fs.CommonConfigurationKeysPublic; |
| 22 | +import org.apache.hadoop.fs.FsConstants; |
| 23 | +import org.apache.hadoop.hdfs.DFSConfigKeys; |
| 24 | +import org.apache.hadoop.hdfs.DistributedFileSystem; |
| 25 | +import org.apache.hadoop.hdfs.MiniDFSCluster; |
| 26 | +import org.apache.hadoop.hdfs.MiniDFSNNTopology; |
| 27 | +import org.junit.After; |
| 28 | +import org.junit.BeforeClass; |
| 29 | +import org.junit.Test; |
| 30 | + |
| 31 | +/** |
| 32 | + * Tests that the NN startup is successful with ViewFSOverloadScheme. |
| 33 | + */ |
| 34 | +public class TestNNStartupWhenViewFSOverloadSchemeEnabled { |
| 35 | + private MiniDFSCluster cluster; |
| 36 | + private static final String FS_IMPL_PATTERN_KEY = "fs.%s.impl"; |
| 37 | + private static final String HDFS_SCHEME = "hdfs"; |
| 38 | + private static final Configuration CONF = new Configuration(); |
| 39 | + |
| 40 | + @BeforeClass |
| 41 | + public static void setUp() { |
| 42 | + CONF.setInt(DFSConfigKeys.DFS_HEARTBEAT_INTERVAL_KEY, 1); |
| 43 | + CONF.setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1); |
| 44 | + CONF.setInt( |
| 45 | + CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 1); |
| 46 | + CONF.set(String.format(FS_IMPL_PATTERN_KEY, HDFS_SCHEME), |
| 47 | + ViewFileSystemOverloadScheme.class.getName()); |
| 48 | + CONF.set(String |
| 49 | + .format(FsConstants.FS_VIEWFS_OVERLOAD_SCHEME_TARGET_FS_IMPL_PATTERN, |
| 50 | + HDFS_SCHEME), DistributedFileSystem.class.getName()); |
| 51 | + // By default trash interval is 0. To trigger TrashEmptier, let's set it to |
| 52 | + // >0 value. |
| 53 | + CONF.setLong(CommonConfigurationKeysPublic.FS_TRASH_INTERVAL_KEY, 100); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Tests that the HA mode NameNode startup is successful when |
| 58 | + * ViewFSOverloadScheme configured. |
| 59 | + */ |
| 60 | + @Test(timeout = 30000) |
| 61 | + public void testHANameNodeAndDataNodeStartup() throws Exception { |
| 62 | + cluster = new MiniDFSCluster.Builder(CONF) |
| 63 | + .nnTopology(MiniDFSNNTopology.simpleHATopology()).numDataNodes(1) |
| 64 | + .waitSafeMode(false).build(); |
| 65 | + cluster.waitActive(); |
| 66 | + cluster.transitionToActive(0); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Tests that the NameNode startup is successful when ViewFSOverloadScheme |
| 71 | + * configured. |
| 72 | + */ |
| 73 | + @Test(timeout = 30000) |
| 74 | + public void testNameNodeAndDataNodeStartup() throws Exception { |
| 75 | + cluster = |
| 76 | + new MiniDFSCluster.Builder(CONF).numDataNodes(1).waitSafeMode(false) |
| 77 | + .build(); |
| 78 | + cluster.waitActive(); |
| 79 | + } |
| 80 | + |
| 81 | + @After |
| 82 | + public void shutdownCluster() { |
| 83 | + if (cluster != null) { |
| 84 | + cluster.shutdown(); |
| 85 | + cluster = null; |
| 86 | + } |
| 87 | + } |
| 88 | +} |
0 commit comments