HBASE-20782 Fix duplication of TestServletFilter.access

Signed-off-by: Jan Hentschel <jan.hentschel@ultratendency.com>
This commit is contained in:
Xu Cang 2019-05-24 14:18:16 -07:00 committed by Jan Hentschel
parent 71a1cd83fc
commit 9a89ea53d2
No known key found for this signature in database
GPG Key ID: 5CD818B19CC299A3
4 changed files with 28 additions and 77 deletions

View File

@ -18,25 +18,31 @@
package org.apache.hadoop.hbase.http; package org.apache.hadoop.hbase.http;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.http.HttpServer.Builder; import org.apache.hadoop.hbase.http.HttpServer.Builder;
import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.security.authorize.AccessControlList; import org.apache.hadoop.security.authorize.AccessControlList;
import org.junit.Assert; import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* This is a base class for functional tests of the {@link HttpServer}. * This is a base class for functional tests of the {@link HttpServer}.
* The methods are static for other classes to import statically. * The methods are static for other classes to import statically.
*/ */
public class HttpServerFunctionalTest extends Assert { public class HttpServerFunctionalTest extends Assert {
private static final Logger LOG = LoggerFactory.getLogger(HttpServerFunctionalTest.class);
/** JVM property for the webapp test dir : {@value} */ /** JVM property for the webapp test dir : {@value} */
public static final String TEST_BUILD_WEBAPPS = "test.build.webapps"; public static final String TEST_BUILD_WEBAPPS = "test.build.webapps";
/** expected location of the test.build.webapps dir: {@value} */ /** expected location of the test.build.webapps dir: {@value} */
@ -270,4 +276,25 @@ public class HttpServerFunctionalTest extends Assert {
} }
} }
} }
/**
* access a url, ignoring some IOException such as the page does not exist
*/
public static void access(String urlstring) throws IOException {
URL url = new URL(urlstring);
URLConnection connection = url.openConnection();
connection.connect();
try (BufferedReader in = new BufferedReader(new InputStreamReader(
connection.getInputStream(), StandardCharsets.UTF_8))){
for(; in.readLine() != null;) {
continue;
}
} catch(IOException ioe) {
LOG.info("Got exception: ", ioe);
}
}
} }

View File

@ -17,11 +17,7 @@
*/ */
package org.apache.hadoop.hbase.http; package org.apache.hadoop.hbase.http;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import javax.servlet.Filter; import javax.servlet.Filter;
@ -89,27 +85,6 @@ public class TestGlobalFilter extends HttpServerFunctionalTest {
} }
} }
/**
* access a url, ignoring some IOException such as the page does not exist
*/
private static void access(String urlstring) throws IOException {
LOG.warn("access " + urlstring);
URL url = new URL(urlstring);
URLConnection connection = url.openConnection();
connection.connect();
try {
try (BufferedReader in = new BufferedReader(
new InputStreamReader(connection.getInputStream(), "UTF-8"))) {
for (; in.readLine() != null; ) {
// Ignoring the content of the URLs. Only checking if something is there.
}
}
} catch(IOException ioe) {
LOG.warn("urlstring=" + urlstring, ioe);
}
}
@Test @Test
public void testServletFilter() throws Exception { public void testServletFilter() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();

View File

@ -17,11 +17,7 @@
*/ */
package org.apache.hadoop.hbase.http; package org.apache.hadoop.hbase.http;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import javax.servlet.Filter; import javax.servlet.Filter;
@ -89,28 +85,6 @@ public class TestPathFilter extends HttpServerFunctionalTest {
} }
} }
/**
* access a url, ignoring some IOException such as the page does not exist
*/
private static void access(String urlstring) throws IOException {
LOG.warn("access " + urlstring);
URL url = new URL(urlstring);
URLConnection connection = url.openConnection();
connection.connect();
try {
try (BufferedReader in = new BufferedReader(
new InputStreamReader(connection.getInputStream(), "UTF-8"))) {
for (; in.readLine() != null; ) {
// Ignoring the content of the URLs. Only checking if something is there.
}
}
} catch(IOException ioe) {
LOG.warn("urlstring=" + urlstring, ioe);
}
}
@Test @Test
public void testPathSpecFilters() throws Exception { public void testPathSpecFilters() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();

View File

@ -17,11 +17,7 @@
*/ */
package org.apache.hadoop.hbase.http; package org.apache.hadoop.hbase.http;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Random; import java.util.Random;
import javax.servlet.Filter; import javax.servlet.Filter;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
@ -97,27 +93,6 @@ public class TestServletFilter extends HttpServerFunctionalTest {
+ StringUtils.stringifyException(t), msg.contains(string)); + StringUtils.stringifyException(t), msg.contains(string));
} }
/**
* access a url, ignoring some IOException such as the page does not exist
*/
private static void access(String urlstring) throws IOException {
LOG.warn("access " + urlstring);
URL url = new URL(urlstring);
URLConnection connection = url.openConnection();
connection.connect();
try {
try (BufferedReader in = new BufferedReader(new InputStreamReader(
connection.getInputStream(), "UTF-8"))) {
for (; in.readLine() != null; ) {
// Ignoring the content of the URLs. Only checking if something is there.
}
}
} catch(IOException ioe) {
LOG.warn("urlstring=" + urlstring, ioe);
}
}
@Test @Test
@Ignore @Ignore
//From stack //From stack