summaryrefslogtreecommitdiffstats
path: root/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/Server.java
diff options
context:
space:
mode:
Diffstat (limited to 'vespa-http-client/src/test/java/com/yahoo/vespa/http/client/Server.java')
-rw-r--r--vespa-http-client/src/test/java/com/yahoo/vespa/http/client/Server.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/Server.java b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/Server.java
new file mode 100644
index 00000000000..5faf5c8a029
--- /dev/null
+++ b/vespa-http-client/src/test/java/com/yahoo/vespa/http/client/Server.java
@@ -0,0 +1,40 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.http.client;
+
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.server.handler.AbstractHandler;
+
+/**
+ * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
+ * @since 5.1.20
+ */
+public final class Server implements AutoCloseable {
+
+ private final org.eclipse.jetty.server.Server server;
+
+ public Server(AbstractHandler handler, int port) {
+ this.server = new org.eclipse.jetty.server.Server(port);
+ server.setHandler(handler);
+ try {
+ server.start();
+ assert(server.isStarted());
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void close() throws RuntimeException {
+ try {
+ server.stop();
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new RuntimeException("jetty server.stop() failed", e);
+ }
+ }
+
+ public int getPort() {
+ return ((ServerConnector)server.getConnectors()[0]).getLocalPort();
+ }
+}