summaryrefslogtreecommitdiffstats
path: root/jdisc_http_service
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@oath.com>2017-11-08 21:26:20 +0100
committerBjørn Christian Seime <bjorncs@oath.com>2017-11-08 21:26:20 +0100
commite53ba12ba9211c58898d586697b34c0213c5ebe9 (patch)
tree0f6282b4a56127b68aadc47f1a0dc0bb98abc4ad /jdisc_http_service
parent90575fdb27aa83c8e652ae4b46eac52fdbefe003 (diff)
Remove dead code
Diffstat (limited to 'jdisc_http_service')
-rw-r--r--jdisc_http_service/src/test/java/com/yahoo/jdisc/http/AssertFile.java34
-rw-r--r--jdisc_http_service/src/test/java/com/yahoo/jdisc/http/AssertHttp.java72
-rw-r--r--jdisc_http_service/src/test/java/com/yahoo/jdisc/http/DummyMetricManager.java58
-rw-r--r--jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/RemoteClient.java52
-rw-r--r--jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/ServerTestDriver.java146
5 files changed, 0 insertions, 362 deletions
diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/AssertFile.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/AssertFile.java
deleted file mode 100644
index 24739fc47a6..00000000000
--- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/AssertFile.java
+++ /dev/null
@@ -1,34 +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;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-
-/**
- * @author <a href="mailto:apurvak@yahoo-inc.com">Apurva Kumar</a>
- */
-
-public class AssertFile {
-
- public static void assertContains(File logFile, String expected) throws IOException {
- String s = new String(
- Files.readAllBytes(Paths.get(logFile.getAbsolutePath())),
- StandardCharsets.UTF_8);
- assertThat(s, containsString(expected));
- }
-
- public static void assertNotContains(File logFile, String expected) throws IOException {
- String s = new String(
- Files.readAllBytes(Paths.get(logFile.getAbsolutePath())),
- StandardCharsets.UTF_8);
- assertThat(s, not(containsString(expected)));
- }
-}
diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/AssertHttp.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/AssertHttp.java
deleted file mode 100644
index dfc9550191c..00000000000
--- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/AssertHttp.java
+++ /dev/null
@@ -1,72 +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;
-
-import com.yahoo.jdisc.handler.RequestHandler;
-import com.yahoo.jdisc.http.test.RemoteClient;
-import com.yahoo.jdisc.http.test.ServerTestDriver;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.regex.Pattern;
-
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-
-/**
- * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen Hult</a>
- */
-public abstract class AssertHttp {
-
- public static void assertChunk(String expected, String actual) {
- if (expected.startsWith("HTTP/1.")) {
- expected = sortChunk(expected);
- actual = sortChunk(actual);
- }
- Pattern pattern = Pattern.compile(expected, Pattern.DOTALL | Pattern.MULTILINE);
- if (pattern.matcher(actual).matches()) {
- return;
- }
- assertEquals(expected, actual);
- }
-
- public static void assertResponse(RequestHandler requestHandler, String request,
- String... expectedChunks) throws IOException {
- ServerTestDriver driver = ServerTestDriver.newInstance(requestHandler);
- assertResponse(driver, request, expectedChunks);
- assertTrue(driver.close());
- }
-
- public static void assertResponse(ServerTestDriver driver, String request, String... expectedChunks)
- throws IOException {
- assertResponse(driver.client(), request, expectedChunks);
- }
-
- public static void assertResponse(RemoteClient client, String request, String... expectedChunks)
- throws IOException {
- client.writeRequest(request);
- for (String expected : expectedChunks) {
- assertChunk(expected, client.readChunk());
- }
- }
-
- private static String sortChunk(String chunk) {
- String[] lines = chunk.split("\r\n");
- if (lines.length > 2) {
- int prev = 1, next = 2;
- for ( ; next < lines.length && !lines[next].isEmpty(); ++next) {
- if (!Character.isLetterOrDigit(lines[next].charAt(0))) {
- Arrays.sort(lines, prev, next);
- prev = next + 1;
- }
- }
- if (prev < next) {
- Arrays.sort(lines, prev, next);
- }
- }
- StringBuilder out = new StringBuilder();
- for (String line : lines) {
- out.append(line).append("\r\n");
- }
- return out.toString();
- }
-}
diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/DummyMetricManager.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/DummyMetricManager.java
deleted file mode 100644
index 100cc19477d..00000000000
--- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/DummyMetricManager.java
+++ /dev/null
@@ -1,58 +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;
-
-import com.google.inject.AbstractModule;
-import com.yahoo.jdisc.Metric;
-import com.yahoo.jdisc.application.MetricConsumer;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:ssameer@yahoo-inc.com">ssameer</a>
- * Date: 2/15/13
- * Time: 11:49 AM
- */
-public class DummyMetricManager extends AbstractModule implements MetricConsumer {
-
- private final Map<String, Integer> metrics = new HashMap<>();
- private Map<String, ?> lastContextDimensions;
-
- @Override
- protected void configure() {
- bind(MetricConsumer.class).toInstance(this);
- }
-
- @Override
- public void add(String key, Number val, Metric.Context ctx) {
- synchronized (metrics) {
- metrics.put(key, get(key) + val.intValue());
- }
- }
-
- @Override
- public void set(String key, Number val, Metric.Context ctx) {
- synchronized (metrics) {
- metrics.put(key, val.intValue());
- }
- }
-
- @Override
- public Metric.Context createContext(Map<String, ?> dimensions) {
- lastContextDimensions = dimensions;
- return new Metric.Context() { };
- }
-
- public Map<String, ?> getLastContextDimensions() {
- return lastContextDimensions;
- }
-
- public int get(String key) {
- Integer val;
- synchronized (metrics) {
- val = metrics.get(key);
- }
- return val != null ? val : 0;
- }
-
-}
diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/RemoteClient.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/RemoteClient.java
deleted file mode 100644
index 12d2f735f63..00000000000
--- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/RemoteClient.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 com.yahoo.jdisc.http.server.jetty.JettyHttpServer;
-import com.yahoo.jdisc.http.ssl.SslKeyStore;
-
-import javax.net.ssl.SSLContext;
-import java.io.IOException;
-import java.net.Socket;
-import java.nio.charset.StandardCharsets;
-
-/**
- * @author Simon Thoresen Hult
- */
-public class RemoteClient extends ChunkReader {
-
- private final Socket socket;
-
- private RemoteClient(Socket socket) throws IOException {
- super(socket.getInputStream());
- this.socket = socket;
- }
-
- public void close() throws IOException {
- socket.close();
- }
-
- public void writeRequest(String request) throws IOException {
- socket.getOutputStream().write(request.getBytes(StandardCharsets.UTF_8));
- }
-
- public static RemoteClient newInstance(JettyHttpServer server) throws IOException {
- return newInstance(server.getListenPort());
- }
-
- public static RemoteClient newInstance(int listenPort) throws IOException {
- return new RemoteClient(new Socket("localhost", listenPort));
- }
-
- public static RemoteClient newSslInstance(int listenPort, SslKeyStore sslKeyStore) throws IOException {
- SSLContext ctx = SslContextFactory.newInstanceFromTrustStore(sslKeyStore).getServerSSLContext();
- if (ctx == null) {
- throw new RuntimeException("Failed to create socket with SSLContext.");
- }
- return new RemoteClient(ctx.getSocketFactory().createSocket("localhost", listenPort));
- }
-
- public static RemoteClient newSslInstance(JettyHttpServer server, SslKeyStore keyStore) throws IOException {
- return newSslInstance(server.getListenPort(), keyStore);
- }
-
-}
diff --git a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/ServerTestDriver.java b/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/ServerTestDriver.java
deleted file mode 100644
index 324d73e5701..00000000000
--- a/jdisc_http_service/src/test/java/com/yahoo/jdisc/http/test/ServerTestDriver.java
+++ /dev/null
@@ -1,146 +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 com.google.inject.AbstractModule;
-import com.google.inject.Module;
-import com.google.inject.TypeLiteral;
-import com.yahoo.jdisc.application.BindingRepository;
-import com.yahoo.jdisc.application.ContainerActivator;
-import com.yahoo.jdisc.application.ContainerBuilder;
-import com.yahoo.jdisc.handler.RequestHandler;
-import com.yahoo.jdisc.http.HttpRequest;
-import com.yahoo.jdisc.http.filter.RequestFilter;
-import com.yahoo.jdisc.http.filter.ResponseFilter;
-import com.yahoo.jdisc.http.server.jetty.JettyHttpServer;
-import com.yahoo.jdisc.http.ssl.SslKeyStore;
-import com.yahoo.jdisc.test.TestDriver;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * @author Simon Thoresen Hult
- */
-public class ServerTestDriver {
-
- private final TestDriver driver;
- private final JettyHttpServer server;
- private final RemoteClient client;
-
- private ServerTestDriver(TestDriver driver, JettyHttpServer server, RemoteClient client) {
- this.driver = driver;
- this.server = server;
- this.client = client;
- }
-
- public boolean close() throws IOException {
- client.close();
- server.close();
- server.release();
- return driver.close();
- }
-
- public TestDriver parent() {
- return driver;
- }
-
- public ContainerActivator containerActivator() {
- return driver;
- }
-
- public JettyHttpServer server() {
- return server;
- }
-
- public RemoteClient client() {
- return client;
- }
-
- public HttpRequest newRequest(HttpRequest.Method method, String uri, HttpRequest.Version version) {
- return HttpRequest.newServerRequest(driver, newRequestUri(uri), method, version);
- }
-
- public URI newRequestUri(String uri) {
- return newRequestUri(URI.create(uri));
- }
-
- public URI newRequestUri(URI uri) {
- try {
- return new URI("http", null, "locahost",
- server.getListenPort(), uri.getPath(), uri.getQuery(), uri.getFragment());
- } catch (URISyntaxException e) {
- throw new IllegalArgumentException(e);
- }
- }
-
- public static ServerTestDriver newInstance(RequestHandler requestHandler, Module... guiceModules) throws IOException {
- return newInstance(requestHandler, Arrays.asList(guiceModules));
- }
-
- public static ServerTestDriver newInstance(RequestHandler requestHandler, Iterable<Module> guiceModules)
- throws IOException {
- List<Module> lst = new LinkedList<>();
- lst.add(newDefaultModule());
- for (Module module : guiceModules) {
- lst.add(module);
- }
- TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(lst.toArray(new Module[lst.size()]));
- ContainerBuilder builder = driver.newContainerBuilder();
- builder.serverBindings().bind("*://*/*", requestHandler);
- JettyHttpServer server = builder.guiceModules().getInstance(JettyHttpServer.class);
- return newInstance(null, driver, builder, server);
- }
-
- private static ServerTestDriver newInstance(SslKeyStore clientTrustStore, TestDriver driver, ContainerBuilder builder,
- JettyHttpServer server) throws IOException {
- builder.serverProviders().install(server);
- driver.activateContainer(builder);
- try {
- server.start();
- } catch (RuntimeException e) {
- server.release();
- driver.close();
- throw e;
- }
- RemoteClient client;
- if (clientTrustStore == null) {
- client = RemoteClient.newInstance(server);
- } else {
- client = RemoteClient.newSslInstance(server, clientTrustStore);
- }
- return new ServerTestDriver(driver, server, client);
- }
-
- public static Module newDefaultModule() {
- return new AbstractModule() {
-
- @Override
- protected void configure() {
- bind(new TypeLiteral<BindingRepository<RequestFilter>>() { })
- .toInstance(new BindingRepository<>());
- bind(new TypeLiteral<BindingRepository<ResponseFilter>>() { })
- .toInstance(new BindingRepository<>());
- }
- };
- }
-
- public static Module newFilterModule(final BindingRepository<RequestFilter> requestFilters,
- final BindingRepository<ResponseFilter> responseFilters) {
- return new AbstractModule() {
-
- @Override
- protected void configure() {
- if (requestFilters != null) {
- bind(new TypeLiteral<BindingRepository<RequestFilter>>() { }).toInstance(requestFilters);
- }
- if (responseFilters != null) {
- bind(new TypeLiteral<BindingRepository<ResponseFilter>>() { }).toInstance(responseFilters);
- }
- }
- };
- }
-}