# Path: django_sharding_library/routing_read_strategies.py
# class RoundRobinRoutingStrategy(BaseRoutingStrategy):
#     """
#     A strategy which will cycle through the read replicas and primary, in a
#     round-robin fashion when choosing which database to read from.
#     """
#     def __init__(self, databases):
#         super(RoundRobinRoutingStrategy, self).__init__(databases)
#         self.read_cycles = {}
# 
#         for primary, replicas in viewitems(self.primary_replica_mapping):
#             self.read_cycles[primary] = cycle(replicas + [primary])
# 
#     def pick_read_db(self, primary_db_name):
#         return next(self.read_cycles[primary_db_name])
# 
# class PrimaryOnlyRoutingStrategy(BaseRoutingStrategy):
#     """
#     A strategy which will always read from the primary, unless overridden,
#     regardless of replicas defined.
#     """
#     def pick_read_db(self, primary_db_name):
#         return primary_db_name


from six.moves import xrange
from django.conf import settings
from django.test import TestCase
from django_sharding_library.routing_read_strategies import RoundRobinRoutingStrategy, PrimaryOnlyRoutingStrategy
        expected_cycled_shards = ['app_shard_001_replica_001', 'app_shard_001_replica_002', 'app_shard_001']
        expected_cycled_shards.sort()

        resulting_shards = [sut.pick_read_db('app_shard_001') for i in xrange(150)]

        self.assertEqual(len(set([resulting_shards[i] for i in xrange(0, 150, 3)])), 1)
        self.assertEqual(len(set([resulting_shards[i] for i in xrange(1, 150, 3)])), 1)
        self.assertEqual(len(set([resulting_shards[i] for i in xrange(2, 150, 3)])), 1)

        resulting_cycled_shard = resulting_shards[:3]
        resulting_cycled_shard.sort()

        self.assertEqual(expected_cycled_shards, resulting_cycled_shard)


class MasterOnlyRoutingStrategyTestCase(TestCase):
    databases = '__all__'

    def test_is_always_primary(self):
        sut = PrimaryOnlyRoutingStrategy(settings.DATABASES)
        expected_shards = ['app_shard_001'] * 150

        resulting_shards = [sut.pick_read_db('app_shard_001') for i in xrange(150)]
        self.assertEqual(expected_shards, resulting_shards)


class RandomRoutingStrategyTestCase(TestCase):
    databases = '__all__'

    def test_no_exception_raised(self):

# Path: django_sharding_library/routing_read_strategies.py
# class RoundRobinRoutingStrategy(BaseRoutingStrategy):
#     """
#     A strategy which will cycle through the read replicas and primary, in a
#     round-robin fashion when choosing which database to read from.
#     """
#     def __init__(self, databases):
#         super(RoundRobinRoutingStrategy, self).__init__(databases)
#         self.read_cycles = {}
# 
#         for primary, replicas in viewitems(self.primary_replica_mapping):
#             self.read_cycles[primary] = cycle(replicas + [primary])
# 
#     def pick_read_db(self, primary_db_name):
#         return next(self.read_cycles[primary_db_name])
# 
# class PrimaryOnlyRoutingStrategy(BaseRoutingStrategy):
#     """
#     A strategy which will always read from the primary, unless overridden,
#     regardless of replicas defined.
#     """
#     def pick_read_db(self, primary_db_name):
#         return primary_db_name


# Path: tests/test_routing_read_strategies.py
from six.moves import xrange
from django.conf import settings
from django.test import TestCase
from django_sharding_library.routing_read_strategies import RoundRobinRoutingStrategy, PrimaryOnlyRoutingStrategy

        expected_cycled_shards = ['app_shard_001_replica_001', 'app_shard_001_replica_002', 'app_shard_001']
        expected_cycled_shards.sort()

        resulting_shards = [sut.pick_read_db('app_shard_001') for i in xrange(150)]

        self.assertEqual(len(set([resulting_shards[i] for i in xrange(0, 150, 3)])), 1)
        self.assertEqual(len(set([resulting_shards[i] for i in xrange(1, 150, 3)])), 1)
        self.assertEqual(len(set([resulting_shards[i] for i in xrange(2, 150, 3)])), 1)

        resulting_cycled_shard = resulting_shards[:3]
        resulting_cycled_shard.sort()

        self.assertEqual(expected_cycled_shards, resulting_cycled_shard)


class MasterOnlyRoutingStrategyTestCase(TestCase):
    databases = '__all__'

    def test_is_always_primary(self):
        sut = PrimaryOnlyRoutingStrategy(settings.DATABASES)
        expected_shards = ['app_shard_001'] * 150

        resulting_shards = [sut.pick_read_db('app_shard_001') for i in xrange(150)]
        self.assertEqual(expected_shards, resulting_shards)


class RandomRoutingStrategyTestCase(TestCase):
    databases = '__all__'

    def test_no_exception_raised(self):

        sut = RoundRobinRoutingStrategy(settings.DATABASES)