You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2014/11/11 00:49:41 UTC

incubator-usergrid git commit: Removed unused code and made cassandra resource completely external

Repository: incubator-usergrid
Updated Branches:
  refs/heads/es-type-updates-ryan-external e16dd43db -> a103e7d71


Removed unused code and made cassandra resource completely external


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

Branch: refs/heads/es-type-updates-ryan-external
Commit: a103e7d713b718730479eb25143574150913dd3b
Parents: e16dd43
Author: Todd Nine <tn...@apigee.com>
Authored: Mon Nov 10 16:49:34 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Mon Nov 10 16:49:34 2014 -0700

----------------------------------------------------------------------
 .../usergrid/cassandra/CassandraResource.java   | 518 +++++--------------
 1 file changed, 134 insertions(+), 384 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a103e7d7/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 401e026..3de0144 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,15 +17,8 @@
 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;
 
 import org.junit.rules.ExternalResource;
@@ -33,30 +26,22 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
-import org.springframework.core.env.PropertySource;
-import org.yaml.snakeyaml.Yaml;
-import org.apache.cassandra.service.CassandraDaemon;
+
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.RandomStringUtils;
-import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.math.RandomUtils;
 
+
 /**
  * A JUnit {@link org.junit.rules.ExternalResource} designed to start up Cassandra once in a TestSuite or test Class as
- * a shared external resource across test cases and shut it down after the TestSuite has completed.
- * <p/>
- * This external resource is completely isolated in terms of the files used and the ports selected if the {@link
- * AvailablePortFinder} is used with it.
- * <p/>
- * Note that for this resource to work properly, a project.properties file must be placed in the src/test/resources
- * directory with the following stanza in the project pom's build section:
- * <p/>
- * <testResources> <testResource> <directory>src/test/resources</directory> <filtering>true</filtering> <includes>
- * <include>**\/*.properties</include> <include>**\/*.xml</include> </includes> </testResource> </testResources>
- * <p/>
- * The following property expansion macro should be placed in this project.properties file:
- * <p/>
+ * a shared external resource across test cases and shut it down after the TestSuite has completed. <p/> This external
+ * resource is completely isolated in terms of the files used and the ports selected if the {@link AvailablePortFinder}
+ * is used with it. <p/> Note that for this resource to work properly, a project.properties file must be placed in the
+ * src/test/resources directory with the following stanza in the project pom's build section: <p/> <testResources>
+ * <testResource> <directory>src/test/resources</directory> <filtering>true</filtering> <includes>
+ * <include>**\/*.properties</include> <include>**\/*.xml</include> </includes> </testResource> </testResources> <p/>
+ * The following property expansion macro should be placed in this project.properties file: <p/>
  * target.directory=${pom.build.directory}
  *
  * TODO this class does 2 things.  It loads spring and starts cassandra.  We should separate these concerns.
@@ -93,34 +78,27 @@ public class CassandraResource extends ExternalResource {
     private int nativeTransportPort = DEFAULT_NATIVE_TRANSPORT_PORT;
 
     private ConfigurableApplicationContext applicationContext;
-    private CassandraDaemon cassandraDaemon;
     private SchemaManager schemaManager;
 
     private static CassandraResource instance;
     private Thread shutdown;
 
-    private Process process = null;
-
     private static Properties properties = null;
 
-    private boolean forkCassandra = false;
-    private boolean externalCassandra = 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")
+    @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 ) {
@@ -143,27 +121,24 @@ public class CassandraResource extends ExternalResource {
 
         try {
             String[] locations = { "usergrid-properties-context.xml" };
-            ConfigurableApplicationContext appContext = 
-                    new ClassPathXmlApplicationContext( locations );
-            
-            Properties properties = (Properties)appContext.getBean("properties");
-            properties.putAll(ArrayUtils.toMap(this.getProjectProperties().entrySet().toArray(new Object[]{})));
-            String forkString = properties.getProperty("cassandra.startup");
-            forkCassandra = "forked".equals( forkString );
-            externalCassandra = "external".equals( forkString );
-
-        } catch (Exception ex) {
-            throw new RuntimeException("Error getting properties", ex);
+            ConfigurableApplicationContext appContext = new ClassPathXmlApplicationContext( locations );
+
+            Properties properties = ( Properties ) appContext.getBean( "properties" );
+            properties.putAll( ArrayUtils.toMap( this.getProjectProperties().entrySet().toArray( new Object[] { } ) ) );
+            String forkString = properties.getProperty( "cassandra.startup" );
+        }
+        catch ( Exception ex ) {
+            throw new RuntimeException( "Error getting properties", ex );
         }
-//        throw new RuntimeException("My debugging skills are terrible!");
     }
 
 
     /**
-     * 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 {
+    public CassandraResource( int rpcPort, int storagePort, int sslStoragePort, int nativeTransportPort )
+            throws IOException {
         this( null, rpcPort, storagePort, sslStoragePort, nativeTransportPort );
     }
 
@@ -208,7 +183,7 @@ public class CassandraResource extends ExternalResource {
      *
      * @return the temporary directory
      */
