Created
January 21, 2011 21:46
-
-
Save zznate/790491 to your computer and use it in GitHub Desktop.
embeddedserver diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.java b/core/src/main/java/me/prettyprint/cassandra/testutils/EmbeddedServerHelper.java | |
index 7770070..3e3fbb5 100644 | |
--- a/core/src/main/java/me/prettyprint/cassandra/testutils/EmbeddedServerHelper.java | |
+++ b/core/src/main/java/me/prettyprint/cassandra/testutils/EmbeddedServerHelper.java | |
@@ -5,16 +5,21 @@ import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.OutputStream; | |
+import java.util.concurrent.ExecutorService; | |
+import java.util.concurrent.Executors; | |
+import java.util.concurrent.Future; | |
+import java.util.concurrent.TimeUnit; | |
+import org.apache.cassandra.config.CFMetaData; | |
+import org.apache.cassandra.config.ConfigurationException; | |
+import org.apache.cassandra.config.DatabaseDescriptor; | |
+import org.apache.cassandra.config.KSMetaData; | |
import org.apache.cassandra.contrib.utils.service.CassandraServiceDataCleaner; | |
import org.apache.cassandra.io.util.FileUtils; | |
-import org.apache.cassandra.service.EmbeddedCassandraService; | |
+import org.apache.cassandra.thrift.CassandraDaemon; | |
import org.apache.thrift.transport.TTransportException; | |
- | |
-import org.apache.cassandra.config.KSMetaData; | |
-import org.apache.cassandra.config.DatabaseDescriptor; | |
-import org.apache.cassandra.config.CFMetaData; | |
-import org.apache.cassandra.config.ConfigurationException; | |
+import org.slf4j.Logger; | |
+import org.slf4j.LoggerFactory; | |
/** | |
* | |
@@ -22,10 +27,11 @@ import org.apache.cassandra.config.ConfigurationException; | |
* | |
*/ | |
public class EmbeddedServerHelper { | |
+ private static Logger log = LoggerFactory.getLogger(EmbeddedServerHelper.class); | |
private static final String TMP = "tmp"; | |
- private EmbeddedCassandraService cassandra; | |
+ private static EmbeddedCassandraService cassandra; | |
private final String yamlFile; | |
public EmbeddedServerHelper() { | |
@@ -49,17 +55,14 @@ public class EmbeddedServerHelper { | |
copy("/log4j.properties", TMP); | |
copy(yamlFile, TMP); | |
System.setProperty("cassandra.config", "file:"+ TMP + yamlFile); | |
+ System.setProperty("cassandra-foreground","true"); | |
CassandraServiceDataCleaner cleaner = new CassandraServiceDataCleaner(); | |
cleaner.prepare(); | |
loadYamlTables(); | |
- cassandra = new EmbeddedCassandraService(); | |
- cassandra.init(); | |
- Thread t = new Thread(cassandra); | |
- t.setDaemon(true); | |
- t.start(); | |
+ startCassandra(); | |
} | |
/** Manually load tables from the test configuration file. | |
@@ -73,13 +76,14 @@ public class EmbeddedServerHelper { | |
} | |
} | |
- public void teardown() { | |
+ public void teardown() { | |
CassandraServiceDataCleaner cleaner = new CassandraServiceDataCleaner(); | |
try { | |
+ stopCassandra(); | |
cleaner.cleanupDataDirectories(); | |
rmdir(TMP); | |
- } catch (IOException e) { | |
+ } catch (Exception e) { | |
// IGNORE | |
} | |
} | |
@@ -120,4 +124,41 @@ public class EmbeddedServerHelper { | |
private static void mkdir(String dir) throws IOException { | |
FileUtils.createDirectory(dir); | |
} | |
+ | |
+ | |
+ | |
+ static ExecutorService executor = Executors.newSingleThreadExecutor(); | |
+ | |
+ | |
+ public void startCassandra() throws TTransportException, IOException { | |
+ cassandra = new EmbeddedCassandraService(); | |
+ cassandra.init(); | |
+ executor.submit(cassandra); | |
+ } | |
+ | |
+ public void stopCassandra() throws Exception { | |
+ if (cassandra.cassandraDaemon != null) { | |
+ //cassandra.cassandraDaemon.stop(); | |
+ } | |
+ executor.shutdown(); | |
+ executor.shutdownNow(); | |
+ //executor.awaitTermination(2, TimeUnit.SECONDS); | |
+ } | |
+ | |
+ class EmbeddedCassandraService implements Runnable | |
+ { | |
+ | |
+ CassandraDaemon cassandraDaemon; | |
+ | |
+ public void init() throws TTransportException, IOException | |
+ { | |
+ cassandraDaemon = new CassandraDaemon(); | |
+ cassandraDaemon.init(null); | |
+ } | |
+ | |
+ public void run() | |
+ { | |
+ cassandraDaemon.start(); | |
+ } | |
+ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment