# Path: tooz/hashring.py
# class UnknownNode(tooz.ToozError):
# class HashRing(object):
#     def __init__(self, node):
#     def __init__(self, nodes, partitions=DEFAULT_PARTITION_NUMBER,
#                  hash_function=DEFAULT_HASH_FUNCTION):
#     def add_node(self, node, weight=1):
#     def add_nodes(self, nodes, weight=1):
#     def remove_node(self, node):
#     def _hash2int(key):
#     def _get_partition(self, data):
#     def _get_node(self, partition):
#     def get_nodes(self, data, ignore_nodes=None, replicas=1):
#     def __getitem__(self, key):
#     def __len__(self):
#     DEFAULT_PARTITION_NUMBER = 2**5
#     DEFAULT_HASH_FUNCTION = 'md5'


import hashlib
from unittest import mock
from testtools import matchers
from testtools import testcase
from tooz import hashring
#    under the License.





class HashRingTestCase(testcase.TestCase):

    # NOTE(deva): the mapping used in these tests is as follows:
    #             if nodes = [foo, bar]:
    #                fake -> foo, bar
    #             if nodes = [foo, bar, baz]:
    #                fake -> foo, bar, baz
    #                fake-again -> bar, baz, foo

    try:
        _ = hashlib.md5(usedforsecurity=False)
        _fips_enabled = True
    except TypeError:
        _fips_enabled = False

    @mock.patch.object(hashlib, 'md5', autospec=True)
    def test_hash2int_returns_int(self, mock_md5):
        r1 = 32 * 'a'
        r2 = 32 * 'b'
        # 2**PARTITION_EXPONENT calls to md5.update per node
        # PARTITION_EXPONENT is currently always 5, so 32 calls each here
        mock_md5.return_value.hexdigest.side_effect = [r1] * 32 + [r2] * 32

        nodes = ['foo', 'bar']

# Path: tooz/hashring.py
# class UnknownNode(tooz.ToozError):
# class HashRing(object):
#     def __init__(self, node):
#     def __init__(self, nodes, partitions=DEFAULT_PARTITION_NUMBER,
#                  hash_function=DEFAULT_HASH_FUNCTION):
#     def add_node(self, node, weight=1):
#     def add_nodes(self, nodes, weight=1):
#     def remove_node(self, node):
#     def _hash2int(key):
#     def _get_partition(self, data):
#     def _get_node(self, partition):
#     def get_nodes(self, data, ignore_nodes=None, replicas=1):
#     def __getitem__(self, key):
#     def __len__(self):
#     DEFAULT_PARTITION_NUMBER = 2**5
#     DEFAULT_HASH_FUNCTION = 'md5'


# Path: tooz/tests/test_hashring.py
import hashlib
from unittest import mock
from testtools import matchers
from testtools import testcase
from tooz import hashring

#    under the License.





class HashRingTestCase(testcase.TestCase):

    # NOTE(deva): the mapping used in these tests is as follows:
    #             if nodes = [foo, bar]:
    #                fake -> foo, bar
    #             if nodes = [foo, bar, baz]:
    #                fake -> foo, bar, baz
    #                fake-again -> bar, baz, foo

    try:
        _ = hashlib.md5(usedforsecurity=False)
        _fips_enabled = True
    except TypeError:
        _fips_enabled = False

    @mock.patch.object(hashlib, 'md5', autospec=True)
    def test_hash2int_returns_int(self, mock_md5):
        r1 = 32 * 'a'
        r2 = 32 * 'b'
        # 2**PARTITION_EXPONENT calls to md5.update per node
        # PARTITION_EXPONENT is currently always 5, so 32 calls each here
        mock_md5.return_value.hexdigest.side_effect = [r1] * 32 + [r2] * 32

        nodes = ['foo', 'bar']

        ring = hashring.HashRing(nodes)