-    @SuppressWarnings("UnusedDeclaration")
+    @SuppressWarnings( "UnusedDeclaration" )
     public File getTemporaryDirectory() {
         return tempDir;
     }
@@ -254,7 +229,12 @@ 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";
+        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";
     }
 
 
@@ -294,318 +274,84 @@ public class CassandraResource extends ExternalResource {
             if ( isReady() ) {
                 return;
             }
-            
-//            if ( forkCassandra ) {
-//                startCassandraForked();
-//            } else if (externalCassandra) {
-//              startCassandraExternal();
-//            }else {
-//
-//                startCassandraEmbedded();
-//            }
-        }
-    }
-    private void addShutdownHook(){
-        Runtime.getRuntime().addShutdownHook( new Thread() {
-            @Override
-            public void run() {
-                after();
-            }
-        } );
-
-    }
-    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 ) );
+            startCassandraExternal();
 
-        LOG.info("before() test, setting system properties for ports : "
-                + "[rpc, storage, sslStorage, native] = [{}, {}, {}, {}]", 
-                new Object[] {rpcPort, storagePort, sslStoragePort, nativeTransportPort});
-        if ( !newYamlFile.exists() ) {
-            throw new RuntimeException( "Cannot find new Yaml file: " + newYamlFile );
+            //            if ( forkCassandra ) {
+            //                startCassandraForked();
+            //            } else if (externalCassandra) {
+            //
+            //            }else {
+            //
+            //                startCassandraEmbedded();
+            //            }
         }
-        
-        cassandraDaemon = new CassandraDaemon();
-        cassandraDaemon.activate();
-
-//        Runtime.getRuntime().addShutdownHook( new Thread() {
-//            @Override
-//            public void run() {
-//                after();
-//            }
-//        } );
-        addShutdownHook();
-        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, sslStorage, 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", 
-                getJammArgument(), 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());
-
-        pb.redirectErrorStream(true);
-
-        process = pb.start();
-
-        // use thread to log Cassandra output
-        new Thread( new Runnable() {
+    private void addShutdownHook() {
+        Runtime.getRuntime().addShutdownHook( new Thread() {
             @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;
-                } 
+                after();
             }
-        }).start();
-
-//        Runtime.getRuntime().addShutdownHook( new Thread() {
-//            @Override
-//            public void run() {
-//                after();
-//            }
-//        } );
-        addShutdownHook();
-        // give C* time to start
-        Thread.sleep(5000);
+        } );
+    }
 
-        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 startCassandraExternal() throws Throwable {
-        LOG.info( "-------------------------------------------------------------------");
-        LOG.info( "Initializing External Cassandra");
-        LOG.info( "-------------------------------------------------------------------");
-        LOG.info("before() test, setting system properties for ports : "
-                + "[rpc, storage, sslStorage, native] = [{}, {}, {}, {}]", 
-                new Object[] {rpcPort, storagePort, sslStoragePort, nativeTransportPort});
-        Thread.sleep(5000);
+        LOG.info( "-------------------------------------------------------------------" );
+        LOG.info( "Initializing External Cassandra" );
+        LOG.info( "-------------------------------------------------------------------" );
+        LOG.info( "before() test, setting system properties for ports : "
+                        + "[rpc, storage, sslStorage, native] = [{}, {}, {}, {}]",
+                new Object[] { rpcPort, storagePort, sslStoragePort, nativeTransportPort } );
+        Thread.sleep( 5000 );
         String[] locations = { "usergrid-test-context.xml" };
         applicationContext = new ClassPathXmlApplicationContext( locations );
-//        PropertySource ps=new PropertySource<String>();
-//        applicationContext.getEnvironment().getPropertySources().addLast(ps);
         applicationContext.refresh();
         loadSchemaManager( schemaManagerName );
         initialized = true;
-        
+
         LOG.info( "External Cassandra resource at {} is ready!", tempDir.toString() );
         lock.notifyAll();
-      
     }
 
