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:20 UTC
[14/15] git commit: Now forking ElasticSearch and Cassandra during
REST tests, current status is: Tests run: 205, Failures: 11, Errors: 11,
Skipped: 11
Now forking ElasticSearch and Cassandra during REST tests, current status is: Tests run: 205, Failures: 11, Errors: 11, Skipped: 11
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/6e100761
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/6e100761
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/6e100761
Branch: refs/heads/two-dot-o
Commit: 6e10076164396be26cdb69b8f8a373739d13eb13
Parents: d142765
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Aug 8 13:08:33 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Aug 8 13:08:33 2014 -0400
----------------------------------------------------------------------
.../main/resources/usergrid-default.properties | 4 +-
.../apache/usergrid/rest/TomcatResource.java | 7 +-
stack/rest/src/test/resources/log4j.properties | 2 +-
.../resources/usergrid-custom-test.properties | 4 +-
.../java/org/apache/usergrid/TomcatMain.java | 2 +-
.../usergrid/cassandra/CassandraMain.java | 70 ++++
.../usergrid/cassandra/CassandraResource.java | 397 +++++++++++++------
.../resources/usergrid-custom-test.properties | 2 +
.../resources/usergrid-properties-context.xml | 23 ++
9 files changed, 393 insertions(+), 118 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6e100761/stack/config/src/main/resources/usergrid-default.properties
----------------------------------------------------------------------
diff --git a/stack/config/src/main/resources/usergrid-default.properties b/stack/config/src/main/resources/usergrid-default.properties
index 09d4f94..d61aeb2 100644
--- a/stack/config/src/main/resources/usergrid-default.properties
+++ b/stack/config/src/main/resources/usergrid-default.properties
@@ -49,8 +49,8 @@ cassandra.connections=600
collection.stage.transient.timeout=60
-hystrix.threadpool.graph_user.coreSize=40
-hystrix.threadpool.graph_async.coreSize=40
+hystrix.threadpool.graph_user.coreSize=10
+hystrix.threadpool.graph_async.coreSize=10
elasticsearch.embedded=false
elasticsearch.cluster_name=elasticsearch
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6e100761/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 85a01e9..645370b 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
@@ -72,7 +72,7 @@ public class TomcatResource extends ExternalResource {
protected TomcatResource() {
- try {
+ try {
String[] locations = { "usergrid-properties-context.xml" };
ConfigurableApplicationContext appContext =
new ClassPathXmlApplicationContext( locations );
@@ -194,6 +194,7 @@ public class TomcatResource extends ExternalResource {
tomcat = new Tomcat();
tomcat.setBaseDir( dataDir.getAbsolutePath() );
tomcat.setPort( port );
+ tomcat.getConnector().setAttribute("maxThreads", "1500");
tomcat.addWebapp( "/", new File( getWebAppsPath() ).getAbsolutePath() );
log.info("-----------------------------------------------------------------");
@@ -202,6 +203,8 @@ public class TomcatResource extends ExternalResource {
tomcat.start();
waitForTomcat();
+
+ mutex.notifyAll();
}
@@ -277,6 +280,8 @@ public class TomcatResource extends ExternalResource {
}
} );
+ mutex.notifyAll();
+
return p;
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6e100761/stack/rest/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/resources/log4j.properties b/stack/rest/src/test/resources/log4j.properties
index 94db6d5..d560b56 100644
--- a/stack/rest/src/test/resources/log4j.properties
+++ b/stack/rest/src/test/resources/log4j.properties
@@ -54,7 +54,7 @@ log4j.logger.org.apache.usergrid.rest.filters.MeteringFilter=ERROR
#log4j.logger.org.apache.usergrid.services=DEBUG
#log4j.logger.org.apache.cassandra.service.StorageProxy=DEBUG, stdout
-log4j.logger.org.apache.usergrid.rest=DEBUG
+#log4j.logger.org.apache.usergrid.rest=DEBUG
#log4j.logger.org.apache.usergrid.cassandra.CassandraResource=DEBUG
#log4j.logger.org.apache.usergrid.rest.TomcatResource=INFO
#log4j.logger.org.apache.usergrid.rest=INFO
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6e100761/stack/rest/src/test/resources/usergrid-custom-test.properties
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/resources/usergrid-custom-test.properties b/stack/rest/src/test/resources/usergrid-custom-test.properties
index ebd5740..37d2423 100644
--- a/stack/rest/src/test/resources/usergrid-custom-test.properties
+++ b/stack/rest/src/test/resources/usergrid-custom-test.properties
@@ -11,6 +11,6 @@ elasticsearch.force_refresh=true
tomcat.startup=embedded
-elasticsearch.startup=embedded
+elasticsearch.startup=forked
-cassandra.use_remote=false
+cassandra.startup=forked
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6e100761/stack/test-utils/src/main/java/org/apache/usergrid/TomcatMain.java
----------------------------------------------------------------------
diff --git a/stack/test-utils/src/main/java/org/apache/usergrid/TomcatMain.java b/stack/test-utils/src/main/java/org/apache/usergrid/TomcatMain.java
index 371cae9..d575bc7 100644
--- a/stack/test-utils/src/main/java/org/apache/usergrid/TomcatMain.java
+++ b/stack/test-utils/src/main/java/org/apache/usergrid/TomcatMain.java
@@ -40,7 +40,7 @@ public class TomcatMain {
Tomcat tomcat = new Tomcat();
tomcat.setBaseDir(dataDir.getAbsolutePath());
tomcat.setPort(port);
- tomcat.getConnector().setAttribute("maxThreads", "600");
+ tomcat.getConnector().setAttribute("maxThreads", "1000");
tomcat.addWebapp("/", new File(webappsPath).getAbsolutePath());
log.info("-----------------------------------------------------------------");
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6e100761/stack/test-utils/src/main/java/org/apache/usergrid/cassandra/CassandraMain.java
----------------------------------------------------------------------
diff --git a/stack/test-utils/src/main/java/org/apache/usergrid/cassandra/CassandraMain.java b/stack/test-utils/src/main/java/org/apache/usergrid/cassandra/CassandraMain.java
new file mode 100644
index 0000000..fc7d1bc
--- /dev/null
+++ b/stack/test-utils/src/main/java/org/apache/usergrid/cassandra/CassandraMain.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2014 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.cassandra;
+
+import org.apache.cassandra.service.CassandraDaemon;
+import static org.apache.usergrid.cassandra.CassandraResource.LOG;
+import static org.apache.usergrid.cassandra.CassandraResource.NATIVE_TRANSPORT_PORT_KEY;
+import static org.apache.usergrid.cassandra.CassandraResource.RPC_PORT_KEY;
+import static org.apache.usergrid.cassandra.CassandraResource.SSL_STORAGE_PORT_KEY;
+import static org.apache.usergrid.cassandra.CassandraResource.STORAGE_PORT_KEY;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Simple wrapper for starting "embedded" Tomcat as it's own process, for testing.
+ */
+public class CassandraMain {
+
+ private static final Logger log = LoggerFactory.getLogger( CassandraMain.class );
+
+ public static void main(String[] args) throws Exception {
+
+ String yamlFileName = args[0];
+ String tmpDirName = args[1];
+ String log4jConfig = args[2];
+ int rpcPort = Integer.parseInt( args[3] );
+ int storagePort = Integer.parseInt( args[4] );
+ int sslStoragePort = Integer.parseInt( args[5] );
+ int nativeTransportPort = Integer.parseInt( args[6] );
+
+ System.setProperty( "cassandra." + RPC_PORT_KEY, Integer.toString( rpcPort ) );
+ System.setProperty( "cassandra." + STORAGE_PORT_KEY, Integer.toString( storagePort ) );
+ System.setProperty( "cassandra." + SSL_STORAGE_PORT_KEY, Integer.toString( sslStoragePort ) );
+ System.setProperty( "cassandra." + NATIVE_TRANSPORT_PORT_KEY, Integer.toString( nativeTransportPort ) );
+
+ System.setProperty( "cassandra.url", "localhost:" + Integer.toString( rpcPort ) );
+ System.setProperty( "cassandra-foreground", "true" );
+ System.setProperty( "log4j.defaultInitOverride", "true" );
+ System.setProperty( "log4j.configuration", "file:" + log4jConfig );
+ System.setProperty( "cassandra.ring_delay_ms", "100" );
+ System.setProperty( "cassandra.config", yamlFileName );
+ System.setProperty( "cassandra.tempName", tmpDirName );
+
+ LOG.info("Starting forked Cassandra: test, setting system properties for ports : "
+ + "[rpc, storage, sslStoage, native] = [{}, {}, {}, {}]",
+ new Object[] {rpcPort, storagePort, sslStoragePort, nativeTransportPort});
+
+ CassandraDaemon cassandraDaemon = new CassandraDaemon();
+ cassandraDaemon.activate();
+
+ while ( true ) {
+ Thread.sleep(1000);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6e100761/stack/test-utils/src/main/java/org/apache/usergrid/cassandra/CassandraResource.java
----------------------------------------------------------------------
diff --git a/stack/test-utils/src/main/java/org/apache/usergrid/cassandra/CassandraResource.java b/stack/test-utils/src/main/java/org/apache/usergrid/cassandra/CassandraResource.java
index 057d328..118534a 100644
--- a/stack/test-utils/src/main/java/org/apache/usergrid/cassandra/CassandraResource.java
+++ b/stack/test-utils/src/main/java/org/apache/usergrid/cassandra/CassandraResource.java
@@ -17,10 +17,14 @@
package org.apache.usergrid.cassandra;
+import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -34,6 +38,7 @@ import org.yaml.snakeyaml.Yaml;
import org.apache.cassandra.service.CassandraDaemon;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.RandomStringUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.RandomUtils;
@@ -90,20 +95,26 @@ public class CassandraResource extends ExternalResource {
private static CassandraResource instance;
private Thread shutdown;
+ private Process process = null;
+
+ private boolean forkCassandra = false;
+
/**
- * Creates a Cassandra starting ExternalResource for JUnit test cases which uses the default SchemaManager for
- * Cassandra.
+ * Creates a Cassandra starting ExternalResource for JUnit test cases which uses the
+ * default SchemaManager for Cassandra.
*/
@SuppressWarnings("UnusedDeclaration")
CassandraResource() throws IOException {
- this( null, DEFAULT_RPC_PORT, DEFAULT_STORAGE_PORT, DEFAULT_SSL_STORAGE_PORT, DEFAULT_NATIVE_TRANSPORT_PORT );
+ this( null, DEFAULT_RPC_PORT, DEFAULT_STORAGE_PORT, DEFAULT_SSL_STORAGE_PORT,
+ DEFAULT_NATIVE_TRANSPORT_PORT );
+
}
/**
- * Creates a Cassandra starting ExternalResource for JUnit test cases which uses the specified SchemaManager for
- * Cassandra.
+ * Creates a Cassandra starting ExternalResource for JUnit test cases which uses the
+ * specified SchemaManager for Cassandra.
*/
CassandraResource( String schemaManagerName, int rpcPort, int storagePort, int sslStoragePort,
int nativeTransportPort ) {
@@ -123,12 +134,25 @@ public class CassandraResource extends ExternalResource {
LOG.error( "Failed to create temporary directory for Cassandra instance.", e );
throw new RuntimeException( e );
}
+
+ try {
+ String[] locations = { "usergrid-properties-context.xml" };
+ ConfigurableApplicationContext appContext =
+ new ClassPathXmlApplicationContext( locations );
+
+ Properties properties = (Properties)appContext.getBean("properties");
+ String forkString = properties.getProperty("cassandra.startup");
+ forkCassandra = "forked".equals( forkString );
+
+ } catch (Exception ex) {
+ throw new RuntimeException("Error getting properties", ex);
+ }
}
/**
- * Creates a Cassandra starting ExternalResource for JUnit test cases which uses the specified SchemaManager for
- * Cassandra.
+ * Creates a Cassandra starting ExternalResource for JUnit test cases which uses the specified
+ * SchemaManager for Cassandra.
*/
public CassandraResource( int rpcPort, int storagePort, int sslStoragePort, int nativeTransportPort ) throws IOException {
this( null, rpcPort, storagePort, sslStoragePort, nativeTransportPort );
@@ -221,7 +245,6 @@ public class CassandraResource extends ExternalResource {
@Override
public String toString() {
-
return "\n" + "cassandra.yaml = " + new File(tempDir, "cassandra.yaml") + "\n" + RPC_PORT_KEY + " = " + rpcPort + "\n" + STORAGE_PORT_KEY + " = " + storagePort + "\n" + SSL_STORAGE_PORT_KEY + " = " + sslStoragePort + "\n" + NATIVE_TRANSPORT_PORT_KEY + " = " + nativeTransportPort + "\n" + DATA_FILE_DIR_KEY + " = " + new File(tempDir, "data").toString() + "\n" + COMMIT_FILE_DIR_KEY + " = " + new File(tempDir, "commitlog").toString() + "\n" + SAVED_CACHES_DIR_KEY + " = " + new File(tempDir, "saved_caches").toString() + "\n";
}
@@ -263,86 +286,227 @@ public class CassandraResource extends ExternalResource {
return;
}
- LOG.info( "-------------------------------------------------------------------");
- LOG.info( "Initializing Embedded Cassandra at {} ...", tempDir.toString() );
- LOG.info( "-------------------------------------------------------------------");
-
- // Create temp directory, setup to create new File configuration there
- File newYamlFile = new File( tempDir, "cassandra.yaml" );
- URL newYamlUrl = FileUtils.toURLs( new File[] { newYamlFile } )[0];
-
- // Read the original yaml file, make changes, and dump to new position in tmpdir
- Yaml yaml = new Yaml();
- @SuppressWarnings("unchecked") Map<String, Object> map =
- ( Map<String, Object> ) yaml.load( ClassLoader.getSystemResourceAsStream( "cassandra.yaml" ) );
- map.put( RPC_PORT_KEY, getRpcPort() );
- map.put( STORAGE_PORT_KEY, getStoragePort() );
- map.put( SSL_STORAGE_PORT_KEY, getSslStoragePort() );
- map.put( NATIVE_TRANSPORT_PORT_KEY, getNativeTransportPort() );
- map.put( COMMIT_FILE_DIR_KEY, new File( tempDir, "commitlog" ).toString() );
- map.put( DATA_FILE_DIR_KEY, new String[] { new File( tempDir, "data" ).toString() } );
- map.put( SAVED_CACHES_DIR_KEY, new File( tempDir, "saved_caches" ).toString() );
- FileWriter writer = new FileWriter( newYamlFile );
- yaml.dump( map, writer );
- writer.flush();
- writer.close();
-
- // Fire up Cassandra by setting configuration to point to new yaml file
- System.setProperty( "cassandra.url", "localhost:" + Integer.toString( rpcPort ) );
- System.setProperty( "cassandra-foreground", "true" );
- System.setProperty( "log4j.defaultInitOverride", "true" );
- System.setProperty( "log4j.configuration", "log4j.properties" );
- System.setProperty( "cassandra.ring_delay_ms", "100" );
- System.setProperty( "cassandra.config", newYamlUrl.toString() );
- System.setProperty( "cassandra.tempName", tempDir.getName() );
+ startCassandraForked();
+ }
+ }
-
- //while ( !AvailablePortFinder.available( rpcPort ) || rpcPort == 9042 ) {
- // why previously has a or condition of rpc == 9042?
- while ( !AvailablePortFinder.available( rpcPort ) ) {
- rpcPort++;
- }
-
- while ( !AvailablePortFinder.available( storagePort ) ) {
- storagePort++;
- }
-
- while ( !AvailablePortFinder.available( sslStoragePort ) ) {
- sslStoragePort++;
+ private void startCassandraEmbedded() throws Throwable {
+
+ LOG.info( "-------------------------------------------------------------------");
+ LOG.info( "Initializing Embedded Cassandra at {} ...", tempDir.toString() );
+ LOG.info( "-------------------------------------------------------------------");
+
+ // Create temp directory, setup to create new File configuration there
+ File newYamlFile = new File( tempDir, "cassandra.yaml" );
+ URL newYamlUrl = FileUtils.toURLs( new File[] { newYamlFile } )[0];
+
+ // Read the original yaml file, make changes, and dump to new position in tmpdir
+ Yaml yaml = new Yaml();
+ @SuppressWarnings("unchecked") Map<String, Object> map =
+ ( Map<String, Object> ) yaml.load( ClassLoader.getSystemResourceAsStream( "cassandra.yaml" ) );
+ map.put( RPC_PORT_KEY, getRpcPort() );
+ map.put( STORAGE_PORT_KEY, getStoragePort() );
+ map.put( SSL_STORAGE_PORT_KEY, getSslStoragePort() );
+ map.put( NATIVE_TRANSPORT_PORT_KEY, getNativeTransportPort() );
+ map.put( COMMIT_FILE_DIR_KEY, new File( tempDir, "commitlog" ).toString() );
+ map.put( DATA_FILE_DIR_KEY, new String[] { new File( tempDir, "data" ).toString() } );
+ map.put( SAVED_CACHES_DIR_KEY, new File( tempDir, "saved_caches" ).toString() );
+ FileWriter writer = new FileWriter( newYamlFile );
+ yaml.dump( map, writer );
+ writer.flush();
+ writer.close();
+
+ // Fire up Cassandra by setting configuration to point to new yaml file
+ System.setProperty( "cassandra.url", "localhost:" + Integer.toString( rpcPort ) );
+ System.setProperty( "cassandra-foreground", "true" );
+ System.setProperty( "log4j.defaultInitOverride", "true" );
+ System.setProperty( "log4j.configuration", "log4j.properties" );
+ System.setProperty( "cassandra.ring_delay_ms", "100" );
+ System.setProperty( "cassandra.config", newYamlUrl.toString() );
+ System.setProperty( "cassandra.tempName", tempDir.getName() );
+
+
+ //while ( !AvailablePortFinder.available( rpcPort ) || rpcPort == 9042 ) {
+ // why previously has a or condition of rpc == 9042?
+ while ( !AvailablePortFinder.available( rpcPort ) ) {
+ rpcPort++;
+ }
+
+ while ( !AvailablePortFinder.available( storagePort ) ) {
+ storagePort++;
+ }
+
+ while ( !AvailablePortFinder.available( sslStoragePort ) ) {
+ sslStoragePort++;
+ }
+
+ while ( !AvailablePortFinder.available( nativeTransportPort ) ) {
+ nativeTransportPort++;
+ }
+
+ System.setProperty( "cassandra." + RPC_PORT_KEY, Integer.toString( rpcPort ) );
+ System.setProperty( "cassandra." + STORAGE_PORT_KEY, Integer.toString( storagePort ) );
+ System.setProperty( "cassandra." + SSL_STORAGE_PORT_KEY, Integer.toString( sslStoragePort ) );
+ System.setProperty( "cassandra." + NATIVE_TRANSPORT_PORT_KEY, Integer.toString( nativeTransportPort ) );
+
+ LOG.info("before() test, setting system properties for ports : "
+ + "[rpc, storage, sslStoage, native] = [{}, {}, {}, {}]",
+ new Object[] {rpcPort, storagePort, sslStoragePort, nativeTransportPort});
+ if ( !newYamlFile.exists() ) {
+ throw new RuntimeException( "Cannot find new Yaml file: " + newYamlFile );
+ }
+
+ cassandraDaemon = new CassandraDaemon();
+ cassandraDaemon.activate();
+
+ Runtime.getRuntime().addShutdownHook( new Thread() {
+ @Override
+ public void run() {
+ after();
}
-
- while ( !AvailablePortFinder.available( nativeTransportPort ) ) {
- nativeTransportPort++;
+ } );
+
+ String[] locations = { "usergrid-test-context.xml" };
+ applicationContext = new ClassPathXmlApplicationContext( locations );
+
+ loadSchemaManager( schemaManagerName );
+ initialized = true;
+ LOG.info( "External Cassandra resource at {} is ready!", tempDir.toString() );
+ lock.notifyAll();
+ }
+
+
+ private void startCassandraForked() throws Throwable {
+
+ LOG.info( "-------------------------------------------------------------------");
+ LOG.info( "Initializing Forked Cassandra at {} ...", tempDir.toString() );
+ LOG.info( "-------------------------------------------------------------------");
+
+ // Create temp directory, setup to create new File configuration there
+ File newYamlFile = new File( tempDir, "cassandra.yaml" );
+ URL newYamlUrl = FileUtils.toURLs( new File[] { newYamlFile } )[0];
+
+ // Read the original yaml file, make changes, and dump to new position in tmpdir
+ Yaml yaml = new Yaml();
+ @SuppressWarnings("unchecked") Map<String, Object> map =
+ ( Map<String, Object> ) yaml.load( ClassLoader.getSystemResourceAsStream( "cassandra.yaml" ) );
+ map.put( RPC_PORT_KEY, getRpcPort() );
+ map.put( STORAGE_PORT_KEY, getStoragePort() );
+ map.put( SSL_STORAGE_PORT_KEY, getSslStoragePort() );
+ map.put( NATIVE_TRANSPORT_PORT_KEY, getNativeTransportPort() );
+ map.put( COMMIT_FILE_DIR_KEY, new File( tempDir, "commitlog" ).toString() );
+ map.put( DATA_FILE_DIR_KEY, new String[] { new File( tempDir, "data" ).toString() } );
+ map.put( SAVED_CACHES_DIR_KEY, new File( tempDir, "saved_caches" ).toString() );
+ FileWriter writer = new FileWriter( newYamlFile );
+ yaml.dump( map, writer );
+ writer.flush();
+ writer.close();
+
+ // Fire up Cassandra by setting configuration to point to new yaml file
+ System.setProperty( "cassandra.url", "localhost:" + Integer.toString( rpcPort ) );
+ System.setProperty( "cassandra-foreground", "true" );
+ System.setProperty( "log4j.defaultInitOverride", "true" );
+ System.setProperty( "log4j.configuration", "log4j.properties" );
+ System.setProperty( "cassandra.ring_delay_ms", "100" );
+ System.setProperty( "cassandra.config", newYamlUrl.toString() );
+ System.setProperty( "cassandra.tempName", tempDir.getName() );
+
+
+ //while ( !AvailablePortFinder.available( rpcPort ) || rpcPort == 9042 ) {
+ // why previously has a or condition of rpc == 9042?
+ while ( !AvailablePortFinder.available( rpcPort ) ) {
+ rpcPort++;
+ }
+
+ while ( !AvailablePortFinder.available( storagePort ) ) {
+ storagePort++;
+ }
+
+ while ( !AvailablePortFinder.available( sslStoragePort ) ) {
+ sslStoragePort++;
+ }
+
+ while ( !AvailablePortFinder.available( nativeTransportPort ) ) {
+ nativeTransportPort++;
+ }
+
+ System.setProperty( "cassandra." + RPC_PORT_KEY, Integer.toString( rpcPort ) );
+ System.setProperty( "cassandra." + STORAGE_PORT_KEY, Integer.toString( storagePort ) );
+ System.setProperty( "cassandra." + SSL_STORAGE_PORT_KEY, Integer.toString( sslStoragePort ) );
+ System.setProperty( "cassandra." + NATIVE_TRANSPORT_PORT_KEY, Integer.toString( nativeTransportPort ) );
+
+ LOG.info("before() test, setting system properties for ports : "
+ + "[rpc, storage, sslStoage, native] = [{}, {}, {}, {}]",
+ new Object[] {rpcPort, storagePort, sslStoragePort, nativeTransportPort});
+
+ if ( !newYamlFile.exists() ) {
+ throw new RuntimeException( "Cannot find new Yaml file: " + newYamlFile );
+ }
+
+ String javaHome = (String)System.getenv("JAVA_HOME");
+
+ String maxMemory = "-Xmx1000m";
+
+ ProcessBuilder pb = new ProcessBuilder(javaHome + "/bin/java", maxMemory,
+ "org.apache.usergrid.cassandra.CassandraMain",
+ newYamlUrl.toString(), tempDir.getName(),
+ getTargetDir() + "/src/test/resources/log4j.properties",
+ ""+rpcPort, ""+storagePort, ""+sslStoragePort, ""+nativeTransportPort );
+
+ // ensure Cassandra gets same classpath we have, but with...
+ String classpath = System.getProperty("java.class.path");
+ List<String> path = new ArrayList<String>();
+
+ String parts[] = classpath.split( File.pathSeparator );
+ for ( String part : parts ) {
+ if ( part.endsWith("test-classes") ) {
+ continue;
}
+ path.add(part);
+ }
+ String newClasspath = StringUtils.join( path, File.pathSeparator );
+
+ Map<String, String> env = pb.environment();
+ StringBuilder sb = new StringBuilder();
+ sb.append( newClasspath );
+ env.put("CLASSPATH", sb.toString());
- System.setProperty( "cassandra." + RPC_PORT_KEY, Integer.toString( rpcPort ) );
- System.setProperty( "cassandra." + STORAGE_PORT_KEY, Integer.toString( storagePort ) );
- System.setProperty( "cassandra." + SSL_STORAGE_PORT_KEY, Integer.toString( sslStoragePort ) );
- System.setProperty( "cassandra." + NATIVE_TRANSPORT_PORT_KEY, Integer.toString( nativeTransportPort ) );
+ pb.redirectErrorStream(true);
- LOG.info("before() test, setting system properties for ports : [rpc, storage, sslStoage, native] = [{}, {}, {}, {}]", new Object[] {rpcPort, storagePort, sslStoragePort, nativeTransportPort});
- if ( !newYamlFile.exists() ) {
- throw new RuntimeException( "Cannot find new Yaml file: " + newYamlFile );
+ process = pb.start();
+
+ // use thread to log Cassandra output
+ new Thread( new Runnable() {
+ @Override
+ public void run() {
+ BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ String line = null;
+ try {
+ while ((line = br.readLine()) != null) {
+ LOG.info(line);
+ }
+
+ } catch (Exception ex) {
+ LOG.error("Error reading from Cassandra process", ex);
+ return;
+ }
}
-
- cassandraDaemon = new CassandraDaemon();
- cassandraDaemon.activate();
+ }).start();
- Runtime.getRuntime().addShutdownHook( new Thread() {
- @Override
- public void run() {
- after();
- }
- } );
+ Runtime.getRuntime().addShutdownHook( new Thread() {
+ @Override
+ public void run() {
+ after();
+ }
+ } );
- String[] locations = { "usergrid-test-context.xml" };
- applicationContext = new ClassPathXmlApplicationContext( locations );
+ String[] locations = { "usergrid-test-context.xml" };
+ applicationContext = new ClassPathXmlApplicationContext( locations );
- loadSchemaManager( schemaManagerName );
- initialized = true;
- LOG.info( "External Cassandra resource at {} is ready!", tempDir.toString() );
- lock.notifyAll();
- }
+ loadSchemaManager( schemaManagerName );
+ initialized = true;
+ LOG.info( "External Cassandra resource at {} is ready!", tempDir.toString() );
+ lock.notifyAll();
}
@@ -351,46 +515,49 @@ public class CassandraResource extends ExternalResource {
protected synchronized void after() {
super.after();
- shutdown = new Thread() {
- @Override
- public void run() {
- try {
- Thread.currentThread().sleep( 100L );
- }
- catch ( InterruptedException e ) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
-
- LOG.info( "Shutting down Cassandra instance in {}", tempDir.toString() );
-
- if ( schemaManager != null ) {
- LOG.info( "Destroying schemaManager..." );
+ if ( process != null ) {
+ process.destroy();
+ }
+ else {
+ shutdown = new Thread() {
+ @Override
+ public void run() {
try {
- schemaManager.destroy();
- }
- catch ( Exception e ) {
- LOG.error( "Ignoring failures while dropping keyspaces: {}", e.getMessage() );
+ Thread.currentThread().sleep( 100L );
}
+ catch ( InterruptedException ignored ) {}
- LOG.info( "SchemaManager destroyed..." );
- }
+ LOG.info( "Shutting down Cassandra instance in {}", tempDir.toString() );
- applicationContext.stop();
- LOG.info( "ApplicationContext stopped..." );
+ if ( schemaManager != null ) {
+ LOG.info( "Destroying schemaManager..." );
+ try {
+ schemaManager.destroy();
+ }
+ catch ( Exception e ) {
+ LOG.error( "Ignoring failures while dropping keyspaces: {}", e.getMessage() );
+ }
- try {
- if ( cassandraDaemon != null ) {
- LOG.info( "Deactivating CassandraDaemon..." );
- cassandraDaemon.deactivate();
+ LOG.info( "SchemaManager destroyed..." );
+ }
+
+ applicationContext.stop();
+ LOG.info( "ApplicationContext stopped..." );
+
+ try {
+ if ( cassandraDaemon != null ) {
+ LOG.info( "Deactivating CassandraDaemon..." );
+ cassandraDaemon.deactivate();
+ }
+ }
+ catch ( Exception ex ) {
+ LOG.error("Error deactivating Cassandra", ex);
}
}
- catch ( Exception ex ) {
- ex.printStackTrace();
- }
- }
- };
+ };
- shutdown.start();
+ shutdown.start();
+ }
}
@@ -505,4 +672,12 @@ public class CassandraResource extends ExternalResource {
return tmpdir;
}
+
+
+ public static String getTargetDir() throws IOException {
+ Properties props = new Properties();
+ props.load( ClassLoader.getSystemResourceAsStream( PROPERTIES_FILE ) );
+ File basedir = new File( ( String ) props.get( TARGET_DIRECTORY_KEY ) );
+ return basedir.getAbsolutePath();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6e100761/stack/test-utils/src/test/resources/usergrid-custom-test.properties
----------------------------------------------------------------------
diff --git a/stack/test-utils/src/test/resources/usergrid-custom-test.properties b/stack/test-utils/src/test/resources/usergrid-custom-test.properties
new file mode 100644
index 0000000..5a57091
--- /dev/null
+++ b/stack/test-utils/src/test/resources/usergrid-custom-test.properties
@@ -0,0 +1,2 @@
+
+cassandra.startup=forked
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6e100761/stack/test-utils/src/test/resources/usergrid-properties-context.xml
----------------------------------------------------------------------
diff --git a/stack/test-utils/src/test/resources/usergrid-properties-context.xml b/stack/test-utils/src/test/resources/usergrid-properties-context.xml
new file mode 100644
index 0000000..fd4d012
--- /dev/null
+++ b/stack/test-utils/src/test/resources/usergrid-properties-context.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
+
+ <bean id="properties"
+ class="org.springframework.beans.factory.config.PropertiesFactoryBean">
+ <property name="singleton" value="true" />
+ <property name="ignoreResourceNotFound" value="true" />
+ <property name="locations">
+ <list>
+ <value>classpath:/usergrid-default.properties</value>
+ <value>classpath:/usergrid-test.properties</value>
+ <value>classpath:/usergrid-custom-test.properties</value>
+ </list>
+ </property>
+ </bean>
+
+</beans>