You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/08/08 21:05:17 UTC

[11/15] git commit: Make it possible to run Tomcat in-process too.

Make it possible to run Tomcat in-process too.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/f969ad3b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/f969ad3b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/f969ad3b

Branch: refs/heads/two-dot-o
Commit: f969ad3b13e64fa16d7e44bd0b28c6534bb698f6
Parents: eb611a2
Author: Dave Johnson <dm...@apigee.com>
Authored: Tue Aug 5 14:47:04 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Tue Aug 5 14:47:04 2014 -0400

----------------------------------------------------------------------
 .../java/org/apache/usergrid/rest/ITSetup.java  |  9 ---------
 .../apache/usergrid/rest/TomcatResource.java    | 20 ++++++++++++--------
 2 files changed, 12 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f969ad3b/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java b/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
index 86a680d..48053ab 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
@@ -63,15 +63,6 @@ public class ITSetup extends ExternalResource {
     }
 
 
-    public ITSetup( CassandraResource cassandraResource, String webAppsPath ) {
-        this.cassandraResource = cassandraResource;
-        managementService = cassandraResource.getBean( ManagementService.class );
-        tomcatResource = TomcatResource.instance;
-        tomcatResource.setWebAppsPath(webAppsPath);
-        tomcatResource.setProperties( managementService.getProperties() );
-    }
-
-
     @Override
     protected void before() throws Throwable {
         synchronized ( cassandraResource ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f969ad3b/stack/rest/src/test/java/org/apache/usergrid/rest/TomcatResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/TomcatResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/TomcatResource.java
index f8ad731..c215345 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/TomcatResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/TomcatResource.java
@@ -61,7 +61,7 @@ public class TomcatResource extends ExternalResource {
     private int cassPort;
     private boolean started = false;
     private Properties properties;
-    private boolean forkTomcat = false;
+    private boolean forkTomcat = true;
 
     private static AtomicInteger clientCount = new AtomicInteger(0);
 
@@ -77,7 +77,7 @@ public class TomcatResource extends ExternalResource {
 
         synchronized (mutex) {
 
-            if ( clientCount.decrementAndGet() == 0 ) {
+            if ( clientCount.decrementAndGet() == 0 && process != null ) {
                 log.info("Destroying Tomcat running on port " + port);
                 process.destroy();
                 started = false;
@@ -108,8 +108,6 @@ public class TomcatResource extends ExternalResource {
                 return;
             }
 
-            started = true;
-
             if ( forkTomcat ) {
                 process = startTomcatProcess();
             } else {
@@ -132,19 +130,23 @@ public class TomcatResource extends ExternalResource {
 
 
     private void waitForTomcat() throws RuntimeException {
+        String url = "http://localhost:" + port + "/status"; 
         int count = 0;
-        while (count++ < 60) {
+        while (count++ < 30) {
             try {
                 Thread.sleep(1000);
                 Client c = Client.create();
-                WebResource wr = c.resource("http://localhost:" + port + "/status");
+                WebResource wr = c.resource( url );
                 wr.get(String.class);
                 log.info("Tomcat is started.");
+                started = true;
                 break;
                 
             } catch (Exception e) {
-                log.info("Cannot connect: " + e.getMessage());
+                log.info("Cannot connect to url {} error: {}", url, e.getMessage());
             }
+        }
+        if ( !started ) {
             throw new RuntimeException("Tomcat process never started.");
         }
     }
@@ -163,9 +165,11 @@ public class TomcatResource extends ExternalResource {
             tomcat.addWebapp( "/", new File( getWebAppsPath() ).getAbsolutePath() );
 
             log.info("-----------------------------------------------------------------");
-            log.info("Starting Tomcat port {} dir {}", port, dataDir.getAbsolutePath());
+            log.info("Starting Tomcat embedded port {} dir {}", port, dataDir.getAbsolutePath());
             log.info("-----------------------------------------------------------------");
             tomcat.start();
+
+            waitForTomcat();
     }