+
     /** Stops Cassandra after a TestSuite or test Class executes. */
     @Override
     protected synchronized void after() {
         super.after();
-        if ( process != null ) {
-            process.destroy();
-        }
-        else { 
-            shutdown = new Thread() {
-                @Override
-                public void run() {
-                    try {
-                        Thread.currentThread();
-            Thread.sleep( 100L );
-                    }
-                    catch ( InterruptedException ignored ) {}
-                    if(externalCassandra){
-                        LOG.info( "Cleaning up external Cassandra instance");
-                    }else{
-                        LOG.info( "Shutting down Cassandra instance in {}", tempDir.toString() );
-                    }
-
-                    if ( schemaManager != null ) {
-                        LOG.info( "Destroying schemaManager..." );
-                        try {
-                            schemaManager.destroy();
-                        }
-                        catch ( Exception e ) {
-                            LOG.error( "Ignoring failures while dropping keyspaces: {}", e.getMessage() );
-                        }
 
-                        LOG.info( "SchemaManager destroyed..." );
-                    }
+        shutdown = new Thread() {
+            @Override
+            public void run() {
+                try {
+                    Thread.currentThread();
+                    Thread.sleep( 100L );
+                }
+                catch ( InterruptedException ignored ) {
+                }
 
-                    applicationContext.stop();
-                    LOG.info( "ApplicationContext stopped..." );
 
+                if ( schemaManager != null ) {
+                    LOG.info( "Destroying schemaManager..." );
                     try {
-                        if ( !externalCassandra && cassandraDaemon != null ) {
-                            LOG.info( "Deactivating CassandraDaemon..." );
-                            cassandraDaemon.deactivate();
-                        }
+                        schemaManager.destroy();
                     }
-                    catch ( Exception ex ) {
-                        LOG.error("Error deactivating Cassandra", ex);
+                    catch ( Exception e ) {
+                        LOG.error( "Ignoring failures while dropping keyspaces: {}", e.getMessage() );
                     }
+
+                    LOG.info( "SchemaManager destroyed..." );
                 }
-            };
 
-            shutdown.start();
-        }
+                applicationContext.stop();
+                LOG.info( "ApplicationContext stopped..." );
+            }
+        };
+
+        shutdown.start();
     }
 
 
@@ -670,58 +416,63 @@ public class CassandraResource extends ExternalResource {
                 sslStoragePort = AvailablePortFinder.getNextAvailable( sslStoragePort );
             }
 
-            instance = new CassandraResource( 
-                schemaManagerName, rpcPort, storagePort, sslStoragePort, nativeTransportPort );
+            instance = new CassandraResource( schemaManagerName, rpcPort, storagePort, sslStoragePort,
+                    nativeTransportPort );
 
-            LOG.info("Created a new instance of CassandraResource: {}", instance);
-            LOG.info("Cassandra using ports {} and {}", storagePort, sslStoragePort);
+            LOG.info( "Created a new instance of CassandraResource: {}", instance );
+            LOG.info( "Cassandra using ports {} and {}", storagePort, sslStoragePort );
             return instance;
         }
     }
