Ejemplo n.º 1
0
 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))
Ejemplo n.º 2
0
 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))
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    def test_bytes_tokens(self):
        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
Ejemplo n.º 5
0
    def test_bytes_tokens(self):
        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