summaryrefslogtreecommitdiffstats
path: root/jdisc_http_service
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@oath.com>2017-11-09 12:54:43 +0100
committerBjørn Christian Seime <bjorncs@oath.com>2017-11-09 12:54:43 +0100
commit6731f1d633a2d5d261b94d40179cc5303bfc4374 (patch)
treec22ac493b1163f6e9a792fe6f37f7ecc01f80af4 /jdisc_http_service
parente53ba12ba9211c58898d586697b34c0213c5ebe9 (diff)
Remove 'test' suffix from package name. Remove more dead code
Diffstat (limited to 'jdisc_http_service')
-rw-r--r--jdisc_http_service/src/test/java/com/yahoo/jdisc/http/SslContextFactory.java (renamed from jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/SslContextFactory.java)2
-rw-r--r--jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/ConnectorFactoryTest.java2
-rw-r--r--jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/TestDriver.java2
-rw-r--r--jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/ChunkReader.java124
-rw-r--r--jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/RemoteServer.java110
-rw-r--r--jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/RemoteServerTestCase.java52
6 files changed, 3 insertions, 289 deletions
diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/SslContextFactory.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/SslContextFactory.java
index 7e0e2ad1371..e71bd190a37 100644
--- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/SslContextFactory.java
+++ b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/SslContextFactory.java
@@ -1,5 +1,5 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.jdisc.http.test;
+package com.yahoo.jdisc.http;
import com.yahoo.jdisc.http.ssl.SslKeyStore;
diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/ConnectorFactoryTest.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/ConnectorFactoryTest.java
index b0e03bc9035..25457c0c6c6 100644
--- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/ConnectorFactoryTest.java
+++ b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/ConnectorFactoryTest.java
@@ -6,7 +6,7 @@ import com.yahoo.jdisc.Metric;
import com.yahoo.jdisc.http.ConnectorConfig;
import com.yahoo.jdisc.http.SecretStore;
import com.yahoo.jdisc.http.ssl.ReaderForPath;
-import com.yahoo.jdisc.http.test.SslContextFactory;
+import com.yahoo.jdisc.http.SslContextFactory;
import com.yahoo.jdisc.http.ssl.SslKeyStore;
import com.yahoo.jdisc.http.ssl.pem.PemKeyStore;
import com.yahoo.jdisc.http.ssl.pem.PemSslKeyStore;
diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/TestDriver.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/TestDriver.java
index b2155655b64..8ddcd7f03ac 100644
--- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/TestDriver.java
+++ b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/server/jetty/TestDriver.java
@@ -7,7 +7,7 @@ import com.yahoo.jdisc.application.ContainerBuilder;
import com.yahoo.jdisc.handler.RequestHandler;
import com.yahoo.jdisc.http.ConnectorConfig;
import com.yahoo.jdisc.http.ssl.jks.JKSKeyStore;
-import com.yahoo.jdisc.http.test.SslContextFactory;
+import com.yahoo.jdisc.http.SslContextFactory;
import com.yahoo.jdisc.http.ssl.SslKeyStore;
import javax.net.ssl.SSLContext;
diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/ChunkReader.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/ChunkReader.java
deleted file mode 100644
index 67572169a82..00000000000
--- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/ChunkReader.java
+++ /dev/null
@@ -1,124 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.jdisc.http.test;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * @author Simon Thoresen
- */
-public class ChunkReader {
-
- private static final Pattern CONTENT_LENGTH = Pattern.compile(".+^content-length: (\\d+)$.*",
- Pattern.CASE_INSENSITIVE |
- Pattern.MULTILINE |
- Pattern.DOTALL);
- private static final Pattern CHUNKED_ENCODING = Pattern.compile(".+^transfer-encoding: chunked$.*",
- Pattern.CASE_INSENSITIVE |
- Pattern.MULTILINE |
- Pattern.DOTALL);
- private final InputStream in;
- private StringBuilder reading = new StringBuilder();
- private boolean readingHeader = true;
-
- public ChunkReader(InputStream in) {
- this.in = in;
- }
-
- public boolean isEndOfContent() throws IOException {
- if (in.available() != 0) {
- StringBuilder sb = new StringBuilder();
- sb.append(in.available()).append(": ");
- for(int c = in.read(); c != -1; c = in.read()) {
- sb.append('\'');
- sb.append(c);
- sb.append("' ");
- }
- throw new IllegalStateException("This is not the end '" + sb.toString());
- }
- return in.available() == 0;
- }
-
- public String readChunk() throws IOException {
- while (true) {
- String ret = removeNextChunk();
- if (ret != null) {
- return ret;
- }
- readFromStream();
- }
- }
-
- private String readContent(int length) throws IOException {
- while (reading.length() < length) {
- readFromStream();
- }
- return splitReadBuffer(length);
- }
-
- private void readFromStream() throws IOException {
- byte[] buf = new byte[4096];
- try {
- while (!Thread.currentThread().isInterrupted()) {
- int len = in.read(buf, 0, buf.length);
- if (len < 0) {
- throw new IOException("Socket is closed.");
- }
- if (len > 0) {
- reading.append(StandardCharsets.UTF_8.decode(ByteBuffer.wrap(buf, 0, len)));
- break;
- }
- Thread.sleep(10);
- }
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- }
- }
-
- private String removeNextChunk() throws IOException {
- if (readingHeader) {
- int pos = reading.indexOf("\r\n\r\n");
- if (pos < 0) {
- return null;
- }
- String ret = splitReadBuffer(pos + 4);
- Matcher m = CONTENT_LENGTH.matcher(ret);
- if (m.matches()) {
- ret += readContent(Integer.valueOf(m.group(1)));
- }
- readingHeader = !CHUNKED_ENCODING.matcher(ret).matches();
- return ret;
- } else if (reading.indexOf("0\r\n") == 0) {
- int pos = reading.indexOf("\r\n\r\n", 1);
- if (pos < 0) {
- return null;
- }
- readingHeader = true;
- return splitReadBuffer(pos + 4);
- } else {
- int pos = reading.indexOf("\r\n");
- if (pos < 0) {
- return null;
- }
- pos = reading.indexOf("\r\n", pos + 2);
- if (pos < 0) {
- return null;
- }
- return splitReadBuffer(pos + 2);
- }
- }
-
- private String splitReadBuffer(int pos) {
- String ret = reading.substring(0, pos);
- if (pos < reading.length()) {
- reading = new StringBuilder(reading.substring(pos));
- } else {
- reading = new StringBuilder();
- }
- return ret;
- }
-}
diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/RemoteServer.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/RemoteServer.java
deleted file mode 100644
index 2897d0e2911..00000000000
--- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/RemoteServer.java
+++ /dev/null
@@ -1,110 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.jdisc.http.test;
-
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
-/**
- * @author Simon Thoresen
- */
-public class RemoteServer implements Runnable {
-
- private final Thread thread = new Thread(this, "RemoteServer@" + System.identityHashCode(this));
- private final LinkedBlockingQueue<Socket> clients = new LinkedBlockingQueue<>();
- private final ServerSocket server;
-
- private RemoteServer(int listenPort) throws IOException {
- this.server = new ServerSocket(listenPort);
- }
-
- @Override
- public void run() {
- try {
- while (!Thread.interrupted()) {
- Socket client = server.accept();
- if (client != null) {
- clients.add(client);
- }
- }
- } catch (IOException e) {
- if (!server.isClosed()) {
- e.printStackTrace();
- }
- }
- }
-
- public URI newRequestUri(String uri) {
- return newRequestUri(URI.create(uri));
- }
-
- public URI newRequestUri(URI uri) {
- URI serverUri = connectionSpec();
- try {
- return new URI(serverUri.getScheme(), serverUri.getUserInfo(), serverUri.getHost(),
- serverUri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment());
- } catch (URISyntaxException e) {
- throw new IllegalArgumentException(e);
- }
- }
-
- public URI connectionSpec() {
- return URI.create("http://localhost:" + server.getLocalPort() + "/");
- }
-
- public Connection awaitConnection(int timeout, TimeUnit unit) throws InterruptedException, IOException {
- Socket client = clients.poll(timeout, unit);
- if (client == null) {
- return null;
- }
- return new Connection(client);
- }
-
- public boolean close(int timeout, TimeUnit unit) {
- try {
- server.close();
- } catch (IOException e) {
- e.printStackTrace();
- return false;
- }
- try {
- thread.join(unit.toMillis(timeout));
- } catch (InterruptedException e) {
- return false;
- }
- return !thread.isAlive();
- }
-
- public static RemoteServer newInstance() throws IOException {
- RemoteServer ret = new RemoteServer(0);
- ret.thread.start();
- return ret;
- }
-
- public static class Connection extends ChunkReader {
-
- private final Socket socket;
- private final PrintWriter out;
-
- private Connection(Socket socket) throws IOException {
- super(socket.getInputStream());
- this.socket = socket;
- this.out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
- }
-
- public void writeChunk(String chunk) {
- out.print(chunk);
- }
-
- public void close() throws IOException {
- out.close();
- socket.close();
- }
- }
-}
diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/RemoteServerTestCase.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/RemoteServerTestCase.java
deleted file mode 100644
index b6b9d984e7e..00000000000
--- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/RemoteServerTestCase.java
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.jdisc.http.test;
-
-import org.testng.annotations.Test;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.concurrent.TimeUnit;
-
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-/**
- * @author Simon Thoresen
- */
-public class RemoteServerTestCase {
-
- @Test
- public void requireThatRequestUriFactoryWorks() throws IOException {
- RemoteServer server = RemoteServer.newInstance();
- try {
- server.newRequestUri((String)null);
- fail();
- } catch (NullPointerException e) {
-
- }
- try {
- server.newRequestUri((URI)null);
- fail();
- } catch (NullPointerException e) {
-
- }
- try {
- server.newRequestUri("foo");
- fail();
- } catch (IllegalArgumentException e) {
- assertTrue(e.getCause() instanceof URISyntaxException);
- }
- URI requestUri = server.newRequestUri("/foo?baz=cox#bar");
- URI serverUri = server.connectionSpec();
- assertEquals(serverUri.getScheme(), requestUri.getScheme());
- assertEquals(serverUri.getUserInfo(), requestUri.getUserInfo());
- assertEquals(serverUri.getHost(), requestUri.getHost());
- assertEquals(serverUri.getPort(), requestUri.getPort());
- assertEquals("/foo", requestUri.getPath());
- assertEquals("baz=cox", requestUri.getQuery());
- assertEquals("bar", requestUri.getFragment());
- assertTrue(server.close(60, TimeUnit.SECONDS));
- }
-}