Author: gdusbabek
Date: Wed Sep 1 17:52:11 2010
New Revision: 991623
URL: http://svn.apache.org/viewvc?rev=991623&view=rev
Log:
move arvo supercolumn tests and cleanup
Modified:
cassandra/trunk/test/system/avro_utils.py
cassandra/trunk/test/system/test_avro_server.py
cassandra/trunk/test/system/test_avro_standard.py
cassandra/trunk/test/system/test_avro_super.py
Modified: cassandra/trunk/test/system/avro_utils.py
URL:
http://svn.apache.org/viewvc/cassandra/trunk/test/system/avro_utils.py?rev=991623&r1=991622&r2=991623&view=diff
==============================================================================
--- cassandra/trunk/test/system/avro_utils.py (original)
+++ cassandra/trunk/test/system/avro_utils.py Wed Sep 1 17:52:11 2010
@@ -1,5 +1,37 @@
+# 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.
+
+import struct
+
+def i64(i):
+ return struct.pack('>q', i)
def assert_raises(excClass, func, *args, **kwargs):
try: r = func(*args, **kwargs)
except excClass: pass
else: raise Exception('expected %s; got %s' % (excClass.__name__, r))
+
+def assert_cosc(thing, with_supercolumn=False):
+ containing = with_supercolumn and 'super_column' or 'column'
+ assert isinstance(thing, dict), "Expected dict, got %s" % type(thing)
+ assert thing.has_key(containing) and thing[containing].has_key('name'), \
+ "Invalid or missing \"%s\" member" % containing
+
+def assert_columns_match(colA, colB):
+ assert colA['name'] == colB['name'], \
+ "column name mismatch: %s != %s" % (colA['name'], colB['name'])
+ assert colA['value'] == colB['value'], \
+ "column value mismatch: %s != %s" % (colA['value'], colB['value'])
Modified: cassandra/trunk/test/system/test_avro_server.py
URL:
http://svn.apache.org/viewvc/cassandra/trunk/test/system/test_avro_server.py?rev=991623&r1=991622&r2=991623&view=diff
==============================================================================
--- cassandra/trunk/test/system/test_avro_server.py (original)
+++ cassandra/trunk/test/system/test_avro_server.py Wed Sep 1 17:52:11 2010
@@ -18,65 +18,9 @@ from . import AvroTester
from time import time
from random import randint
from avro.ipc import AvroRemoteException
-import struct
-
-def i64(i):
- return struct.pack('>q', i)
-
-def timestamp():
- return long(time() * 1e6)
-
-def new_column(suffix, stamp=None, ttl=0):
- ts = isinstance(stamp, (long,int)) and stamp or timestamp()
- column = dict()
- column['name'] = 'name-%s' % suffix
- column['value'] = 'value-%s' % suffix
- column['clock'] = {'timestamp': ts}
- column['ttl'] = ttl
- return column
-
-def assert_columns_match(colA, colB):
- assert colA['name'] == colB['name'], \
- "column name mismatch: %s != %s" % (colA['name'], colB['name'])
- assert colA['value'] == colB['value'], \
- "column value mismatch: %s != %s" % (colA['value'], colB['value'])
-
-def assert_cosc(thing, with_supercolumn=False):
- containing = with_supercolumn and 'super_column' or 'column'
- assert isinstance(thing, dict), "Expected dict, got %s" % type(thing)
- assert thing.has_key(containing) and thing[containing].has_key('name'), \
- "Invalid or missing \"%s\" member" % containing
class TestRpcOperations(AvroTester):
- def test_insert_super(self):
- "setting and getting a super column"
- self.__set_keyspace('Keyspace1')
-
- params = dict()
- params['key'] = 'key1'
- params['column_parent'] = dict()
- params['column_parent']['column_family'] = 'Super1'
- params['column_parent']['super_column'] = 'sc1'
- params['column'] = dict()
- params['column']['name'] = i64(1)
- params['column']['value'] = 'v1'
- params['column']['clock'] = { 'timestamp' : 0 }
- params['consistency_level'] = 'ONE'
- self.client.request('insert', params)
-
- read_params = dict()
- read_params['key'] = params['key']
- read_params['column_path'] = dict()
- read_params['column_path']['column_family'] = 'Super1'
- read_params['column_path']['super_column'] =
params['column_parent']['super_column']
- read_params['column_path']['column'] = params['column']['name']
- read_params['consistency_level'] = 'ONE'
-
- cosc = self.client.request('get', read_params)
-
- assert_cosc(cosc)
- assert_columns_match(cosc['column'], params['column'])
-
+
def test_describe_keyspaces(self):
"retrieving a list of all keyspaces"
keyspaces = self.client.request('describe_keyspaces', {})
@@ -108,28 +52,5 @@ class TestRpcOperations(AvroTester):
part = "org.apache.cassandra.dht.CollatingOrderPreservingPartitioner"
result = self.client.request('describe_partitioner', {})
assert result == part, "got %s, expected %s" % (result, part)
-
- def __get(self, key, cf, super_name, col_name, consistency_level='ONE'):
- """
- Given arguments for the key, column family, super column name,
- column name, and consistency level, returns a dictionary
- representing a ColumnOrSuperColumn record.
-
- Raises an AvroRemoteException if the column is not found.
- """
- params = dict()
- params['key'] = key
- params['column_path'] = dict()
- params['column_path']['column_family'] = cf
- params['column_path']['column'] = col_name
- params['consistency_level'] = consistency_level
-
- if (super_name):
- params['super_column'] = super_name
-
- return self.client.request('get', params)
-
- def __set_keyspace(self, keyspace_name):
- self.client.request('set_keyspace', {'keyspace': keyspace_name})
# vi:ai sw=4 ts=4 tw=0 et
Modified: cassandra/trunk/test/system/test_avro_standard.py
URL:
http://svn.apache.org/viewvc/cassandra/trunk/test/system/test_avro_standard.py?rev=991623&r1=991622&r2=991623&view=diff
==============================================================================
--- cassandra/trunk/test/system/test_avro_standard.py (original)
+++ cassandra/trunk/test/system/test_avro_standard.py Wed Sep 1 17:52:11 2010
@@ -17,15 +17,28 @@
from . import AvroTester
import avro_utils
+from time import time
from avro.ipc import AvroRemoteException
+def new_column(suffix, stamp=None, ttl=0):
+ ts = isinstance(stamp, (long,int)) and stamp or timestamp()
+ column = dict()
+ column['name'] = 'name-%s' % suffix
+ column['value'] = 'value-%s' % suffix
+ column['clock'] = {'timestamp': ts}
+ column['ttl'] = ttl
+ return column
+
+def timestamp():
+ return long(time() * 1e6)
+
class TestStandardOperations(AvroTester):
"""
Operations on Standard column families
"""
def test_insert_simple(self): # Also tests get
"setting and getting a simple column"
- self.client.request('set_keyspace', {'keyspace': keyspace_name})
+ self.client.request('set_keyspace', {'keyspace': 'Keyspace1'})
params = dict()
params['key'] = 'key1'
@@ -43,12 +56,12 @@ class TestStandardOperations(AvroTester)
cosc = self.client.request('get', read_params)
- assert_cosc(cosc)
- assert_columns_match(cosc['column'], params['column'])
+ avro_utils.assert_cosc(cosc)
+ avro_utils.assert_columns_match(cosc['column'], params['column'])
def test_remove_simple(self):
"removing a simple column"
- self.client.request('set_keyspace', {'keyspace': keyspace_name})
+ self.client.request('set_keyspace', {'keyspace': 'Keyspace1'})
params = dict()
params['key'] = 'key1'
@@ -66,7 +79,7 @@ class TestStandardOperations(AvroTester)
cosc = self.client.request('get', read_params)
- assert_cosc(cosc)
+ avro_utils.assert_cosc(cosc)
remove_params = read_params
remove_params['clock'] = {'timestamp': timestamp()}
@@ -78,7 +91,7 @@ class TestStandardOperations(AvroTester)
def test_batch_mutate(self):
"batching addition/removal mutations"
- self.client.request('set_keyspace', {'keyspace': keyspace_name})
+ self.client.request('set_keyspace', {'keyspace': 'Keyspace1'})
mutations = list()
@@ -100,8 +113,8 @@ class TestStandardOperations(AvroTester)
for i in range(3):
column = new_column(i)
cosc = self.__get('key1', 'Standard1', None, column['name'])
- assert_cosc(cosc)
- assert_columns_match(cosc['column'], column)
+ avro_utils.assert_cosc(cosc)
+ avro_utils.assert_columns_match(cosc['column'], column)
# Add one more column; remove one column
extra_column = new_column(3); remove_column = new_column(0)
@@ -125,12 +138,12 @@ class TestStandardOperations(AvroTester)
# Ensure successful column addition
cosc = self.__get('key1', 'Standard1', None, extra_column['name'])
- assert_cosc(cosc)
- assert_columns_match(cosc['column'], extra_column)
+ avro_utils.assert_cosc(cosc)
+ avro_utils.assert_columns_match(cosc['column'], extra_column)
def test_get_slice_simple(self):
"performing a slice of simple columns"
- self.client.request('set_keyspace', {'keyspace': keyspace_name})
+ self.client.request('set_keyspace', {'keyspace': 'Keyspace1'})
columns = list(); mutations = list()
@@ -159,9 +172,9 @@ class TestStandardOperations(AvroTester)
coscs = self.client.request('get_slice', slice_params)
- for cosc in coscs: assert_cosc(cosc)
- assert_columns_match(coscs[0]['column'], columns[0])
- assert_columns_match(coscs[1]['column'], columns[4])
+ for cosc in coscs: avro_utils.assert_cosc(cosc)
+ avro_utils.assert_columns_match(coscs[0]['column'], columns[0])
+ avro_utils.assert_columns_match(coscs[1]['column'], columns[4])
# Slicing on a range of column names
slice_range = dict()
@@ -173,14 +186,14 @@ class TestStandardOperations(AvroTester)
coscs = self.client.request('get_slice', slice_params)
- for cosc in coscs: assert_cosc(cosc)
+ for cosc in coscs: avro_utils.assert_cosc(cosc)
assert len(coscs) == 4, "expected 4 results, got %d" % len(coscs)
- assert_columns_match(coscs[0]['column'], columns[2])
- assert_columns_match(coscs[3]['column'], columns[5])
+ avro_utils.assert_columns_match(coscs[0]['column'], columns[2])
+ avro_utils.assert_columns_match(coscs[3]['column'], columns[5])
def test_multiget_slice_simple(self):
"performing a slice of simple columns, multiple keys"
- self.client.request('set_keyspace', {'keyspace': keyspace_name})
+ self.client.request('set_keyspace', {'keyspace': 'Keyspace1'})
columns = list(); mutation_params = dict()
@@ -226,7 +239,7 @@ class TestStandardOperations(AvroTester)
def test_get_count(self):
"counting columns"
- self.client.request('set_keyspace', {'keyspace': keyspace_name})
+ self.client.request('set_keyspace', {'keyspace': 'Keyspace1'})
mutations = list()
@@ -253,7 +266,7 @@ class TestStandardOperations(AvroTester)
def test_multiget_count(self):
"obtaining the column count for multiple rows"
- self.client.request('set_keyspace', {'keyspace': keyspace_name})
+ self.client.request('set_keyspace', {'keyspace': 'Keyspace1'})
mutations = list()
@@ -281,4 +294,24 @@ class TestStandardOperations(AvroTester)
for e in counts:
assert(e['count'] == 10), \
"expected 10 results for %s, got %d" % (e['key'], e['count'])
+
+ def __get(self, key, cf, super_name, col_name, consistency_level='ONE'):
+ """
+ Given arguments for the key, column family, super column name,
+ column name, and consistency level, returns a dictionary
+ representing a ColumnOrSuperColumn record.
+
+ Raises an AvroRemoteException if the column is not found.
+ """
+ params = dict()
+ params['key'] = key
+ params['column_path'] = dict()
+ params['column_path']['column_family'] = cf
+ params['column_path']['column'] = col_name
+ params['consistency_level'] = consistency_level
+
+ if (super_name):
+ params['super_column'] = super_name
+
+ return self.client.request('get', params)
Modified: cassandra/trunk/test/system/test_avro_super.py
URL:
http://svn.apache.org/viewvc/cassandra/trunk/test/system/test_avro_super.py?rev=991623&r1=991622&r2=991623&view=diff
==============================================================================
--- cassandra/trunk/test/system/test_avro_super.py (original)
+++ cassandra/trunk/test/system/test_avro_super.py Wed Sep 1 17:52:11 2010
@@ -17,11 +17,37 @@
from . import AvroTester
from avro.ipc import AvroRemoteException
+import avro_utils
class TestSuperOperations(AvroTester):
"""
Operations on Super column families
"""
- pass
- def test_test(self):
- pass
+ def test_insert_super(self):
+ "setting and getting a super column"
+ self.client.request('set_keyspace', {'keyspace': 'Keyspace1'})
+
+ params = dict()
+ params['key'] = 'key1'
+ params['column_parent'] = dict()
+ params['column_parent']['column_family'] = 'Super1'
+ params['column_parent']['super_column'] = 'sc1'
+ params['column'] = dict()
+ params['column']['name'] = avro_utils.i64(1)
+ params['column']['value'] = 'v1'
+ params['column']['clock'] = { 'timestamp' : 0 }
+ params['consistency_level'] = 'ONE'
+ self.client.request('insert', params)
+
+ read_params = dict()
+ read_params['key'] = params['key']
+ read_params['column_path'] = dict()
+ read_params['column_path']['column_family'] = 'Super1'
+ read_params['column_path']['super_column'] =
params['column_parent']['super_column']
+ read_params['column_path']['column'] = params['column']['name']
+ read_params['consistency_level'] = 'ONE'
+
+ cosc = self.client.request('get', read_params)
+
+ avro_utils.assert_cosc(cosc)
+ avro_utils.assert_columns_match(cosc['column'], params['column'])