jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1329670 - in /jackrabbit/oak/trunk/oak-run/src: main/java/org/apache/jackrabbit/oak/run/Main.java test/java/org/apache/jackrabbit/oak/run/BasicServerTest.java
Date Tue, 24 Apr 2012 12:24:34 GMT
Author: reschke
Date: Tue Apr 24 12:24:33 2012
New Revision: 1329670

URL: http://svn.apache.org/viewvc?rev=1329670&view=rev
Log:
OAK-69: fix server lifecycle

Modified:
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java
    jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/BasicServerTest.java

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java?rev=1329670&r1=1329669&r2=1329670&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java Tue
Apr 24 12:24:33 2012
@@ -33,44 +33,16 @@ public class Main {
     public static void main(String[] args) throws Exception {
         printProductInfo();
 
-        ServletContextHandler context =
-                new ServletContextHandler(ServletContextHandler.SECURITY);
-        context.setContextPath("/");
-
-        if (args.length == 0) {
-            System.out.println("Starting an in-memory repository");
-            System.out.println(URI + " -> [memory]");
-            Servlet servlet = new RepositoryServlet(null);
-            context.addServlet(new ServletHolder(servlet),"/*");
-        } else if (args.length == 1) {
-            System.out.println("Starting a standalone repository");
-            System.out.println(URI + " -> " + args[0]);
-            Servlet servlet = new RepositoryServlet(args[0]);
-            context.addServlet(new ServletHolder(servlet), "/*");
-        } else {
-            System.out.println("Starting a clustered repository");
-            for (int i = 0; i < args.length; i++) {
-                // FIXME: Use a clustered MicroKernel implementation
-                System.out.println(
-                        URI + "/node" + i + "/ -> " + args[i]);
-                Servlet servlet = new RepositoryServlet(args[i]);
-                context.addServlet(
-                        new ServletHolder(servlet), "/node" + i + "/*");
-            }
-        }
-
-        Server server = new Server(PORT);
-        server.setHandler(context);
-        server.start();
-        server.join();
+        HttpServer httpServer = new HttpServer(URI, args);
+        httpServer.start();
     }
 
     private static void printProductInfo() {
         String version = null;
 
         try {
-            InputStream stream = Main.class.getResourceAsStream(
-                    "/META-INF/maven/org.apache.jackrabbit/oak-run/pom.properties");
+            InputStream stream = Main.class
+                    .getResourceAsStream("/META-INF/maven/org.apache.jackrabbit/oak-run/pom.properties");
             if (stream != null) {
                 try {
                     Properties properties = new Properties();
@@ -93,4 +65,51 @@ public class Main {
         System.out.println(product);
     }
 
+    public static class HttpServer {
+
+        private Server server;
+
+        public HttpServer(String uri, String args[]) {
+            ServletContextHandler context = new ServletContextHandler(
+                    ServletContextHandler.SECURITY);
+            context.setContextPath("/");
+
+            if (args.length == 0) {
+                System.out.println("Starting an in-memory repository");
+                System.out.println(URI + " -> [memory]");
+                Servlet servlet = new RepositoryServlet(null);
+                context.addServlet(new ServletHolder(servlet), "/*");
+            } else if (args.length == 1) {
+                System.out.println("Starting a standalone repository");
+                System.out.println(URI + " -> " + args[0]);
+                Servlet servlet = new RepositoryServlet(args[0]);
+                context.addServlet(new ServletHolder(servlet), "/*");
+            } else {
+                System.out.println("Starting a clustered repository");
+                for (int i = 0; i < args.length; i++) {
+                    // FIXME: Use a clustered MicroKernel implementation
+                    System.out.println(URI + "/node" + i + "/ -> " + args[i]);
+                    Servlet servlet = new RepositoryServlet(args[i]);
+                    context.addServlet(new ServletHolder(servlet), "/node" + i
+                            + "/*");
+                }
+            }
+
+            server = new Server(PORT);
+            server.setHandler(context);
+        }
+
+        public void start() throws Exception {
+            server.start();
+        }
+
+        public void join() throws Exception {
+            server.join();
+        }
+
+        public void stop() throws Exception {
+            server.stop();
+        }
+    }
+
 }

Modified: jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/BasicServerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/BasicServerTest.java?rev=1329670&r1=1329669&r2=1329670&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/BasicServerTest.java
(original)
+++ jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/BasicServerTest.java
Tue Apr 24 12:24:33 2012
@@ -29,17 +29,17 @@ import static org.junit.Assert.assertEqu
 
 public class BasicServerTest {
 
-    private Thread st;
+    private Main.HttpServer server;
 
     @Before
-    public void startServer() {
-        st = new Thread(new ServerThread());
-        st.start();
+    public void startServer() throws Exception {
+        server = new Main.HttpServer(Main.URI, new String[0]);
+        server.start();
     }
 
     @After
-    public void stopServer() {
-        st.stop();
+    public void stopServer() throws Exception {
+        server.stop();
     }
 
     @Test
@@ -51,16 +51,4 @@ public class BasicServerTest {
                 "Basic " + Base64.encode("a:a"));
         assertEquals(200, conn.getResponseCode());
     }
-
-    public static class ServerThread implements Runnable {
-
-        @Override
-        public void run() {
-            try {
-                Main.main(new String[0]);
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-    }
 }



Mime
View raw message