|
| 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 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 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 | + |
| 19 | +package org.apache.hadoop.hdfs.server.federation.router; |
| 20 | + |
| 21 | +import org.apache.hadoop.conf.Configuration; |
| 22 | +import org.apache.hadoop.hdfs.HdfsConfiguration; |
| 23 | +import org.apache.hadoop.hdfs.server.federation.MockResolver; |
| 24 | +import org.apache.hadoop.hdfs.server.federation.resolver.ActiveNamenodeResolver; |
| 25 | +import org.apache.hadoop.hdfs.server.federation.resolver.FileSubclusterResolver; |
| 26 | +import org.apache.hadoop.hdfs.server.federation.store.StateStoreService; |
| 27 | +import org.junit.Test; |
| 28 | + |
| 29 | +import static org.junit.Assert.assertNotNull; |
| 30 | +import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.FEDERATION_FILE_RESOLVER_CLIENT_CLASS; |
| 31 | +import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.FEDERATION_NAMENODE_RESOLVER_CLIENT_CLASS; |
| 32 | + |
| 33 | +/** |
| 34 | + * Tests Router federation utility methods. |
| 35 | + */ |
| 36 | +public class TestFederationUtil { |
| 37 | + |
| 38 | + @Test |
| 39 | + public void testInstanceCreation() { |
| 40 | + Configuration conf = new HdfsConfiguration(); |
| 41 | + |
| 42 | + // Use mock resolver classes |
| 43 | + conf.setClass(FEDERATION_NAMENODE_RESOLVER_CLIENT_CLASS, |
| 44 | + MockResolver.class, ActiveNamenodeResolver.class); |
| 45 | + conf.setClass(FEDERATION_FILE_RESOLVER_CLIENT_CLASS, |
| 46 | + MockResolver.class, FileSubclusterResolver.class); |
| 47 | + |
| 48 | + Router router = new Router(); |
| 49 | + StateStoreService stateStore = new StateStoreService(); |
| 50 | + |
| 51 | + ActiveNamenodeResolver namenodeResolverWithContext = |
| 52 | + FederationUtil.newActiveNamenodeResolver(conf, stateStore); |
| 53 | + |
| 54 | + ActiveNamenodeResolver namenodeResolverWithoutContext = |
| 55 | + FederationUtil.newActiveNamenodeResolver(conf, null); |
| 56 | + |
| 57 | + FileSubclusterResolver subclusterResolverWithContext = |
| 58 | + FederationUtil.newFileSubclusterResolver(conf, router); |
| 59 | + |
| 60 | + FileSubclusterResolver subclusterResolverWithoutContext = |
| 61 | + FederationUtil.newFileSubclusterResolver(conf, null); |
| 62 | + |
| 63 | + // Check all instances are created successfully. |
| 64 | + assertNotNull(namenodeResolverWithContext); |
| 65 | + assertNotNull(namenodeResolverWithoutContext); |
| 66 | + assertNotNull(subclusterResolverWithContext); |
| 67 | + assertNotNull(subclusterResolverWithoutContext); |
| 68 | + } |
| 69 | +} |
0 commit comments