You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ca...@codespot.com on 2012/02/07 23:07:31 UTC

[cassandra-jdbc] 3 new revisions pushed by wfs...@gmail.com on 2012-02-07 22:06 GMT

3 new revisions:

Revision: 318882147cdf
Author:   Rick Shaw <wf...@gmail.com>
Date:     Thu Feb  2 08:31:00 2012
Log:      ...
http://code.google.com/a/apache-extras.org/p/cassandra-jdbc/source/detail?r=318882147cdf

Revision: e89b5626b388
Author:   Rick Shaw <wf...@gmail.com>
Date:     Fri Feb  3 12:43:22 2012
Log:      Update Utils.java to support version=M.m.p in the URL for the  
Driver...
http://code.google.com/a/apache-extras.org/p/cassandra-jdbc/source/detail?r=e89b5626b388

Revision: 34afe6507c94
Author:   Rick Shaw <wf...@gmail.com>
Date:     Tue Feb  7 13:58:37 2012
Log:      Add ability to set the CQL version of the session using  
connection URL...
http://code.google.com/a/apache-extras.org/p/cassandra-jdbc/source/detail?r=34afe6507c94

==============================================================================
Revision: 318882147cdf
Author:   Rick Shaw <wf...@gmail.com>
Date:     Thu Feb  2 08:31:00 2012
Log:

Signed-off-by: Rick Shaw <wf...@gmail.com>
http://code.google.com/a/apache-extras.org/p/cassandra-jdbc/source/detail?r=318882147cdf

Modified:
  /src/test/resources/org/apache/cassandra/cql/ConnectionDetails.properties

=======================================
---  
/src/test/resources/org/apache/cassandra/cql/ConnectionDetails.properties	 
Sat Dec 17 20:01:00 2011
+++  
/src/test/resources/org/apache/cassandra/cql/ConnectionDetails.properties	 
Thu Feb  2 08:31:00 2012
@@ -1,3 +1,3 @@
-#port=${cassandra.rpc.port}
+port=${cassandra.rpc.port}
  host=${cassandra.host}
  port=9160

==============================================================================
Revision: e89b5626b388
Author:   Rick Shaw <wf...@gmail.com>
Date:     Fri Feb  3 12:43:22 2012
Log:      Update Utils.java to support version=M.m.p in the URL for the  
Driver

o Add a Unit test


http://code.google.com/a/apache-extras.org/p/cassandra-jdbc/source/detail?r=e89b5626b388

Added:
  /src/test/java/org/apache/cassandra/cql/jdbc/UtilsUnitTest.java
Modified:
  /src/main/java/org/apache/cassandra/cql/jdbc/Utils.java

