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:08 UTC
[02/15] git commit: Fixes to REST test infrastructure,
Tomcat property handling and Tomcat startup/shutdown.
Fixes to REST test infrastructure, Tomcat property handling and Tomcat startup/shutdown.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/6ddaec10
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/6ddaec10
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/6ddaec10
Branch: refs/heads/two-dot-o
Commit: 6ddaec107362073d94457bce0758cfd9dfb96c3a
Parents: 8618ec2
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Jul 31 09:33:10 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Jul 31 09:33:10 2014 -0400
----------------------------------------------------------------------
.../usergrid/corepersistence/CpSetup.java | 2 +-
.../apache/usergrid/rest/AbstractRestIT.java | 13 +-
.../java/org/apache/usergrid/rest/ITSetup.java | 12 +-
.../apache/usergrid/rest/TomcatResource.java | 133 +++++++++++++++----
4 files changed, 125 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6ddaec10/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
index a940e0a..c9e7ac9 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
@@ -140,7 +140,7 @@ public class CpSetup implements Setup {
// Make all Usergrid properties into Core Persistence config
cpProps.putAll( cass.getProperties() );
- logger.debug("All properties fed to Core Persistence: " + cpProps.toString() );
+ //logger.debug("All properties fed to Core Persistence: " + cpProps.toString() );
ConfigurationManager.loadProperties( cpProps );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6ddaec10/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
index dd7db4d..fd0adae 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
@@ -50,9 +50,10 @@ import org.slf4j.LoggerFactory;
/**
- * Base class for testing Usergrid Jersey-based REST API. Implementations should model the paths mapped, not the method
- * names. For example, to test the the "password" mapping on applications.users.UserResource for a PUT method, the test
- * method(s) should following the following naming convention: test_[HTTP verb]_[action mapping]_[ok|fail][_[specific
+ * Base class for testing Usergrid Jersey-based REST API. Implementations should model the
+ * paths mapped, not the method names. For example, to test the the "password" mapping on
+ * applications.users.UserResource for a PUT method, the test method(s) should following the
+ * following naming convention: test_[HTTP verb]_[action mapping]_[ok|fail][_[specific
* failure condition if multiple]
*/
//@Concurrent()
@@ -370,7 +371,7 @@ public abstract class AbstractRestIT extends JerseyTest {
// set the value locally (in the Usergrid instance here in the JUnit classloader
setup.getMgmtSvc().getProperties().setProperty( key, value );
- // set the value remotely (in the Usergrid instance running in Jetty classloader)
+ // set the value remotely (in the Usergrid instance running in Tomcat classloader)
Map<String, String> props = new HashMap<String, String>();
props.put( key, value );
resource().path( "/testproperties" ).queryParam( "access_token", access_token )
@@ -387,14 +388,14 @@ public abstract class AbstractRestIT extends JerseyTest {
setup.getMgmtSvc().getProperties().setProperty( key, props.get( key ) );
}
- // set the values remotely (in the Usergrid instance running in Jetty classloader)
+ // set the values remotely (in the Usergrid instance running in Tomcat classloader)
resource().path( "/testproperties" ).queryParam( "access_token", access_token )
.accept( MediaType.APPLICATION_JSON )
.type( MediaType.APPLICATION_JSON_TYPE ).post( props );
}
- /** Get all management service properties from th Jetty instance of the service. */
+ /** Get all management service properties from the Tomcat instance of the service. */
public Map<String, String> getRemoteTestProperties() {
return resource().path( "/testproperties" ).queryParam( "access_token", access_token )
.accept( MediaType.APPLICATION_JSON )
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6ddaec10/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 448a022..86a680d 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
@@ -56,14 +56,19 @@ public class ITSetup extends ExternalResource {
public ITSetup( CassandraResource cassandraResource) {
this.cassandraResource = cassandraResource;
+ managementService = cassandraResource.getBean( ManagementService.class );
tomcatResource = TomcatResource.instance;
- tomcatResource.setWebAppsPath("src/main/webapp");
+ tomcatResource.setWebAppsPath( "src/main/webapp" );
+ tomcatResource.setProperties( managementService.getProperties() );
}
+
public ITSetup( CassandraResource cassandraResource, String webAppsPath ) {
this.cassandraResource = cassandraResource;
+ managementService = cassandraResource.getBean( ManagementService.class );
tomcatResource = TomcatResource.instance;
tomcatResource.setWebAppsPath(webAppsPath);
+ tomcatResource.setProperties( managementService.getProperties() );
}
@@ -72,8 +77,6 @@ public class ITSetup extends ExternalResource {
synchronized ( cassandraResource ) {
super.before();
- managementService = cassandraResource.getBean( ManagementService.class );
-
if ( !setupCalled ) {
managementService.setup();
setupCalled = true;
@@ -87,7 +90,8 @@ public class ITSetup extends ExternalResource {
applicationCreator = cassandraResource.getBean( ApplicationCreator.class );
tomcatResource.setCassandraPort( cassandraResource.getRpcPort() );
- tomcatResource.setElasticSearchPort( Integer.parseInt( System.getProperty("EMBEDDED_ES_PORT")) );
+ tomcatResource.setElasticSearchPort(
+ Integer.parseInt( System.getProperty("EMBEDDED_ES_PORT")) );
tomcatResource.before();
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6ddaec10/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 0da3701..f3f7635 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
@@ -33,6 +33,8 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,36 +49,61 @@ public class TomcatResource extends ExternalResource {
private static final Logger log = LoggerFactory.getLogger(TomcatResource.class);
public static final TomcatResource instance = new TomcatResource();
+
private static final Object mutex = new Object();
private String webAppsPath;
private int port;
private int esPort;
private int cassPort;
private boolean started = false;
+ private Properties properties;
+
+ private static AtomicInteger clientCount = new AtomicInteger(0);
Process process = null;
protected TomcatResource() {}
+
@Override
protected void after() {
- process.destroy();
+ log.info("Entering after");
+
+ synchronized (mutex) {
+
+ if ( clientCount.decrementAndGet() == 0 ) {
+ log.info("Destroying Tomcat running on port " + port);
+ process.destroy();
+ started = false;
+ } else {
+ log.info("NOT stopping Tomcat because it is still in use");
+ }
+ }
+
+ log.info("Leaving after");
}
@Override
protected void before() throws Throwable {
+ log.info("Entering before");
- if (started) {
- return;
- }
+// if (started) {
+// log.info("NOT starting Tomcat because it is already started #1");
+// return;
+// }
synchronized (mutex) {
+ clientCount.incrementAndGet();
+
if (started) {
+ log.info("NOT starting Tomcat because it is already started #2");
return;
}
+ started = true;
+
port = AvailablePortFinder.getNextAvailable(9998 + RandomUtils.nextInt(10));
String propDirPath = createPropDir();
@@ -87,8 +114,15 @@ public class TomcatResource extends ExternalResource {
waitForTomcat();
- started = true;
+ Runtime.getRuntime().addShutdownHook( new Thread() {
+ @Override
+ public void run() {
+ after();
+ }
+ } );
}
+
+ log.info("Leaving before");
}
private String createPropDir() {
@@ -122,7 +156,7 @@ public class TomcatResource extends ExternalResource {
String javaHome = (String)System.getenv("JAVA_HOME");
String logConfig = "-Dlog4j.configuration=file:./src/test/resources/log4j.properties";
- String maxMemory = "-Xmx5000m";
+ String maxMemory = "-Xmx1000m";
ProcessBuilder pb = new ProcessBuilder(javaHome + "/bin/java", maxMemory, logConfig,
"org.apache.usergrid.TomcatMain", "src/main/webapp", port + "");
@@ -151,7 +185,7 @@ public class TomcatResource extends ExternalResource {
final Process p = pb.start();
- log.debug("Started Tomcat process with classpath = " + newClasspath );
+ //log.debug("Started Tomcat process with classpath = " + newClasspath );
// use thread to log Tomcat output
new Thread( new Runnable() {
@@ -163,10 +197,11 @@ public class TomcatResource extends ExternalResource {
while ((line = br.readLine()) != null) {
log.info(line);
}
- } catch (IOException ex) {
+
+ } catch (Exception ex) {
log.error("Error reading from Tomcat process", ex);
return;
- }
+ }
}
}).start();
@@ -176,37 +211,83 @@ public class TomcatResource extends ExternalResource {
private void createPropertyFiles( String propDirPath ) throws IOException {
PrintWriter pw = new PrintWriter(
- new FileWriter( propDirPath + File.separator + "usergrid-custom.properties"));
+ new FileWriter( propDirPath + File.separator + "usergrid-custom.properties"));
pw.println("cassandra.url=localhost:" + cassPort);
- pw.println("usergrid.mongo.disable=true");
- pw.println("swagger.basepath=http://sometestvalue");
- pw.println("usergrid.counter.batch.size=1");
- pw.println("usergrid.test=true");
- pw.println("usergrid.sysadmin.login.name=superuser");
- pw.println("usergrid.sysadmin.login.email=superuser@usergrid.com");
- pw.println("usergrid.sysadmin.login.password=superpassword");
- pw.println("usergrid.sysadmin.login.allowed=true");
-
pw.println("cassandra.version=1.2");
pw.println("cassandra.cluster_name=Usergrid");
- pw.println("cassandra.connections=20");
+ pw.println("cassandra.connections=600");
pw.println("cassandra.timeout=5000");
+
+ pw.println("elasticsearch.hosts=127.0.0.1");
+ pw.println("elasticsearch.port=" + esPort);
+ pw.println("elasticsearch.cluster_name=test_cluster");
+ pw.println("elasticsearch.index_prefix=usergrid");
pw.println("collections.keyspace=Usergrid_Applications");
pw.println("collections.keyspace.strategy.options=replication_factor:1");
pw.println("collections.keyspace.strategy.class=org.apache.cassandra.locator.SimpleStrategy");
pw.println("collection.stage.transient.timeout=6");
+
+ pw.println("usergrid.mongo.disable=true");
+ pw.println("swagger.basepath=http://sometestvalue");
+ pw.println("usergrid.counter.batch.size=1");
+ pw.println("usergrid.test=true");
+
+ pw.println("usergrid.sysadmin.login.name=superuser");
+ pw.println("usergrid.sysadmin.login.email=superuser@usergrid.com");
+ pw.println("usergrid.sysadmin.login.password=superpassword");
+ pw.println("usergrid.sysadmin.login.allowed=true");
+
- pw.println("elasticsearch.hosts=127.0.0.1");
- pw.println("elasticsearch.port=" + esPort);
- pw.println("elasticsearch.cluster_name=test_cluster");
- pw.println("elasticsearch.index_prefix=usergrid");
+ pw.println("mail.transport.protocol=smtp");
+ pw.println("mail.store.protocol=imap");
+ pw.println("mail.smtp.host=usergrid.com");
+ pw.println("mail.smtp.username=testuser");
+ pw.println("mail.smtp.password=testpassword");
pw.println("index.query.limit.default=1000");
+
+ pw.println("usergrid.recaptcha.public=");
+ pw.println("usergrid.recaptcha.private=");
+ pw.println("usergrid.sysadmin.email=");
+ pw.println("usergrid.management.admin_users_require_confirmation=false");
+ pw.println("usergrid.management.admin_users_require_activation=false");
+ pw.println("usergrid.management.notify_admin_of_activation=false");
+ pw.println("usergrid.management.organizations_require_confirmation=false");
+ pw.println("usergrid.management.organizations_require_activation=false");
+ pw.println("usergrid.management.notify_sysadmin_of_new_organizations=false");
+ pw.println("usergrid.management.notify_sysadmin_of_new_admin_users=false");
+ pw.println("usergrid.setup-test-account=true");
+ pw.println("usergrid.test-account.app=test-app");
+ pw.println("usergrid.test-account.organization=test-organization");
+ pw.println("usergrid.test-account.admin-user.username=test");
+ pw.println("usergrid.test-account.admin-user.name=Test User");
+ pw.println("usergrid.test-account.admin-user.email=test@usergrid.com");
+ pw.println("usergrid.test-account.admin-user.password=test");
pw.flush();
pw.close();
+
+
+// // include all properties
+// Map<String, String> allProperties = new HashMap<String, String>();
+// for ( Object name : properties.keySet() ) {
+// allProperties.put( (String)name, properties.getProperty((String)name));
+// }
+//
+// // override some properties with correct port numbers
+// allProperties.put("cassandra.url", "localhost:" + cassPort);
+// allProperties.put("elasticsearch.hosts", "127.0.0.1");
+// allProperties.put("elasticsearch.port", ""+esPort );
+//
+// PrintWriter pw = new PrintWriter(
+// new FileWriter( propDirPath + File.separator + "usergrid-custom.properties"));
+// for ( String name : allProperties.keySet() ) {
+// pw.println(name + "=" + allProperties.get( name ));
+// }
+// pw.flush();
+// pw.close();
}
/**
@@ -231,4 +312,8 @@ public class TomcatResource extends ExternalResource {
void setElasticSearchPort(int esPort) {
this.esPort = esPort;
}
+
+ void setProperties(Properties properties) {
+ this.properties = properties;
+ }
}