Skip to content

Commit

Permalink
Fix ut & checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzhaobo99 committed Dec 23, 2024
1 parent b8e30f4 commit e36817d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* 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.
*/

/**
* The Balancer is a tool for balancing the data across
* the storage devices of an HDFS cluster.
* Over time, the data in the HDFS storage can become skewed,
* The Balancer moves data blocks between DataNodes to balance data distribution.
*/
package org.apache.hadoop.hdfs.server.balancer;
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileUtil;
Expand All @@ -36,6 +35,8 @@
import org.apache.hadoop.security.ssl.KeyStoreTestUtil;
import org.apache.hadoop.test.GenericTestUtils;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

public class TestBalancerHttpServer {
private static final String BASEDIR =
GenericTestUtils.getTempPath(TestBalancerHttpServer.class.getSimpleName());
Expand Down Expand Up @@ -67,13 +68,16 @@ public static void tearDown() throws Exception {

@Test
public void testHttpServer() throws Exception {
BalancerHttpServer server = new BalancerHttpServer(conf);
BalancerHttpServer server = null;
try {
server = new BalancerHttpServer(conf);
server.start();
Assertions.assertTrue(checkConnection("http", server.getHttpAddress()));
Assertions.assertTrue(checkConnection("https", server.getHttpsAddress()));
assertThat(checkConnection("http", server.getHttpAddress())).isTrue();
assertThat(checkConnection("https", server.getHttpsAddress())).isTrue();
} finally {
server.stop();
if (server != null) {
server.stop();
}
}
}

Expand All @@ -84,11 +88,13 @@ private boolean checkConnection(String scheme, InetSocketAddress address) {
try {
URL url = new URL(scheme + "://" + NetUtils.getHostPortString(address));
URLConnection conn = connectionFactory.openConnection(url);
conn.setConnectTimeout(5 * 1000);
conn.setReadTimeout(5 * 1000);
conn.connect();
conn.getContent();
return true;
} catch (Exception e) {
return false;
}
return true;
}
}

0 comments on commit e36817d

Please sign in to comment.