cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cassandra-dbapi2.apache-extras....@codespot.com
Subject [cassandra-dbapi2] 3 new revisions pushed by pcannon@gmail.com on 2012-09-20 17:59 GMT
Date Thu, 20 Sep 2012 17:59:57 GMT
3 new revisions:

Revision: 9eb88a2ed7f3
Author:   Sylvain Lebresne <sylvain@datastax.com>
Date:     Mon Sep 17 04:34:57 2012
Log:      Set initial keyspace after connection has been finalized
http://code.google.com/a/apache-extras.org/p/cassandra-dbapi2/source/detail?r=9eb88a2ed7f3

Revision: 378ebda45976
Author:   paul cannon <paul@thepaul.org>
Date:     Thu Sep 20 10:38:41 2012
Log:      tests for specifying keyspace in connect() call
http://code.google.com/a/apache-extras.org/p/cassandra-dbapi2/source/detail?r=378ebda45976

Revision: a26caaa88cd1
Author:   paul cannon <paul@thepaul.org>
Date:     Thu Sep 20 10:58:57 2012
Log:      explicitly use cql 2 for test_cql tests
http://code.google.com/a/apache-extras.org/p/cassandra-dbapi2/source/detail?r=a26caaa88cd1

==============================================================================
Revision: 9eb88a2ed7f3
Author:   Sylvain Lebresne <sylvain@datastax.com>
Date:     Mon Sep 17 04:34:57 2012
Log:      Set initial keyspace after connection has been finalized

http://code.google.com/a/apache-extras.org/p/cassandra-dbapi2/source/detail?r=9eb88a2ed7f3

Modified:
  /cql/connection.py
  /cql/native.py
  /cql/thrifteries.py

=======================================
--- /cql/connection.py	Tue Sep 11 17:31:33 2012
+++ /cql/connection.py	Mon Sep 17 04:34:57 2012
@@ -46,6 +46,9 @@
          self.establish_connection()
          self.open_socket = True

