本文整理匯總了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)