gt:             String keyspaceName = keyspaceDefinition.getName();
context: package org.cassandraunit.utils;
  
  import me.prettyprint.cassandra.service.CassandraHostConfigurator;
  import me.prettyprint.hector.api.Cluster;
  import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
  import me.prettyprint.hector.api.factory.HFactory;
  import org.apache.cassandra.config.DatabaseDescriptor;
  import org.apache.cassandra.db.commitlog.CommitLog;
  import org.apache.cassandra.exceptions.ConfigurationException;
  import org.apache.cassandra.io.util.FileUtils;
  import org.apache.cassandra.service.CassandraDaemon;
  import org.apache.commons.lang3.StringUtils;
  import org.apache.thrift.transport.TTransportException;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.yaml.snakeyaml.reader.UnicodeReader;
  
  import java.io.*;
  import java.net.ServerSocket;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.concurrent.CountDownLatch;
  import java.util.concurrent.ExecutorService;
  import java.util.concurrent.Executors;
  import java.util.regex.Matcher;
  import java.util.regex.Pattern;
  
  import static java.util.concurrent.TimeUnit.MILLISECONDS;
  
  /**
   * @author Jeremy Sevellec
   */
  public class EmbeddedCassandraServerHelper {
  
      private static Logger log = LoggerFactory.getLogger(EmbeddedCassandraServerHelper.class);
  
      public static final long DEFAULT_STARTUP_TIMEOUT = 10000;
      public static final String DEFAULT_TMP_DIR = "target/embeddedCassandra";
      /** Default configuration file. Starts embedded cassandra under the well known ports */
      public static final String DEFAULT_CASSANDRA_YML_FILE = "cu-cassandra.yaml";
      /** Configuration file which starts the embedded cassandra on a random free port */
      public static final String CASSANDRA_RNDPORT_YML_FILE = "cu-cassandra-rndport.yaml";
      public static final String DEFAULT_LOG4J_CONFIG_FILE = "/log4j-embedded-cassandra.properties";
      private static final String INTERNAL_CASSANDRA_KEYSPACE = "system";
      private static final String INTERNAL_CASSANDRA_AUTH_KEYSPACE = "system_auth";
      private static final String INTERNAL_CASSANDRA_TRACES_KEYSPACE = "system_traces";
  
      private static CassandraDaemon cassandraDaemon = null;
      private static String launchedYamlFile;
  
      public static void startEmbeddedCassandra() throws TTransportException, IOException, InterruptedException, ConfigurationException {
          startEmbeddedCassandra(DEFAULT_STARTUP_TIMEOUT);
      }
  
      public static void startEmbeddedCassandra(long timeout) throws TTransportException, IOException, InterruptedException, ConfigurationException {
          startEmbeddedCassandra(DEFAULT_CASSANDRA_YML_FILE, timeout);
      }
  
      public static void startEmbeddedCassandra(String yamlFile) throws TTransportException, IOException, ConfigurationException {
          startEmbeddedCassandra(yamlFile, DEFAULT_STARTUP_TIMEOUT);
      }
  
      public static void startEmbeddedCassandra(String yamlFile, long timeout) throws TTransportException, IOException, ConfigurationException {
          startEmbeddedCassandra(yamlFile, DEFAULT_TMP_DIR, timeout);
      }
  
      public static void startEmbeddedCassandra(String yamlFile, String tmpDir) throws TTransportException, IOException, ConfigurationException {
          startEmbeddedCassandra(yamlFile, tmpDir, DEFAULT_STARTUP_TIMEOUT);
      }
  
      public static void startEmbeddedCassandra(String yamlFile, String tmpDir, long timeout) throws TTransportException, IOException, ConfigurationException {
          if (cassandraDaemon != null) {
              /* nothing to do Cassandra is already started */
              return;
          }
  
          if (!StringUtils.startsWith(yamlFile, "/")) {
              yamlFile = "/" + yamlFile;
          }
  
          rmdir(tmpDir);
          copy(yamlFile, tmpDir);
          File file = new File(tmpDir + yamlFile);
          readAndAdaptYaml(file);
          startEmbeddedCassandra(file, tmpDir, timeout);
      }
  
      /**
       * Set embedded cassandra up and spawn it in a new thread.
       *
       * @throws TTransportException
       * @throws IOException
       * @throws ConfigurationException
       */
      public static void startEmbeddedCassandra(File file, String tmpDir, long timeout) throws TTransportException, IOException, ConfigurationException {
          if (cassandraDaemon != null) {
              /* nothing to do Cassandra is already started */
              return;
          }
  
          checkConfigNameForRestart(file.getAbsolutePath());
  
          log.debug("Starting cassandra...");
          log.debug("Initialization needed");
  
          System.setProperty("cassandra.config", "file:" + file.getAbsolutePath());
          System.setProperty("cassandra-foreground", "true");
          System.setProperty("cassandra.native.epoll.enabled", "false"); // JNA doesnt cope with relocated netty
  
          // If there is no log4j config set already, set the default config
          if (System.getProperty("log4j.configuration") == null) {
              copy(DEFAULT_LOG4J_CONFIG_FILE, tmpDir);
              System.setProperty("log4j.configuration", "file:" + tmpDir + DEFAULT_LOG4J_CONFIG_FILE);
          }
  
          cleanupAndLeaveDirs();
          final CountDownLatch startupLatch = new CountDownLatch(1);
          ExecutorService executor = Executors.newSingleThreadExecutor();
          executor.execute(new Runnable() {
              @Override
              public void run() {
                  cassandraDaemon = new CassandraDaemon();
                  cassandraDaemon.activate();
                  startupLatch.countDown();
              }
          });
          try {
              if (!startupLatch.await(timeout, MILLISECONDS)) {
                  log.error("Cassandra daemon did not start after " + timeout + " ms. Consider increasing the timeout");
                  throw new AssertionError("Cassandra daemon did not start within timeout");
              }
          } catch (InterruptedException e) {
              log.error("Interrupted waiting for Cassandra daemon to start:", e);
              throw new AssertionError(e);
          } finally {
              executor.shutdown();
          }
      }
  
      private static void checkConfigNameForRestart(String yamlFile) {
          boolean wasPreviouslyLaunched = launchedYamlFile != null;
          if (wasPreviouslyLaunched && !launchedYamlFile.equals(yamlFile)) {
              throw new UnsupportedOperationException("We can't launch two Cassandra configurations in the same JVM instance");
          }
          launchedYamlFile = yamlFile;
      }
  
      /**
       * Now deprecated, previous version was not fully operating.
       * This is now an empty method, will be pruned in future versions.
       */
      @Deprecated
      public static void stopEmbeddedCassandra() {
          log.warn("EmbeddedCassandraServerHelper.stopEmbeddedCassandra() is now deprecated, " +
                  "previous version was not fully operating");
      }
  
       /**
       * drop all keyspaces (expect system)
       */
      public static void cleanEmbeddedCassandra() {
          dropKeyspaces();
      }
  
      /**
       * Get the embedded cassandra cluster name
       * 
       * @return the cluster name
       */
      public static String getClusterName() {
          return DatabaseDescriptor.getClusterName();
      }
      
      /**
       * Get embedded cassandra host.
       * 
       * @return the cassandra host
       */
      public static String getHost() {
          return DatabaseDescriptor.getRpcAddress().getHostName();
      }
      
      /**
       * Get embedded cassandra RPC port.
       *
       * @return the cassandra RPC port
       */
      public static int getRpcPort() {
          return DatabaseDescriptor.getRpcPort();
      }
  
      /**
       * Get embedded cassandra native transport port.
       *
       * @return the cassandra native transport port.
       */
      public static int getNativeTransportPort() {
          return DatabaseDescriptor.getNativeTransportPort();
      }
  
     private static void dropKeyspaces() {
          if (hasHector()) {
              dropKeyspacesWithHector();
          } else {
              dropKeyspacesWithNativeDriver();
          }
      }
  
      private static boolean hasHector() {
          boolean hector = false;
          try {
              new CassandraHostConfigurator("");
              hector = true;
          } catch(NoClassDefFoundError err) {
              hector = false;
          }
          return hector;
      }
      
      private static void dropKeyspacesWithHector() {
          String host = DatabaseDescriptor.getRpcAddress().getHostName();
          int port = DatabaseDescriptor.getRpcPort();
          log.debug("Cleaning cassandra keyspaces on " + host + ":" + port);
          Cluster cluster = HFactory.getOrCreateCluster("TestCluster", new CassandraHostConfigurator(host + ":" + port));
          /* get all keyspace */
          List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces();
  
          /* drop all keyspace except internal cassandra keyspace */
          for (KeyspaceDefinition keyspaceDefinition : keyspaces) {
  