mirror of https://github.com/apache/druid.git
fix web supplier test
This commit is contained in:
parent
29c3db92b5
commit
7c90a0fb96
|
@ -18,7 +18,8 @@
|
||||||
~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>io.druid.extensions</groupId>
|
<groupId>io.druid.extensions</groupId>
|
||||||
<artifactId>druid-examples</artifactId>
|
<artifactId>druid-examples</artifactId>
|
||||||
|
@ -58,6 +59,11 @@
|
||||||
<artifactId>twitter4j-stream</artifactId>
|
<artifactId>twitter4j-stream</artifactId>
|
||||||
<version>3.0.3</version>
|
<version>3.0.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-validator</groupId>
|
||||||
|
<artifactId>commons-validator</artifactId>
|
||||||
|
<version>1.4.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- For tests! -->
|
<!-- For tests! -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -19,8 +19,11 @@
|
||||||
|
|
||||||
package io.druid.examples.web;
|
package io.druid.examples.web;
|
||||||
|
|
||||||
|
import com.google.api.client.repackaged.com.google.common.base.Throwables;
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.io.InputSupplier;
|
import com.google.common.io.InputSupplier;
|
||||||
import com.metamx.emitter.EmittingLogger;
|
import com.metamx.emitter.EmittingLogger;
|
||||||
|
import org.apache.commons.validator.routines.UrlValidator;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -31,25 +34,25 @@ import java.net.URLConnection;
|
||||||
public class WebJsonSupplier implements InputSupplier<BufferedReader>
|
public class WebJsonSupplier implements InputSupplier<BufferedReader>
|
||||||
{
|
{
|
||||||
private static final EmittingLogger log = new EmittingLogger(WebJsonSupplier.class);
|
private static final EmittingLogger log = new EmittingLogger(WebJsonSupplier.class);
|
||||||
|
private static final UrlValidator urlValidator = new UrlValidator();
|
||||||
|
|
||||||
private String urlString;
|
|
||||||
private URL url;
|
private URL url;
|
||||||
|
|
||||||
public WebJsonSupplier(String urlString)
|
public WebJsonSupplier(String urlString)
|
||||||
{
|
{
|
||||||
this.urlString = urlString;
|
Preconditions.checkState(urlValidator.isValid(urlString));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.url = new URL(urlString);
|
this.url = new URL(urlString);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
log.error(e,"Malformed url");
|
throw Throwables.propagate(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BufferedReader getInput() throws IOException
|
public BufferedReader getInput() throws IOException
|
||||||
{
|
{
|
||||||
URL url = new URL(urlString);
|
|
||||||
URLConnection connection = url.openConnection();
|
URLConnection connection = url.openConnection();
|
||||||
connection.setDoInput(true);
|
connection.setDoInput(true);
|
||||||
return new BufferedReader(new InputStreamReader(url.openStream()));
|
return new BufferedReader(new InputStreamReader(url.openStream()));
|
||||||
|
|
|
@ -22,15 +22,14 @@ package io.druid.examples.web;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
|
||||||
public class WebJsonSupplierTest
|
public class WebJsonSupplierTest
|
||||||
{
|
{
|
||||||
@Test(expected = IOException.class)
|
@Test(expected = IllegalStateException.class)
|
||||||
public void checkInvalidUrl() throws Exception
|
public void checkInvalidUrl() throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
String invalidURL = "http://invalid.url.";
|
String invalidURL = "http://invalid.url.";
|
||||||
WebJsonSupplier supplier = new WebJsonSupplier(invalidURL);
|
WebJsonSupplier supplier = new WebJsonSupplier(invalidURL);
|
||||||
supplier.getInput();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue