Skip to content

Commit

Permalink
add more robust sanity checking of get_column arguments. patch by jbe…
Browse files Browse the repository at this point in the history
…llis; reviewed by Jun Rao for CASSANDRA-151

git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@773016 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jbellis committed May 8, 2009
1 parent 85a121b commit f2260f1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
22 changes: 19 additions & 3 deletions src/java/org/apache/cassandra/service/CassandraServer.java
Expand Up @@ -212,11 +212,27 @@ public column_t get_column(String tablename, String key, String columnFamily_col
{
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();
Expand Down
19 changes: 14 additions & 5 deletions test/system/test_server.py
Expand Up @@ -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)]
Expand Down Expand Up @@ -45,13 +45,15 @@ def _verify_super(supercolumn='Super1'):
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):
Expand All @@ -62,7 +64,7 @@ def test_empty_slice_super(self):
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
Expand All @@ -89,6 +91,13 @@ def test_batch_insert_blocking(self):
_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}
Expand Down

0 comments on commit f2260f1

Please sign in to comment.