Skip to content

Commit

Permalink
HBASE-20782 Fix duplication of TestServletFilter.access
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Hentschel <[email protected]>
  • Loading branch information
xcangCRM authored and HorizonNet committed May 27, 2019
1 parent 65b8179 commit 1c1638f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,31 @@

package org.apache.hadoop.hbase.http;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.ServerSocket;
import java.net.URI;
import java.net.URL;

import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.http.HttpServer.Builder;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.security.authorize.AccessControlList;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This is a base class for functional tests of the {@link HttpServer}.
* The methods are static for other classes to import statically.
*/
public class HttpServerFunctionalTest extends Assert {
private static final Logger LOG = LoggerFactory.getLogger(HttpServerFunctionalTest.class);
/** JVM property for the webapp test dir : {@value} */
public static final String TEST_BUILD_WEBAPPS = "test.build.webapps";
/** expected location of the test.build.webapps dir: {@value} */
Expand Down Expand Up @@ -270,4 +276,25 @@ protected static int getFreePort() throws IOException {
}
}
}

/**
* 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);
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
*/
package org.apache.hadoop.hbase.http;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Set;
import java.util.TreeSet;
import javax.servlet.Filter;
Expand Down Expand Up @@ -89,27 +85,6 @@ public void initFilter(FilterContainer container, Configuration conf) {
}
}

/**
* 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
public void testServletFilter() throws Exception {
Configuration conf = new Configuration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
*/
package org.apache.hadoop.hbase.http;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Set;
import java.util.TreeSet;
import javax.servlet.Filter;
Expand Down Expand Up @@ -89,28 +85,6 @@ public void initFilter(FilterContainer container, Configuration conf) {
}
}

/**
* 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
public void testPathSpecFilters() throws Exception {
Configuration conf = new Configuration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
*/
package org.apache.hadoop.hbase.http;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Random;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
Expand Down Expand Up @@ -97,27 +93,6 @@ private static void assertExceptionContains(String string, Throwable t) {
+ 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
@Ignore
//From stack
Expand Down

0 comments on commit 1c1638f

Please sign in to comment.