本文整理汇总了Python中cassandra.metadata.BytesToken类的典型用法代码示例。如果您正苦于以下问题:Python BytesToken类的具体用法?Python BytesToken怎么用?Python BytesToken使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BytesToken类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bytes_tokens
def test_bytes_tokens(self):
bytes_token = BytesToken(unhexlify(six.b('01')))
self.assertEqual(bytes_token.value, six.b('\x01'))
self.assertEqual(str(bytes_token), "<BytesToken: %s>" % bytes_token.value)
self.assertEqual(bytes_token.hash_fn('123'), '123')
self.assertEqual(bytes_token.hash_fn(123), 123)
self.assertEqual(bytes_token.hash_fn(str(cassandra.metadata.MAX_LONG)), str(cassandra.metadata.MAX_LONG))
示例2: test_token_values
def test_token_values(self):
"""
Spot check token classes and values
"""
# spot check murmur3
murmur3_token = Murmur3Token(cassandra.metadata.MIN_LONG - 1)
self.assertEqual(murmur3_token.hash_fn('123'), -7468325962851647638)
self.assertEqual(murmur3_token.hash_fn(str(cassandra.metadata.MAX_LONG)), 7162290910810015547)
self.assertEqual(str(murmur3_token), '<Murmur3Token: -9223372036854775809L>')
md5_token = MD5Token(cassandra.metadata.MIN_LONG - 1)
self.assertEqual(md5_token.hash_fn('123'), 42767516990368493138776584305024125808L)
self.assertEqual(md5_token.hash_fn(str(cassandra.metadata.MAX_LONG)), 28528976619278518853815276204542453639L)
self.assertEqual(str(md5_token), '<MD5Token: -9223372036854775809L>')
bytes_token = BytesToken(str(cassandra.metadata.MIN_LONG - 1))
self.assertEqual(bytes_token.hash_fn('123'), '123')
self.assertEqual(bytes_token.hash_fn(123), 123)
self.assertEqual(bytes_token.hash_fn(str(cassandra.metadata.MAX_LONG)), str(cassandra.metadata.MAX_LONG))
self.assertEqual(str(bytes_token), "<BytesToken: '-9223372036854775809'>")
try:
bytes_token = BytesToken(cassandra.metadata.MIN_LONG - 1)
self.fail('Tokens for ByteOrderedPartitioner should be only strings')
except TypeError:
pass
示例3: test_comparison_unicode
def test_comparison_unicode(self):
value = six.b('\'_-()"\xc2\xac')
t0 = BytesToken(value)
t1 = BytesToken.from_string('00')
self.assertGreater(t0, t1)
self.assertFalse(t0 < t1)
示例4: test_comparison
def test_comparison(self):
tok = BytesToken.from_string(six.text_type('0123456789abcdef'))
token_high_order = uint16_unpack(tok.value[0:2])
self.assertLess(BytesToken(uint16_pack(token_high_order - 1)), tok)
self.assertGreater(BytesToken(uint16_pack(token_high_order + 1)), tok)
示例5: test_from_string
def test_from_string(self):
from_unicode = BytesToken.from_string(six.text_type('0123456789abcdef'))
from_bin = BytesToken.from_string(six.b('0123456789abcdef'))
self.assertEqual(from_unicode, from_bin)
self.assertIsInstance(from_unicode.value, six.binary_type)
self.assertIsInstance(from_bin.value, six.binary_type)