=======================================
--- /dev/null
+++ /src/test/java/org/apache/cassandra/cql/jdbc/UtilsUnitTest.java	Fri  
Feb  3 12:43:22 2012
@@ -0,0 +1,86 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.cassandra.cql.jdbc;
+
+import static org.junit.Assert.*;
+
+import java.util.Properties;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class UtilsUnitTest
+{
+
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception
+    {}
+
+    @Test
+    public void testParseURL() throws Exception
+    {
+        String happypath  
= "jdbc:cassandra://localhost:9170/Keyspace1?version=2.0.0";
+        Properties props = Utils.parseURL(happypath);
+        assertEquals("localhost",  
props.getProperty(Utils.TAG_SERVER_NAME));
+        assertEquals("9170", props.getProperty(Utils.TAG_PORT_NUMBER));
+        assertEquals("Keyspace1",  
props.getProperty(Utils.TAG_DATABASE_NAME));
+        assertEquals("2.0.0", props.getProperty(Utils.TAG_CQL_VERSION));
+
+        String noport  
= "jdbc:cassandra://localhost/Keyspace1?version=2.0.0";
+        props = Utils.parseURL(noport);
+        assertEquals("localhost",  
props.getProperty(Utils.TAG_SERVER_NAME));
+        assertEquals("9160", props.getProperty(Utils.TAG_PORT_NUMBER));
+        assertEquals("Keyspace1",  
props.getProperty(Utils.TAG_DATABASE_NAME));
+        assertEquals("2.0.0", props.getProperty(Utils.TAG_CQL_VERSION));
+
+        String noversion = "jdbc:cassandra://localhost:9170/Keyspace1";
+        props = Utils.parseURL(noversion);
+        assertEquals("localhost",  
props.getProperty(Utils.TAG_SERVER_NAME));
+        assertEquals("9170", props.getProperty(Utils.TAG_PORT_NUMBER));
+        assertEquals("Keyspace1",  
props.getProperty(Utils.TAG_DATABASE_NAME));
+        assertNull(props.getProperty(Utils.TAG_CQL_VERSION));
+
+        String nokeyspaceonly  
= "jdbc:cassandra://localhost:9170?version=2.0.0";
+        props = Utils.parseURL(nokeyspaceonly);
+        assertEquals("localhost",  
props.getProperty(Utils.TAG_SERVER_NAME));
+        assertEquals("9170", props.getProperty(Utils.TAG_PORT_NUMBER));
+        assertNull(props.getProperty(Utils.TAG_DATABASE_NAME));
+        assertEquals("2.0.0", props.getProperty(Utils.TAG_CQL_VERSION));
+
+        String nokeyspaceorver = "jdbc:cassandra://localhost:9170";
+        props = Utils.parseURL(nokeyspaceorver);
+        assertEquals("localhost",  
props.getProperty(Utils.TAG_SERVER_NAME));
+        assertEquals("9170", props.getProperty(Utils.TAG_PORT_NUMBER));
+        assertNull(props.getProperty(Utils.TAG_DATABASE_NAME));
+        assertNull(props.getProperty(Utils.TAG_CQL_VERSION));
+    }
+
+    @Test
+    public void testCreateSubName() throws Exception
+    {
+        String happypath  
= "jdbc:cassandra://localhost:9170/Keyspace1?version=2.0.0";
+        Properties props = Utils.parseURL(happypath);
+
+        String result = Utils.createSubName(props);
+        assertEquals(happypath, Utils.PROTOCOL+result);
+    }
+}
=======================================
--- /src/main/java/org/apache/cassandra/cql/jdbc/Utils.java	Thu Oct 13  
00:45:22 2011
+++ /src/main/java/org/apache/cassandra/cql/jdbc/Utils.java	Fri Feb  3  
12:43:22 2012
@@ -60,6 +60,10 @@
      public static final String TAG_DATABASE_NAME = "databaseName";
      public static final String TAG_SERVER_NAME = "serverName";
      public static final String TAG_PORT_NUMBER = "portNumber";
+    public static final String TAG_ACTIVE_CQL_VERSION = "activeCqlVersion";
+    public static final String TAG_CQL_VERSION = "cqlVersion";
+    public static final String TAG_BUILD_VERSION = "buildVersion";
+    public static final String TAG_THRIFT_VERSION = "thriftVersion";

      protected static final String WAS_CLOSED_CON = "method was called on a  
closed Connection";
      protected static final String WAS_CLOSED_STMT = "method was called on  
a closed Statement";
@@ -93,7 +97,8 @@
      protected static final String HOST_IN_URL = "Connection url must  
specify a host, e.g., jdbc:cassandra://localhost:9170/Keyspace1";
      protected static final String HOST_REQUIRED = "a 'host' name is  
required to build a Connection";
      protected static final String BAD_KEYSPACE = "Keyspace names must be  
composed of alphanumerics and underscores (parsed: '%s')";
-    protected static final String URI_IS_SIMPLE = "Connection url may only  
include host, port, and keyspace, e.g.,  
jdbc:cassandra://localhost:9170/Keyspace1";
+    protected static final String URI_IS_SIMPLE = "Connection url may only  
include host, port, and keyspace and version option, e.g.,  
jdbc:cassandra://localhost:9170/Keyspace1?version=2.0.0";
+    protected static final String NOT_OPTION = "Connection url only  
support the 'version' option";

      protected static final Logger logger =  
LoggerFactory.getLogger(Utils.class);

@@ -172,6 +177,18 @@

              if (uri.getUserInfo() != null)
                  throw new  