+
+
     public static CassandraResource newWithMavenAllocatedPorts() {
-      synchronized ( lock ) {
-          Properties props = new Properties();
-          try {
-        props.load(ClassLoader.getSystemResourceAsStream( "project.properties" ));
-
-          } catch (IOException e) {
-        LOG.error("Unable to load project properties: {}", e.getLocalizedMessage());
-      }
-          int rpcPort = Integer.parseInt(props.getProperty("cassandra.rpcPort", Integer.toString(CassandraResource.DEFAULT_RPC_PORT)));
-          int storagePort = Integer.parseInt(props.getProperty("cassandra.storagePort", Integer.toString(CassandraResource.DEFAULT_STORAGE_PORT))) ;
-          int sslStoragePort = Integer.parseInt(props.getProperty("cassandra.sslPort", Integer.toString(CassandraResource.DEFAULT_SSL_STORAGE_PORT)));
-          int nativeTransportPort = Integer.parseInt(props.getProperty("cassandra.nativeTransportPort", Integer.toString(CassandraResource.DEFAULT_NATIVE_TRANSPORT_PORT)));
-          String host = props.getProperty("cassandra.host", DEFAULT_HOST);
-//          int rpcPort = CassandraResource.DEFAULT_RPC_PORT;
-//          int storagePort = CassandraResource.DEFAULT_STORAGE_PORT ;
-//          int sslStoragePort = CassandraResource.DEFAULT_SSL_STORAGE_PORT;
-//          int nativeTransportPort = CassandraResource.DEFAULT_NATIVE_TRANSPORT_PORT;
-
-          System.setProperty( "cassandra.url", host+":" + Integer.toString( rpcPort ) );
-          System.setProperty( "cassandra.cluster", props.getProperty("cassandra.cluster","Usergrid") );
-          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." + 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("project.properties loaded properties for ports : "
-                  + "[rpc, storage, sslStorage, native] = [{}, {}, {}, {}]", 
-                  new Object[] {rpcPort, storagePort, sslStoragePort, nativeTransportPort});
-
-
-          instance = new CassandraResource( 
-              null, rpcPort, storagePort, sslStoragePort, nativeTransportPort );
-  
-          LOG.info("Created a new instance of CassandraResource: {}", instance);
-          LOG.info("Cassandra using ports {} and {}", storagePort, sslStoragePort);
-          
-          return instance;
-      }
+        synchronized ( lock ) {
+            Properties props = new Properties();
+            try {
+                props.load( ClassLoader.getSystemResourceAsStream( "project.properties" ) );
+            }
+            catch ( IOException e ) {
+                LOG.error( "Unable to load project properties: {}", e.getLocalizedMessage() );
+            }
+            int rpcPort = Integer.parseInt(
+                    props.getProperty( "cassandra.rpcPort", Integer.toString( CassandraResource.DEFAULT_RPC_PORT ) ) );
+            int storagePort = Integer.parseInt( props.getProperty( "cassandra.storagePort",
+                    Integer.toString( CassandraResource.DEFAULT_STORAGE_PORT ) ) );
+            int sslStoragePort = Integer.parseInt( props.getProperty( "cassandra.sslPort",
+                    Integer.toString( CassandraResource.DEFAULT_SSL_STORAGE_PORT ) ) );
+            int nativeTransportPort = Integer.parseInt( props.getProperty( "cassandra.nativeTransportPort",
+                    Integer.toString( CassandraResource.DEFAULT_NATIVE_TRANSPORT_PORT ) ) );
+            String host = props.getProperty( "cassandra.host", DEFAULT_HOST );
+            //          int rpcPort = CassandraResource.DEFAULT_RPC_PORT;
+            //          int storagePort = CassandraResource.DEFAULT_STORAGE_PORT ;
+            //          int sslStoragePort = CassandraResource.DEFAULT_SSL_STORAGE_PORT;
+            //          int nativeTransportPort = CassandraResource.DEFAULT_NATIVE_TRANSPORT_PORT;
+
+            System.setProperty( "cassandra.url", host + ":" + Integer.toString( rpcPort ) );
+            System.setProperty( "cassandra.cluster", props.getProperty( "cassandra.cluster", "Usergrid" ) );
+            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." + 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( "project.properties loaded properties for ports : "
+                            + "[rpc, storage, sslStorage, native] = [{}, {}, {}, {}]",
+                    new Object[] { rpcPort, storagePort, sslStoragePort, nativeTransportPort } );
+
+
+            instance = new CassandraResource( null, rpcPort, storagePort, sslStoragePort, nativeTransportPort );
+
+            LOG.info( "Created a new instance of CassandraResource: {}", instance );
+            LOG.info( "Cassandra using ports {} and {}", storagePort, sslStoragePort );
+
+            return instance;
+        }
     }
 
 
@@ -772,7 +523,7 @@ public class CassandraResource extends ExternalResource {
 
 
     public static String getJammArgument() throws IOException {
-        return ( String ) getProjectProperties().get( JAMM_PATH ); 
+        return ( String ) getProjectProperties().get( JAMM_PATH );
     }
 
 
@@ -780,8 +531,7 @@ public class CassandraResource extends ExternalResource {
         if ( properties == null ) {
             properties = new Properties();
             properties.load( ClassLoader.getSystemResourceAsStream( PROPERTIES_FILE ) );
-        } 
+        }
         return properties;
     }
-
 }