Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #218 from kurtjx/master

hacky pass at uuid sorting
  • Loading branch information...
commit 7fbb698cc074946306cb4d80469103b0a00cd29c 2 parents e22f411 + 0fddc32
@thobbs thobbs authored
Showing with 29 additions and 3 deletions.
  1. +16 −2 pycassa/contrib/stubs.py
  2. +13 −1 tests/contrib/stubs.py
View
18 pycassa/contrib/stubs.py
@@ -7,6 +7,8 @@
"""
import operator
+import datetime
+from uuid import UUID
from collections import MutableMapping
from pycassa import NotFoundException
@@ -110,7 +112,7 @@ def describe_schema_versions(self):
return {self._schema(): ['1.1.1.1']}
-
+
class ColumnFamilyStub(object):
"""Functional ColumnFamily stub object.
@@ -148,9 +150,21 @@ def get(self, key, columns=None, column_start=None, column_finish=None,
if not my_columns:
raise NotFoundException()
+
items = my_columns.items()
- items.sort()
+ if isinstance(items[0], UUID) and items[0].version==1:
+ items.sort(key=lambda uuid: uuid.time)
+ elif isinstance(items[0], tuple) and any([isinstance(x, UUID) for x in items[0]]):
+ isuid = [isinstance(x, UUID) and x.version==1 for x in items[0]]
+ def sortuuid(tup):
+ return [x.time if y else x for x, y in zip(tup, isuid)]
+ items.sort(key=sortuuid)
+ else:
+ items.sort()
+
+
+
if column_reversed:
items.reverse()
View
14 tests/contrib/stubs.py
@@ -1,4 +1,5 @@
import unittest
+import time
from nose.tools import assert_raises, assert_equal, assert_true
@@ -8,7 +9,7 @@
from pycassa.contrib.stubs import ColumnFamilyStub, ConnectionPoolStub, \
SystemManagerStub
-from pycassa.util import OrderedDict
+from pycassa.util import OrderedDict, convert_time_to_uuid
pool = cf = None
pool_stub = cf_stub = None
@@ -227,3 +228,14 @@ def test_remove(self):
test_cf.remove(key)
assert_raises(NotFoundException, test_cf.get, key)
+
+ def test_insert_get_tuuids(self):
+ key = 'TestColumnFamily.test_insert_get'
+ columns = ( (convert_time_to_uuid(time.time()-1000, randomize=True), 'val1'),
+ (convert_time_to_uuid(time.time(), randomize=True), 'val2') )
+ for test_cf in (cf, cf_stub):
+ assert_raises(NotFoundException, test_cf.get, key)
+ ts = test_cf.insert(key, dict(columns))
+ assert_true(isinstance(ts, (int, long)))
+ assert_equal(test_cf.get(key).keys(), [x[0] for x in columns])
+
Please sign in to comment.
Something went wrong with that request. Please try again.