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 2011/11/07 22:44:17 UTC
[cassandra-dbapi2] 3 new revisions pushed by pcannon@gmail.com on
2011-11-07 21:44 GMT
3 new revisions:
Revision: 915b1789fcd5
Author: paul cannon <pa...@riptano.com>
Date: Fri Nov 4 14:31:47 2011
Log: avoid relative in-package imports...
http://code.google.com/a/apache-extras.org/p/cassandra-dbapi2/source/detail?r=915b1789fcd5
Revision: 820e18dee00c
Author: paul cannon <pa...@riptano.com>
Date: Fri Nov 4 14:20:53 2011
Log: allow overriding cluster addr/port when testing
http://code.google.com/a/apache-extras.org/p/cassandra-dbapi2/source/detail?r=820e18dee00c
Revision: aa4ebaa32085
Author: paul cannon <pa...@riptano.com>
Date: Mon Nov 7 13:42:10 2011
Log: skip some tests if run against RandomPartitioner
http://code.google.com/a/apache-extras.org/p/cassandra-dbapi2/source/detail?r=aa4ebaa32085
==============================================================================
Revision: 915b1789fcd5
Author: paul cannon <pa...@riptano.com>
Date: Fri Nov 4 14:31:47 2011
Log: avoid relative in-package imports
they'll work, but in some versions of Python should produce a warning
(see PEP-328). the marshal module makes this worse, since there is an
official Python module by the same name which will get imported instead
after the import rules change. if we can require Python 2.5 with this
library, we could just use the explicit relative-import syntax, but it
looks like everything else here is compatible with Python 2.4, so we
should probably maintain that as long as feasible.
Changed all relative imports within the cql package to absolute imports,
resolved using the 'cql' name.
http://code.google.com/a/apache-extras.org/p/cassandra-dbapi2/source/detail?r=915b1789fcd5
Modified:
/cql/__init__.py
/cql/connection.py
/cql/connection_pool.py
/cql/decoders.py
=======================================
--- /cql/__init__.py Fri Sep 9 10:07:55 2011
+++ /cql/__init__.py Fri Nov 4 14:31:47 2011
@@ -19,8 +19,8 @@
import datetime
import time
-import connection
-import marshal
+from cql import connection
+from cql import marshal
# dbapi Error hierarchy
=======================================
--- /cql/connection.py Wed Aug 24 11:18:52 2011
+++ /cql/connection.py Fri Nov 4 14:31:47 2011
@@ -15,8 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from cursor import Cursor
-from cassandra import Cassandra
+from cql.cursor import Cursor
+from cql.cassandra import Cassandra
from thrift.transport import TTransport, TSocket
from thrift.protocol import TBinaryProtocol
from cql.cassandra.ttypes import AuthenticationRequest
=======================================
--- /cql/connection_pool.py Mon Feb 21 08:55:19 2011
+++ /cql/connection_pool.py Fri Nov 4 14:31:47 2011
@@ -18,7 +18,7 @@
from Queue import Queue, Empty
from threading import Thread
from time import sleep
-from connection import Connection
+from cql.connection import Connection
__all__ = ['ConnectionPool']
=======================================
--- /cql/decoders.py Mon Nov 7 12:27:00 2011
+++ /cql/decoders.py Fri Nov 4 14:31:47 2011
@@ -16,7 +16,7 @@
# limitations under the License.
import cql
-from marshal import (unmarshallers, unmarshal_noop)
+from cql.marshal import (unmarshallers, unmarshal_noop)
class SchemaDecoder(object):
"""
==============================================================================
Revision: 820e18dee00c
Author: paul cannon <pa...@riptano.com>
Date: Fri Nov 4 14:20:53 2011
Log: allow overriding cluster addr/port when testing
http://code.google.com/a/apache-extras.org/p/cassandra-dbapi2/source/detail?r=820e18dee00c
Added:
/test/__init__.py
Modified:
/test/test_cql.py
=======================================
--- /test/test_cql.py Tue Sep 27 13:40:05 2011
+++ /test/test_cql.py Fri Nov 4 14:20:53 2011
@@ -16,7 +16,13 @@
# limitations under the License.
# to run a single test, run from trunk/:
-# PYTHONPATH=test nosetests
--tests=system.test_cql:TestCql.test_column_count
+# PYTHONPATH=test nosetests --tests=test_cql:TestCql.test_column_count
+
+# Note that some tests will fail if run against a cluster with
+# RandomPartitioner.
+
+# to configure behavior, define $CQL_TEST_HOST to the destination address
+# for Thrift connections, and $CQL_TEST_PORT to the associated port.
from os.path import abspath, dirname, join
from random import choice
@@ -24,14 +30,17 @@
from thrift.transport import TSocket
from thrift.transport import THttpClient
from thrift.protocol import TBinaryProtocol
-import sys, uuid, time
+import sys, os, uuid, time
+
+TEST_HOST = os.environ.get('CQL_TEST_HOST', 'localhost')
+TEST_PORT = int(os.environ.get('CQL_TEST_PORT', 9170))
sys.path.append(join(abspath(dirname(__file__)), '..'))
import cql
from cql.cassandra import Cassandra
-def get_thrift_client(host='127.0.0.1', port=9170):
+def get_thrift_client(host=TEST_HOST, port=TEST_PORT):
socket = TSocket.TSocket(host, port)
transport = TTransport.TFramedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
@@ -158,7 +167,7 @@
keyspace = None
def setUp(self):
- dbconn = cql.connect('localhost', 9170)
+ dbconn = cql.connect(TEST_HOST, TEST_PORT)
self.cursor = dbconn.cursor()
self.keyspace = create_schema(self.cursor)
load_sample(self.cursor)
==============================================================================
Revision: aa4ebaa32085
Author: paul cannon <pa...@riptano.com>
Date: Mon Nov 7 13:42:10 2011
Log: skip some tests if run against RandomPartitioner
http://code.google.com/a/apache-extras.org/p/cassandra-dbapi2/source/detail?r=aa4ebaa32085
Modified:
/test/test_cql.py
=======================================
--- /test/test_cql.py Fri Nov 4 14:20:53 2011
+++ /test/test_cql.py Mon Nov 7 13:42:10 2011
@@ -18,7 +18,7 @@
# to run a single test, run from trunk/:
# PYTHONPATH=test nosetests --tests=test_cql:TestCql.test_column_count
-# Note that some tests will fail if run against a cluster with
+# Note that some tests will be skipped if run against a cluster with
# RandomPartitioner.
# to configure behavior, define $CQL_TEST_HOST to the destination address
@@ -31,6 +31,7 @@
from thrift.transport import THttpClient
from thrift.protocol import TBinaryProtocol
import sys, os, uuid, time
+import unittest
TEST_HOST = os.environ.get('CQL_TEST_HOST', 'localhost')
TEST_PORT = int(os.environ.get('CQL_TEST_PORT', 9170))
@@ -162,7 +163,7 @@
""")
-class TestCql(object):
+class TestCql(unittest.TestCase):
cursor = None
keyspace = None
@@ -181,12 +182,15 @@
# Cleanup keyspaces created by test-cases
for ks in ("AlterTableKS", "CreateCFKeyspace", "Keyspace4CFDrop", \
- "TestKeyspace42", "DropIndexTests"):
+ "TestKeyspace42", "TestKeyspace43", "DropIndexTests"):
try:
self.cursor.execute("DROP KEYSPACE :ks", dict(ks=ks))
except:
pass
+ def get_partitioner(self):
+ return thrift_client.describe_partitioner()
+
def test_select_simple(self):
"single-row named column queries"
@@ -215,6 +219,10 @@
def test_select_row_range(self):
"retrieve a range of rows with columns"
+
+ if self.get_partitioner().split('.')[-1] == 'RandomPartitioner':
+ self.skipTest("Key ranges don't make sense under RP")
+
# everything
cursor = self.cursor
cursor.execute("SELECT * FROM StandardLongA")
@@ -297,13 +305,6 @@
row = cursor.fetchone()
assert ['1', '2', '3'] == row, row
- cursor.execute("""
- SELECT key,20,40 FROM StandardIntegerA
- WHERE KEY > 'k1' AND KEY < 'k7' LIMIT 5
- """)
- row = cursor.fetchone()
- assert ['k2', 'f', 'h'] == row, row
-
# range of columns (slice) by row with FIRST
cursor.execute("SELECT FIRST 1 1..3 FROM StandardLongA WHERE KEY
= 'aa'")
assert cursor.rowcount == 1
@@ -316,6 +317,7 @@
row = cursor.fetchone()
assert ['3', '2'] == row, row
+
def test_select_range_with_single_column_results(self):
"range should not fail when keys were not set"
cursor = self.cursor
@@ -333,14 +335,18 @@
assert cursor.rowcount == 3, "expected 3 results, got %d" %
cursor.rowcount
+ # if using RP, these won't be sorted, so we'll sort. other tests
take care of
+ # checking sorted-ness under non-RP partitioners anyway.
+ rows = sorted(cursor.fetchall())
+
# two of three results should contain one column "name", third
should be empty
for i in range(1, 3):
- r = cursor.fetchone()
+ r = rows[i - 1]
assert len(r) == 2
- assert r[0] == "user%d" % i
- assert r[1] == "%s" % i
-
- r = cursor.fetchone()
+ assert r[0] == "user%d" % i, r
+ assert r[1] == "%s" % i, r
+
+ r = rows[2]
assert len(r) == 2
assert r[0] == "user3"
assert r[1] == None
@@ -374,6 +380,10 @@
def test_index_scan_with_start_key(self):
"indexed scan with a starting key"
+
+ if self.get_partitioner().split('.')[-1] == 'RandomPartitioner':
+ self.skipTest("Key ranges don't make sense under RP")
+
cursor = self.cursor
cursor.execute("""
SELECT KEY, 'birthdate' FROM IndexedA
@@ -388,7 +398,7 @@
cursor = self.cursor
cursor.execute("SELECT KEY, 'col' FROM StandardString1 LIMIT 3")
assert cursor.rowcount == 3
- rows = cursor.fetchmany(3)
+ rows = sorted(cursor.fetchmany(3))
assert rows[0][0] == "ka"
assert rows[1][0] == "kb"
assert rows[2][0] == "kc"