cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r912016 - in /incubator/cassandra/trunk/test/system: __init__.py test_avro_server.py test_server.py
Date Fri, 19 Feb 2010 22:29:09 GMT
Author: eevans
Date: Fri Feb 19 22:29:08 2010
New Revision: 912016

URL: http://svn.apache.org/viewvc?rev=912016&view=rev
Log:
CASSANDRA-812 stubbed out functional tests from avro

Patch by eevans for CASSANDRA-812

Added:
    incubator/cassandra/trunk/test/system/test_avro_server.py
Modified:
    incubator/cassandra/trunk/test/system/__init__.py
    incubator/cassandra/trunk/test/system/test_server.py

Modified: incubator/cassandra/trunk/test/system/__init__.py
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/system/__init__.py?rev=912016&r1=912015&r2=912016&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/system/__init__.py (original)
+++ incubator/cassandra/trunk/test/system/__init__.py Fri Feb 19 22:29:08 2010
@@ -14,14 +14,16 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import os, sys, time, signal
+import os, sys, time, signal, httplib
 
-__all__ = ['root', 'client']
+__all__ = ['root', 'thrift_client']
 
 from thrift.transport import TTransport
 from thrift.transport import TSocket
 from thrift.transport import THttpClient
 from thrift.protocol import TBinaryProtocol
+import avro.ipc as ipc
+import avro.protocol as protocol
 
 # add cassandra directory to sys.path
 L = os.path.abspath(__file__).split(os.path.sep)[:-3]
@@ -30,26 +32,40 @@
 sys.path.append(os.path.join(_ipath, 'cassandra'))
 import Cassandra
 
-def get_client(host='127.0.0.1', port=9170):
+def get_thrift_client(host='127.0.0.1', port=9170):
     socket = TSocket.TSocket(host, port)
     transport = TTransport.TBufferedTransport(socket)
     protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)
     client = Cassandra.Client(protocol)
     client.transport = transport
     return client
+thrift_client = get_thrift_client()
 
-client = get_client()
-
+def get_avro_client(host='127.0.0.1', port=9170):
+    schema = os.path.join(root, 'interface', 'cassandra.avpr')
+    proto = protocol.parse(open(schema).read())
+    conn = httplib.HTTPConnection(host, port)
+    conn.connect()
+    client = ipc.HTTPTransceiver(conn)
+    return ipc.Requestor(proto, client)
 
 pid_fname = "system_test.pid"
 def pid():
     return int(open(pid_fname).read())
 
-
-class CassandraTester(object):
+class BaseTester(object):
     # leave this True unless you are manually starting a server and then
-    # running only a single test against it; tests assume they start against an empty db.
+    # running only a single test against it; tests assume they start
+    # against an empty db.
     runserver = True
+    client = None
+    extra_args = []
+
+    def open_client(self):
+        raise NotImplementedError()
+
+    def close_client(self):
+        raise NotImplementedError()
 
     def setUp(self):
         if self.runserver:
@@ -70,7 +86,7 @@
             import subprocess as sp
             os.chdir(root)
             os.environ['CASSANDRA_INCLUDE'] = 'test/cassandra.in.sh'
-            args = ['bin/cassandra', '-p', pid_fname]
+            args = ['bin/cassandra', '-p', pid_fname] + self.extra_args
             process = sp.Popen(args, stderr=sp.PIPE, stdout=sp.PIPE)
             time.sleep(0.1)
 
@@ -78,7 +94,7 @@
             start = time.time()
             while time.time() < start + 10:
                 try:
-                    client.transport.open()
+                    self.open_client()
                 except:
                     time.sleep(0.1)
                 else:
@@ -97,17 +113,36 @@
                 sys.exit()
         else:
             try:
-                client.transport.open()
+                self.open_client()
             except:
                 pass
 
     def tearDown(self):
         if self.runserver:
-            client.transport.close()
+            self.close_client()
             open('/tmp/kill', 'w').write('killing %s\n' % pid())
             os.kill(pid(), signal.SIGTERM)
             # TODO kill server with SIGKILL if it's still alive
             time.sleep(0.5)
             # TODO assert server is Truly Dead
 
+class ThriftTester(BaseTester):
+    client = thrift_client
+
+    def open_client(self):
+        self.client.transport.open()
+
+    def close_client(self):
+        self.client.transport.close()
+
+class AvroTester(BaseTester):
+    client = None
+    extra_args = ['-a']
+
+    def open_client(self):
+        self.client = get_avro_client()
+
+    def close_client(self):
+        self.client.transceiver.conn.close()
+
 # vim:ai sw=4 ts=4 tw=0 et

Added: incubator/cassandra/trunk/test/system/test_avro_server.py
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/system/test_avro_server.py?rev=912016&view=auto
==============================================================================
--- incubator/cassandra/trunk/test/system/test_avro_server.py (added)
+++ incubator/cassandra/trunk/test/system/test_avro_server.py Fri Feb 19 22:29:08 2010
@@ -0,0 +1,44 @@
+# 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.
+
+from . import AvroTester
+
+class TestMutations(AvroTester):
+    def test_insert_and_get(self):
+        params = dict()
+        params['keyspace'] = 'Keyspace1'
+        params['key'] = 'key1'
+        params['column_path'] = dict(column_family='Standard1', column='c1')
+        params['value'] = 'v1'
+        params['timestamp'] = 1L
+        params['consistency_level'] = 'ONE'
+
+        self.client.request('insert', params)
+
+        params = dict()
+        params['keyspace'] = 'Keyspace1'
+        params['key'] = 'key1'
+        params['column_path'] = dict(column_family='Standard1', column='c1')
+        params['consistency_level'] = 'ONE'
+
+        response = self.client.request('get', params)
+
+        assert isinstance(response, dict) and response.has_key('column') \
+                and response['column'].has_key('name')
+        assert response['column']['name'] == 'c1'
+        assert response['column']['value'] == 'v1'
+        
+# vi:ai sw=4 ts=4 tw=0 et

Modified: incubator/cassandra/trunk/test/system/test_server.py
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/system/test_server.py?rev=912016&r1=912015&r2=912016&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/system/test_server.py (original)
+++ incubator/cassandra/trunk/test/system/test_server.py Fri Feb 19 22:29:08 2010
@@ -19,7 +19,8 @@
 
 import os, sys, time, struct
 
-from . import client, root, CassandraTester
+from . import root, ThriftTester
+from . import thrift_client as client
 
 from thrift.Thrift import TApplicationException
 from ttypes import *
@@ -172,7 +173,7 @@
     _expect_exception(fn, NotFoundException)
 
 
-class TestMutations(CassandraTester):
+class TestMutations(ThriftTester):
     def test_insert(self):
         _insert_simple(False)
         time.sleep(0.1)



Mime
View raw message