SQLNonTransientConnectionException(URI_IS_SIMPLE);
+
+            String query = uri.getQuery();
+            if ((query != null) && (!query.isEmpty()))
+            {
+               String[] items = query.split("&");
+               if (items.length != 1) throw new  
SQLNonTransientConnectionException(URI_IS_SIMPLE);
+
+               String[] option = query.split("=");
+               if (!option[0].equalsIgnoreCase("version")) throw new  
SQLNonTransientConnectionException(NOT_OPTION);
+               if (option.length!=2) throw new  
SQLNonTransientConnectionException(NOT_OPTION);
+               props.setProperty(TAG_CQL_VERSION, option[1]);
+            }
          }

          if (logger.isTraceEnabled()) logger.trace("URL : '{}' parses to:  
{}", url, props);
@@ -183,7 +200,7 @@
       * Create a "Subname" portion of a JDBC URL from properties.
       *
       * @param props A Properties file containing all the properties to be  
considered.
-     * @return A constructed "Subname" portion of a JDBC URL in the form  
of a CLI (ie: //myhost:9160/Test1 )
+     * @return A constructed "Subname" portion of a JDBC URL in the form  
of a CLI (ie: //myhost:9160/Test1?version=3.0.0 )
       * @throws SQLException
       */
      public static final String createSubName(Properties props)throws  
SQLException
@@ -198,6 +215,8 @@
          String host = props.getProperty(TAG_SERVER_NAME);
          if (host==null)throw new  
SQLNonTransientConnectionException(HOST_REQUIRED);

+        String version = (props.getProperty(TAG_CQL_VERSION)==null)?  
null : "version="+ props.getProperty(TAG_CQL_VERSION);
+
          // construct a valid URI from parts...
          URI uri;
          try
@@ -208,7 +227,7 @@
                  host,
                  props.getProperty(TAG_PORT_NUMBER)==null ? DEFAULT_PORT :  
Integer.parseInt(props.getProperty(TAG_PORT_NUMBER)),
                  keyspace,
-                null,
+                version,
                  null);
          }
          catch (Exception e)

==============================================================================
Revision: 34afe6507c94
Author:   Rick Shaw <wf...@gmail.com>
Date:     Tue Feb  7 13:58:37 2012
Log:      Add ability to set the CQL version of the session using  
connection URL

o support adding "?version=M.m.p" to the URL argument to set the active
   CQL version like: "jdbc:cassandra://localhost:9160/KS1?version=3.0.0"
o add a toString() method to Cassandra connection to show all
   connection properties.
o Update driver to define version as 1.1.0
o Update JdbcRegression with a simple visual test for Issue#15
http://code.google.com/a/apache-extras.org/p/cassandra-jdbc/source/detail?r=34afe6507c94

Modified:
  /src/main/java/org/apache/cassandra/cql/jdbc/CassandraConnection.java
  /src/main/java/org/apache/cassandra/cql/jdbc/CassandraDriver.java
  /src/test/java/org/apache/cassandra/cql/JdbcDriverTest.java
  /src/test/java/org/apache/cassandra/cql/jdbc/DataSourceTest.java
  /src/test/java/org/apache/cassandra/cql/jdbc/JdbcRegressionTest.java
  /src/test/java/org/apache/cassandra/cql/jdbc/SpashScreenTest.java

=======================================
--- /src/main/java/org/apache/cassandra/cql/jdbc/CassandraConnection.java	 
Thu Feb  2 07:47:12 2012
+++ /src/main/java/org/apache/cassandra/cql/jdbc/CassandraConnection.java	 
Tue Feb  7 13:58:37 2012
@@ -50,9 +50,10 @@

      private static final Logger logger =  
LoggerFactory.getLogger(CassandraConnection.class);

-    public static final int DB_MAJOR_VERSION = 0;
-    public static final int DB_MINOR_VERSION = 8;
+    public static final int DB_MAJOR_VERSION = 1;
+    public static final int DB_MINOR_VERSION = 1;
      public static final String DB_PRODUCT_NAME = "Cassandra";
+    public static final String DEFAULT_CQL_VERSION = "2.0.0";

      public static Compression defaultCompression = Compression.GZIP;

@@ -60,6 +61,11 @@

      private final int transactionIsolation = Connection.TRANSACTION_NONE;

+    /**
+     * Connection Properties
+     */
+    private Properties connectionProps;
+
      /**
       * Client Info Properties (currently unused)
       */
@@ -86,15 +92,17 @@
       */
      public CassandraConnection(Properties props) throws SQLException
      {
+        connectionProps = (Properties)props.clone();
          clientInfo = new Properties();
          url = PROTOCOL + createSubName(props);
          try
          {
              String host = props.getProperty(TAG_SERVER_NAME);
              int port =  
Integer.parseInt(props.getProperty(TAG_PORT_NUMBER));
-            String keyspace = props.getProperty(TAG_DATABASE_NAME);
+            currentKeyspace =  
props.getProperty(TAG_DATABASE_NAME,"system");
              username = props.getProperty(TAG_USER);
              String password = props.getProperty(TAG_PASSWORD);
+            String version = props.getProperty(TAG_CQL_VERSION);

              TSocket socket = new TSocket(host, port);
              transport = new TFramedTransport(socket);
@@ -109,35 +117,27 @@
                  if (password != null) credentials.put("password",  
password);
                  AuthenticationRequest areq = new  
AuthenticationRequest(credentials);
                  client.login(areq);
-
-            }
-
+            }
+
+            if (version != null)
+            {
+                client.set_cql_version(version);
+                connectionProps.setProperty(TAG_ACTIVE_CQL_VERSION,  
version);
+            }
+
              decoder = new ColumnDecoder(client.describe_keyspaces());
-
-            logger.info("Connected to {}:{}", host, port);
-
-
-            if (keyspace != null)
-            {
-                execute("USE " + keyspace);
-            }
-        }
-        catch (SchemaDisagreementException e)
-        {
-            throw new SQLRecoverableException(SCHEMA_MISMATCH);
+
+            client.set_keyspace("system");
+
+            client.set_keyspace(currentKeyspace);
+
+            Object[] args = {host, port,currentKeyspace,(version==null) ?  
DEFAULT_CQL_VERSION: version};
+            logger.info("Connected to {}:{} using Keyspace {} and CQL  
version {}",args);
          }
          catch (InvalidRequestException e)
          {
              throw new SQLSyntaxErrorException(e);
          }
-        catch (UnavailableException e)
-        {
-            throw new SQLNonTransientConnectionException(e);
-        }
-        catch (TimedOutException e)
-        {
-            throw new SQLTransientConnectionException(e);
-        }
          catch (TException e)
          {
              throw new SQLNonTransientConnectionException(e);
@@ -482,4 +482,13 @@
      {
          return transport.isOpen();
      }
-}
+
+    public String toString()
+    {
+        StringBuilder builder = new StringBuilder();
+        builder.append("CassandraConnection [connectionProps=");
+        builder.append(connectionProps);
+        builder.append("]");
+        return builder.toString();
+    }
+}
=======================================
--- /src/main/java/org/apache/cassandra/cql/jdbc/CassandraDriver.java	Fri  
Nov 18 09:54:44 2011
+++ /src/main/java/org/apache/cassandra/cql/jdbc/CassandraDriver.java	Tue  
Feb  7 13:58:37 2012
@@ -43,9 +43,9 @@
  {
      public static final int DVR_MAJOR_VERSION = 1;

-    public static final int DVR_MINOR_VERSION = 0;
-
-    public static final int DVR_PATCH_VERSION = 5;
+    public static final int DVR_MINOR_VERSION = 1;
+
+    public static final int DVR_PATCH_VERSION = 0;

      public static final String DVR_NAME = "Cassandra JDBC Driver";

=======================================
--- /src/test/java/org/apache/cassandra/cql/JdbcDriverTest.java	Wed Dec 21  
21:12:23 2011
+++ /src/test/java/org/apache/cassandra/cql/JdbcDriverTest.java	Tue Feb  7  
13:58:37 2012
@@ -49,13 +49,16 @@
   */
  public class JdbcDriverTest
  {
+    private static final String HOST = System.getProperty("host",  
ConnectionDetails.getHost());
+    private static final int PORT =  
Integer.parseInt(System.getProperty("port",  
ConnectionDetails.getPort()+""));
+
      private static java.sql.Connection con = null;
      private static final String first = bytesToHex("first".getBytes());
      private static final String firstrec =  
bytesToHex("firstrec".getBytes());
      private static final String last = bytesToHex("last".getBytes());
      private static final String lastrec = bytesToHex("lastrec".getBytes());
      private static final String jsmith = bytesToHex("jsmith".getBytes());
-    private static final Schema schema = new  
Schema(ConnectionDetails.getHost(), ConnectionDetails.getPort());
+    private static final Schema schema = new Schema(HOST, PORT);

      /** SetUp */
      @BeforeClass
@@ -63,7 +66,7 @@
      {
          schema.createSchema();
          Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver");
-        con =  
DriverManager.getConnection(String.format("jdbc:cassandra://%s:%d/%s",  
ConnectionDetails.getHost(), ConnectionDetails.getPort(),  
Schema.KEYSPACE_NAME));
+        con =  
DriverManager.getConnection(String.format("jdbc:cassandra://%s:%d/%s",HOST,  
PORT, Schema.KEYSPACE_NAME));
          String[] inserts =
          {
              String.format("UPDATE Standard1 SET '%s' = '%s', '%s' = '%s'  
WHERE KEY = '%s'", first, firstrec, last, lastrec, jsmith),
=======================================
--- /src/test/java/org/apache/cassandra/cql/jdbc/DataSourceTest.java	Thu  
Feb  2 07:58:40 2012
+++ /src/test/java/org/apache/cassandra/cql/jdbc/DataSourceTest.java	Tue  
Feb  7 13:58:37 2012
@@ -30,6 +30,7 @@
  import javax.sql.DataSource;

  import org.apache.cassandra.cql.ConnectionDetails;
+import org.junit.AfterClass;
  import org.junit.BeforeClass;
  import org.junit.Test;

@@ -37,7 +38,7 @@
  {
      private static final String HOST = System.getProperty("host",  
ConnectionDetails.getHost());
      private static final int PORT =  
Integer.parseInt(System.getProperty("port",  
ConnectionDetails.getPort()+""));
-    private static final String KEYSPACE = "JdbcTestKeyspace";
+    private static final String KEYSPACE = "TestKS";
      private static final String USER = "JohnDoe";
      private static final String PASSWORD = "secret";

@@ -61,6 +62,14 @@
          String createKS = String.format("CREATE KEYSPACE %s WITH  
strategy_class = SimpleStrategy AND strategy_options:replication_factor =  
1;",KEYSPACE);
          stmt.execute(createKS);
      }
+
+    @AfterClass
+    public static void tearDownAfterClass() throws Exception
+    {
+        if (con!=null) con.close();
+    }
+
+
      @Test
      public void testConstructor() throws Exception
      {
=======================================
--- /src/test/java/org/apache/cassandra/cql/jdbc/JdbcRegressionTest.java	 
Thu Feb  2 07:58:40 2012
+++ /src/test/java/org/apache/cassandra/cql/jdbc/JdbcRegressionTest.java	 
Tue Feb  7 13:58:37 2012
@@ -28,6 +28,7 @@
  import java.sql.Statement;

  import org.apache.cassandra.cql.ConnectionDetails;
+import org.junit.AfterClass;
  import org.junit.BeforeClass;
  import org.junit.Test;

@@ -35,8 +36,9 @@
  {
      private static final String HOST = System.getProperty("host",  
ConnectionDetails.getHost());
      private static final int PORT =  
Integer.parseInt(System.getProperty("port",  
ConnectionDetails.getPort()+""));
-    private static final String KEYSPACE = "JdbcTestKeyspace";
-
+    private static final String KEYSPACE = "TestKS";
+    private static final String CQLV3 = "3.0.0";
+
      private static java.sql.Connection con = null;


@@ -44,7 +46,7 @@
      public static void setUpBeforeClass() throws Exception
      {
          Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver");
-        con =  
DriverManager.getConnection(String.format("jdbc:cassandra://%s:%d/%s",HOST,PORT,KEYSPACE));
+        con =  
DriverManager.getConnection(String.format("jdbc:cassandra://%s:%d/%s",HOST,PORT,"system"));
          Statement stmt = con.createStatement();

          // Drop Keyspace
@@ -58,8 +60,12 @@
          stmt = con.createStatement();
          stmt.execute(createKS);

+        // Use Keyspace
+        String useKS = String.format("USE %s;",KEYSPACE);
+        stmt.execute(useKS);
+
          // Create the target Column family
-        String createCF = "CREATE COLUMNFAMILY RegressionTest (KEY text  
PRIMARY KEY,"
+        String createCF = "CREATE COLUMNFAMILY RegressionTest (keyname  
text PRIMARY KEY,"
                          + "bValue boolean, "
                          + "iValue int "
                          + ") WITH comparator = ascii AND  
default_validation = bigint;";
@@ -71,12 +77,22 @@

          // open it up again to see the new CF
          con =  
DriverManager.getConnection(String.format("jdbc:cassandra://%s:%d/%s",HOST,PORT,KEYSPACE));
-    }
+        System.out.println(con);
+
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() throws Exception
+    {
+        if (con!=null) con.close();
+    }
+
+

      @Test
      public void testIssue10() throws Exception
      {
-        String insert = "INSERT INTO RegressionTest (KEY,bValue,iValue)  
VALUES( 'key0',true, 2000);";
+        String insert = "INSERT INTO RegressionTest  
(keyname,bValue,iValue) VALUES( 'key0',true, 2000);";
          Statement statement = con.createStatement();

          statement.executeUpdate(insert);
@@ -85,20 +101,32 @@
          Thread.sleep(3000);

          statement = con.createStatement();
-        ResultSet result = statement.executeQuery("SELECT  
bValue,notThere,iValue FROM RegressionTest WHERE KEY=key0;");
+        ResultSet result = statement.executeQuery("SELECT  
bValue,notThere,iValue FROM RegressionTest WHERE keyname=key0;");
          result.next();

          boolean b = result.getBoolean(1);
-        System.out.println("b = "+ b);
          assertTrue(b);

          long l = result.getLong("notThere");
          assertEquals(0,l);
-//        System.out.println("l = "+ l + " ... wasNull() = "+  
result.wasNull());

          int i = result.getInt(3);
-//        System.out.println("i ="+ i + " ... wasNull() = "+  
result.wasNull());
          assertEquals(2000, i);
     }
+
+    @Test
+    public void testIssue15() throws Exception
+    {
+//        con.close();
+//
+//        con =  
DriverManager.getConnection(String.format("jdbc:cassandra://%s:%d/%s?version=%s",HOST,PORT,KEYSPACE,CQLV3));
+//        System.out.println(con);
+//        con.close();
+
+//        con =  
DriverManager.getConnection(String.format("jdbc:cassandra://%s:%d/%s",HOST,PORT,KEYSPACE));
+//        System.out.println(con);
+//        con.close();
+
+    }

  }
=======================================
--- /src/test/java/org/apache/cassandra/cql/jdbc/SpashScreenTest.java	Mon  
Nov 21 14:40:58 2011
+++ /src/test/java/org/apache/cassandra/cql/jdbc/SpashScreenTest.java	Tue  
Feb  7 13:58:37 2012
@@ -28,34 +28,56 @@
  import java.sql.Statement;

  import org.apache.cassandra.cql.ConnectionDetails;
+import org.junit.AfterClass;
  import org.junit.BeforeClass;
  import org.junit.Test;

  public class SpashScreenTest
  {
+    private static final String HOST = System.getProperty("host",  
ConnectionDetails.getHost());
+    private static final int PORT =  
Integer.parseInt(System.getProperty("port",  
ConnectionDetails.getPort()+""));
+    private static final String KEYSPACE = "TestKS";
+
      private static java.sql.Connection con = null;

      @BeforeClass
-    public static void waxOn() throws Exception
+    public static void setUpBeforeClass() throws Exception
      {
          Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver");
-        con =  
DriverManager.getConnection(String.format("jdbc:cassandra://%s:%d/%s",
-            ConnectionDetails.getHost(),
-            ConnectionDetails.getPort(),
-            "JdbcTestKeyspace"));
-
+        con =  
DriverManager.getConnection(String.format("jdbc:cassandra://%s:%d/%s",HOST,PORT,"system"));
+        Statement stmt = con.createStatement();
+
+        // Drop Keyspace
+        String dropKS = String.format("DROP KEYSPACE %s;",KEYSPACE);
+
+        try { stmt.execute(dropKS);}
+        catch (Exception e){/* Exception on DROP is OK */}
+
+        // Create KeySpace
+        String createKS = String.format("CREATE KEYSPACE %s WITH  
strategy_class = SimpleStrategy AND strategy_options:replication_factor =  
1;",KEYSPACE);
+        stmt = con.createStatement();
+        stmt.execute(createKS);
+
+        // Use Keyspace
+        String useKS = String.format("USE %s;",KEYSPACE);
+        stmt.execute(useKS);
+
+
          // Create the target Column family
          String create = "CREATE COLUMNFAMILY Test (KEY text PRIMARY KEY)  
WITH comparator = ascii AND default_validation = bigint;";
-        Statement stmt = con.createStatement();
+        stmt = con.createStatement();
          stmt.execute(create);
          stmt.close();
          con.close();

          // open it up again to see the new CF
-        con =  
DriverManager.getConnection(String.format("jdbc:cassandra://%s:%d/%s",
-            ConnectionDetails.getHost(),
-            ConnectionDetails.getPort(),
-            "JdbcTestKeyspace"));
+        con =  
DriverManager.getConnection(String.format("jdbc:cassandra://%s:%d/%s",HOST,PORT,KEYSPACE));
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() throws Exception
+    {
+        if (con!=null) con.close();
      }