package com.geekbeast.rhizome.tests.bootstrap;

import java.io.IOException;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.thrift.transport.TTransportException;
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.datastax.driver.core.Cluster;
import com.kryptnostic.rhizome.cassandra.EmbeddedCassandraManager;
import com.kryptnostic.rhizome.pods.CassandraPod;

public class CassandraBootstrap {
    private static Logger                          logger = LoggerFactory.getLogger( CassandraBootstrap.class );
    protected static EmbeddedCassandraManager ecm    = new RhizomeEmbeddedCassandraManager();
    static {
        CassandraPod.setEmbeddedCassandraManager( ecm );
    }

    @BeforeClass
    public static void startCassandra() throws ConfigurationException, TTransportException, IOException {
        ecm.start( CassandraPod.RANDOM_PORTS_YAML );
    }

    private static final class RhizomeEmbeddedCassandraManager implements EmbeddedCassandraManager {
        private static final Lock lock = new ReentrantLock();

        public void start( String yamlFile ) {
            if ( lock.tryLock() ) {
                try {
                    EmbeddedCassandraServerHelper.startEmbeddedCassandra( yamlFile, 100000 );
                } catch ( ConfigurationException | TTransportException | IOException e ) {
                    throw new IllegalStateException( "Cassandra unable to start.", e );
                }
                logger.info( "Started cassandra on port: {}", EmbeddedCassandraServerHelper.getNativeTransportPort() );
            }
        }

        @Override
        public Cluster cluster() {
            return EmbeddedCassandraServerHelper.getCluster();
        }
    }
}

@@ -465,24 +465,105 @@
 re.Cluster;%0A
+import com.google.common.base.Supplier;%0Aimport com.google.common.base.Suppliers;%0A
 import com.k
@@ -702,16 +702,89 @@
 strap %7B%0A
+    private static final int                  EMBEDDED_TIMEOUT = 60000;%0A%0A
     priv
@@ -825,20 +825,25 @@
     
-     
 logger 
+          
 = Lo
@@ -946,16 +946,26 @@
  ecm    
+          
 = new Rh
@@ -1396,33 +1396,818 @@
 ock 
-lock = new ReentrantLock(
+             lock            = new ReentrantLock();%0A        private static final Supplier%3CCluster%3E clusterSupplier = Suppliers.memoize( () -%3E %7B%0A                                                                   final Cluster cluster = EmbeddedCassandraServerHelper%0A                                                                           .getCluster();%0A                                                                   cluster.getConfiguration()%0A                                                                           .getSocketOptions()%0A                                                                           .setReadTimeoutMillis( EMBEDDED_TIMEOUT );%0A                                                                   return cluster;%0A                                                               %7D 
 );%0A%0A
@@ -2401,24 +2401,196 @@
 , 100000 );%0A
+                    EmbeddedCassandraServerHelper.getCluster().getConfiguration().getSocketOptions()%0A                            .setReadTimeoutMillis( EMBEDDED_TIMEOUT );%0A
             
@@ -2995,48 +2995,27 @@
 urn 
-EmbeddedCassandraServerHelper.getCluster
+clusterSupplier.get
 ();%0A

Increase timeouts