You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jb...@apache.org on 2009/05/08 16:53:25 UTC

svn commit: r773016 - in /incubator/cassandra/trunk: src/java/org/apache/cassandra/service/CassandraServer.java test/system/test_server.py

Author: jbellis
Date: Fri May  8 14:53:25 2009
New Revision: 773016

URL: http://svn.apache.org/viewvc?rev=773016&view=rev
Log:
add more robust sanity checking of get_column arguments.  patch by jbellis; reviewed by Jun Rao for CASSANDRA-151

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraServer.java
    incubator/cassandra/trunk/test/system/test_server.py

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraServer.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraServer.java?rev=773016&r1=773015&r2=773016&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraServer.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/service/CassandraServer.java Fri May  8 14:53:25 2009
@@ -212,11 +212,27 @@
     {
         logger.debug("get_column");
         String[] values = RowMutation.getColumnAndColumnFamily(columnFamily_column);
-        if (values.length < 2)
+        if (values.length < 1)
         {
-            throw new InvalidRequestException("get_column requires both parts of columnfamily:column");
+            throw new InvalidRequestException("get_column requires non-empty columnfamily");
         }
-        ColumnFamily cfamily = readColumnFamily(new ColumnReadCommand(tablename, key, columnFamily_column));
+        if (DatabaseDescriptor.getColumnFamilyType(values[0]).equals("Standard"))
+        {
+            if (values.length != 2)
+            {
+                throw new InvalidRequestException("get_column requires both parts of columnfamily:column for standard CF " + values[0]);
+            }
+        }
+        else
+        {
+            if (values.length != 3)
+            {
+                throw new InvalidRequestException("get_column requires all parts of columnfamily:supercolumn:subcolumn for super CF " + values[0]);
+            }
+        }
+
+        ColumnReadCommand readCommand = new ColumnReadCommand(tablename, key, columnFamily_column);
+        ColumnFamily cfamily = readColumnFamily(readCommand);
         if (cfamily == null)
         {
             throw new NotFoundException();

Modified: incubator/cassandra/trunk/test/system/test_server.py
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/system/test_server.py?rev=773016&r1=773015&r2=773016&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/system/test_server.py (original)
+++ incubator/cassandra/trunk/test/system/test_server.py Fri May  8 14:53:25 2009
@@ -3,7 +3,7 @@
 from . import client, root, CassandraTester
 
 from thrift.Thrift import TApplicationException
-from ttypes import batch_mutation_t, batch_mutation_super_t, superColumn_t, column_t, NotFoundException
+from ttypes import batch_mutation_t, batch_mutation_super_t, superColumn_t, column_t, NotFoundException, InvalidRequestException
 
 _SIMPLE_COLUMNS = [column_t(columnName='c1', value='value1', timestamp=0),
                    column_t(columnName='c2', value='value2', timestamp=0)]
@@ -45,13 +45,15 @@
     slice = client.get_slice_super('Table1', 'key1', 'Super1', -1, -1)
     assert slice == _SUPER_COLUMNS, slice
 
-def _expect_missing(fn):
+def _expect_exception(fn, type_):
     try:
         r = fn()
-    except NotFoundException:
+    except type_:
         pass
     else:
-        raise Exception('expected missing result; got %s' % r)
+        raise Exception('expected %s; got %s' % (type_.__name__, r))
+def _expect_missing(fn):
+    _expect_exception(fn, NotFoundException)
 
 
 class TestMutations(CassandraTester):
@@ -62,7 +64,7 @@
         assert client.get_slice('Table1', 'key1', 'Super1', -1, -1) == []
 
     def test_missing_super(self):
-        _expect_missing(lambda: client.get_column('Table1', 'key1', 'Super1:sc1'))
+        _expect_missing(lambda: client.get_column('Table1', 'key1', 'Super1:sc1:c1'))
 
     def test_count(self):
         assert client.get_column_count('Table1', 'key1', 'Standard2') == 0
@@ -89,6 +91,13 @@
         _insert_batch(True)
         _verify_batch()
 
+    def test_bad_gets(self):
+        _expect_exception(lambda: client.get_column('Table1', 'key1', 'Standard1'), InvalidRequestException)
+        _expect_exception(lambda: client.get_column('Table1', 'key1', 'Standard1:x:y'), InvalidRequestException)
+        _expect_exception(lambda: client.get_column('Table1', 'key1', 'Super1'), InvalidRequestException)
+        _expect_exception(lambda: client.get_column('Table1', 'key1', 'Super1:x'), InvalidRequestException)
+        _expect_exception(lambda: client.get_column('Table1', 'key1', 'Super1:x:y:z'), InvalidRequestException)
+
     def test_batch_insert_super(self):
          cfmap = {'Super1': _SUPER_COLUMNS,
                   'Super2': _SUPER_COLUMNS}