package me.prettyprint.cassandra.testutils;

import me.prettyprint.cassandra.service.CassandraClientTest;
import org.apache.cassandra.contrib.utils.service.CassandraServiceDataCleaner;
import org.apache.cassandra.io.util.FileUtils;
import org.apache.cassandra.service.EmbeddedCassandraService;
import org.apache.thrift.transport.TTransportException;

import java.io.*;

/**
*
* @author Ran Tavory (rantav@gmail.com)
*
*/
public class EmbeddedServerHelper {

  private static final String TMP = "tmp";

  private EmbeddedCassandraService cassandra;

  /**
   * Set embedded cassandra up and spawn it in a new thread.
   *
   * @throws TTransportException
   * @throws IOException
   * @throws InterruptedException
   */
  public void setup() throws TTransportException, IOException, InterruptedException {
    // delete tmp dir first
    rmdir(TMP);
    // make a tmp dir and copy storag-conf.xml and log4j.properties to it
    copy("/storage-conf.xml", TMP);
    copy("/log4j.properties", TMP);
    System.setProperty("storage-config", TMP);

    CassandraServiceDataCleaner cleaner = new CassandraServiceDataCleaner();
    cleaner.prepare();
    cassandra = new EmbeddedCassandraService();
    cassandra.init();
    Thread t = new Thread(cassandra);
    t.setDaemon(true);
    t.start();
  }

  public void teardown() {
    CassandraServiceDataCleaner cleaner = new CassandraServiceDataCleaner();

    try {
      cleaner.cleanupDataDirectories();
      rmdir(TMP);
    } catch (IOException e) {
      // IGNORE
    }
  }

  private static void rmdir(String dir) throws IOException {
    File dirFile = new File(dir);
    if (dirFile.exists()) {
      FileUtils.deleteDir(new File(dir));
    }
  }
  /**
   * Copies a resource from within the jar to a directory.
   *
   * @param resource
   * @param directory
   * @throws IOException
   */
  private static void copy(String resource, String directory) throws IOException {
    mkdir(directory);
    InputStream is = CassandraClientTest.class.getResourceAsStream(resource);
    String fileName = resource.substring(resource.lastIndexOf("/") + 1);
    File file = new File(directory + System.getProperty("file.separator") + fileName);
    OutputStream out = new FileOutputStream(file);
    byte buf[] = new byte[1024];
    int len;
    while ((len = is.read(buf)) > 0) {
      out.write(buf, 0, len);
    }
    out.close();
    is.close();
  }

  /**
   * Creates a directory
   * @param dir
   * @throws IOException
   */
  private static void mkdir(String dir) throws IOException {
    FileUtils.createDirectory(dir);
  }
}

@@ -49,61 +49,140 @@
 ort 
-me.prettyprint.cassandra.service.CassandraClientTest;
+java.io.File;%0Aimport java.io.FileOutputStream;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.io.OutputStream;%0A
 %0Aimp
@@ -427,27 +427,8 @@
 n;%0A%0A
-import java.io.*;%0A%0A
 /**%0A
@@ -2026,27 +2026,28 @@
 s = 
-CassandraClientTest
+EmbeddedServerHelper
 .cla

Remove CassandraClientTest.class where it's not really required