+        if self.keyspace:
+            self.set_initial_keyspace(self.keyspace)
+
      def __str__(self):
          return ("%s(host=%r, port=%r, keyspace=%r, %s)"
                  % (self.__class__.__name__, self.host, self.port,  
self.keyspace,
=======================================
--- /cql/native.py	Tue Sep 11 18:09:31 2012
+++ /cql/native.py	Mon Sep 17 04:34:57 2012
@@ -761,8 +761,6 @@
                  raise cql.InternalError("Unexpected response %r during  
connection setup"
                                          % startup_response)

-        if self.keyspace:
-            self.set_initial_keyspace(self.keyspace)

      def set_initial_keyspace(self, keyspace):
          c = self.cursor()
=======================================
--- /cql/thrifteries.py	Tue Sep 11 17:31:33 2012
+++ /cql/thrifteries.py	Mon Sep 17 04:34:57 2012
@@ -134,9 +134,6 @@
          if self.cql_version:
              self.set_cql_version(self.cql_version)

-        if self.keyspace:
-            self.set_initial_keyspace(self.keyspace)
-
      def set_cql_version(self, cql_version):
          self.client.set_cql_version(cql_version)
          try:

==============================================================================
Revision: 378ebda45976
Author:   paul cannon <paul@thepaul.org>
Date:     Thu Sep 20 10:38:41 2012
Log:      tests for specifying keyspace in connect() call

http://code.google.com/a/apache-extras.org/p/cassandra-dbapi2/source/detail?r=378ebda45976

Added:
  /test/test_connection.py

=======================================
--- /dev/null
+++ /test/test_connection.py	Thu Sep 20 10:38:41 2012
@@ -0,0 +1,103 @@
+# 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.
+
+# to configure behavior, define $CQL_TEST_HOST to the destination address
+# for Thrift connections, and $CQL_TEST_PORT to the associated port.
+
+import unittest
+import contextlib
+from thrift.transport import TTransport
+import test_cql
+from test_prepared_queries import MIN_THRIFT_FOR_CQL_3_0_0_FINAL
+
+cql = test_cql.cql
+TEST_HOST = test_cql.TEST_HOST
+TEST_PORT = test_cql.TEST_PORT
+randstring = test_cql.randstring
+del test_cql
+
+class TestConnection(unittest.TestCase):
+    def setUp(self):
+        self.randstr = randstring()
+
+    @contextlib.contextmanager
+    def with_keyspace(self, cursor, cqlver):
+        ksname = self.randstr + '_conntest_' + cqlver.replace('.', '_')
+        if cqlver.startswith('2.'):
+            cursor.execute("create keyspace '%s' with  
strategy_class='SimpleStrategy'"
+                           " and strategy_options:replication_factor=1;" %  
ksname)
+            cursor.execute("use '%s'" % ksname)
+            yield ksname
+            cursor.execute("use system;")
+            cursor.execute("drop keyspace '%s'" % ksname)
+        elif cqlver == '3.0.0-beta1': # for cassandra 1.1
+            cursor.execute("create keyspace \"%s\" with  
strategy_class='SimpleStrategy'"
+                           " and strategy_options:replication_factor=1;" %  
ksname)
+            cursor.execute('use "%s"' % ksname)
+            yield ksname
+            cursor.execute('use system;')
+            cursor.execute('drop keyspace "%s"' % ksname)
+        else:
+            cursor.execute("create keyspace \"%s\" with replication = "
+                           "{'class': 'SimpleStrategy', 'replication_factor':  
1};" %  
ksname)
+            cursor.execute('use "%s"' % ksname)
+            yield ksname
+            cursor.execute('use system;')
+            cursor.execute('drop keyspace "%s"' % ksname)
+
+    def test_connecting_with_cql_version(self):
+        conn = cql.connect(TEST_HOST, TEST_PORT, cql_version='2.0.0')
+        curs = conn.cursor()
+        with self.with_keyspace(curs, '2.0.0'):
+            # this should only parse in cql 2
+            curs.execute('create table foo (a int primary key) with  
comparator = float;')
+        conn.close()
+
+        if conn.remote_thrift_version >= MIN_THRIFT_FOR_CQL_3_0_0_FINAL:
+            cqlver = '3.0.0'
+        else:
+            cqlver = '3.0.0-beta1'
+        conn = cql.connect(TEST_HOST, TEST_PORT, cql_version=cqlver)
+        curs = conn.cursor()
+        with self.with_keyspace(curs, cqlver):
+            # this should only parse in cql 3
+            curs.execute('create table foo (a int, b text, c timestamp,  
primary key (a, b));')
+
+    def test_connecting_with_keyspace(self):
+        # this conn is just for creating the keyspace
+        conn = cql.connect(TEST_HOST, TEST_PORT, cql_version='2.0.0')
+        curs = conn.cursor()
+        with self.with_keyspace(curs, '2.0.0') as ksname:
+            curs.execute('create table blah1_%s (a int primary key, b  
int);' % self.randstr)
+            conn2 = cql.connect(TEST_HOST, TEST_PORT, keyspace=ksname,  
cql_version='3.0.0')
+            curs2 = conn2.cursor()
+            curs2.execute('select * from blah1_%s;' % self.randstr)
+            conn2.close()
+        with self.with_keyspace(curs, '2.0.0') as ksname:
+            curs.execute('create table blah2_%s (a int primary key, b  
int);' % self.randstr)
+            conn3 = cql.connect(TEST_HOST, TEST_PORT, keyspace=ksname,  
cql_version='3.0.0')
+            curs3 = conn3.cursor()
+            curs3.execute('select * from blah2_%s;' % self.randstr)
+            conn3.close()
+
+    def test_execution_fails_after_close(self):
+        conn = cql.connect(TEST_HOST, TEST_PORT, cql_version='3.0.0')
+        curs = conn.cursor()
+        with self.with_keyspace(curs, '3.0.0') as ksname:
+            curs.execute('create table blah (a int primary key, b int);')
+            curs.execute('select * from blah;')
+        conn.close()
+        self.assertRaises(TTransport.TTransportException,  
curs.execute, 'select * from blah;')

==============================================================================
Revision: a26caaa88cd1
Author:   paul cannon <paul@thepaul.org>
Date:     Thu Sep 20 10:58:57 2012
Log:      explicitly use cql 2 for test_cql tests

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

Modified:
  /test/test_cql.py

=======================================
--- /test/test_cql.py	Tue Sep 11 15:57:31 2012
+++ /test/test_cql.py	Thu Sep 20 10:58:57 2012
@@ -164,7 +164,8 @@
      keyspace = None

      def setUp(self):
-        dbconn = cql.connect(TEST_HOST, TEST_PORT)
+        # all tests in this module are against cql 2. change would be  
welcomed.
+        dbconn = cql.connect(TEST_HOST, TEST_PORT, cql_version='2.0.0')
          self.cursor = dbconn.cursor()
          self.randstr = randstring()
          self.keyspace = create_schema(self.cursor, self.randstr)

Mime
View raw message