|
| 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 | +package org.apache.hadoop.hdfs.server.federation.router.async; |
| 19 | + |
| 20 | +import org.apache.hadoop.conf.Configuration; |
| 21 | +import org.apache.hadoop.hdfs.DFSClient; |
| 22 | +import org.apache.hadoop.hdfs.protocol.DirectoryListing; |
| 23 | +import org.apache.hadoop.hdfs.protocol.HdfsFileStatus; |
| 24 | +import org.apache.hadoop.hdfs.server.federation.RouterConfigBuilder; |
| 25 | +import org.apache.hadoop.hdfs.server.federation.StateStoreDFSCluster; |
| 26 | +import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys; |
| 27 | +import org.junit.jupiter.api.Test; |
| 28 | + |
| 29 | +import java.io.IOException; |
| 30 | +import java.net.URI; |
| 31 | + |
| 32 | +import static org.apache.hadoop.hdfs.server.federation.FederationTestUtils.transitionClusterNSToActive; |
| 33 | +import static org.apache.hadoop.hdfs.server.federation.FederationTestUtils.transitionClusterNSToStandby; |
| 34 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 35 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 36 | + |
| 37 | +public class TestRouterAsyncClientRejectOverload { |
| 38 | + |
| 39 | + private StateStoreDFSCluster cluster; |
| 40 | + |
| 41 | + private void setupCluster(boolean ha) |
| 42 | + throws Exception { |
| 43 | + // Build and start a federated cluster. |
| 44 | + cluster = new StateStoreDFSCluster(ha, 2); |
| 45 | + Configuration routerConf = new RouterConfigBuilder() |
| 46 | + .stateStore() |
| 47 | + .metrics() |
| 48 | + .admin() |
| 49 | + .rpc() |
| 50 | + .heartbeat() |
| 51 | + .build(); |
| 52 | + |
| 53 | + routerConf.setBoolean(RBFConfigKeys.DFS_ROUTER_ASYNC_RPC_ENABLE_KEY, true); |
| 54 | + |
| 55 | + cluster.addRouterOverrides(routerConf); |
| 56 | + cluster.startCluster(); |
| 57 | + cluster.startRouters(); |
| 58 | + cluster.waitClusterUp(); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + public void testGetFileInfoWhenNsFailover() throws Exception { |
| 63 | + setupCluster(true); |
| 64 | + Configuration conf = cluster.getRouterClientConf(); |
| 65 | + conf.setInt("dfs.client.retry.max.attempts", 2); |
| 66 | + DFSClient routerClient = new DFSClient(new URI("hdfs://fed"), conf); |
| 67 | + transitionClusterNSToActive(cluster, 0); |
| 68 | + |
| 69 | + String basePath = "/ARR/testGetFileInfo"; |
| 70 | + routerClient.mkdirs(basePath); |
| 71 | + DirectoryListing directoryListing = routerClient.listPaths("/ARR", new byte[0]); |
| 72 | + assertEquals(1, directoryListing.getPartialListing().length); |
| 73 | + |
| 74 | + transitionClusterNSToStandby(cluster); |
| 75 | + |
| 76 | + assertThrows(IOException.class, () -> { |
| 77 | + HdfsFileStatus fileInfo = routerClient.getFileInfo(basePath + 1); |
| 78 | + }); |
| 79 | + } |
| 80 | +} |
| 81 | + |
0 commit comments