Ejemplo n.º 1
0
    def test_nts_transient_parsing(self):
        """ Test that we can PARSE a transient replication factor for NTS """
        rs = ReplicationStrategy()

        nts_transient = rs.create('NetworkTopologyStrategy', {
            'dc1': '3/1',
            'dc2': '5/1'
        })
        self.assertEqual(nts_transient.dc_replication_factors_info['dc1'],
                         ReplicationFactor(3, 1))
        self.assertEqual(nts_transient.dc_replication_factors_info['dc2'],
                         ReplicationFactor(5, 1))
        self.assertEqual(nts_transient.dc_replication_factors['dc1'], 2)
        self.assertEqual(nts_transient.dc_replication_factors['dc2'], 4)
        self.assertIn("'dc1': '3/1', 'dc2': '5/1'",
                      nts_transient.export_for_schema())

        nts_str = rs.create('NetworkTopologyStrategy', {
            'dc1': '3',
            'dc2': '5'
        })
        self.assertNotEqual(nts_transient, nts_str)

        # make token replica map
        ring = [MD5Token(0), MD5Token(1), MD5Token(2)]
        hosts = [
            Host('dc1.{}'.format(host), SimpleConvictionPolicy)
            for host in range(3)
        ]
        token_to_host = dict(zip(ring, hosts))
        self.assertEqual(
            nts_transient.make_token_replica_map(token_to_host, ring),
            nts_str.make_token_replica_map(token_to_host, ring))
Ejemplo n.º 2
0
    def test_replication_strategy(self):
        """
        Basic code coverage testing that ensures different ReplicationStrategies
        can be initiated using parameters correctly.
        """

        rs = ReplicationStrategy()

        self.assertEqual(rs.create('OldNetworkTopologyStrategy', None), _UnknownStrategy('OldNetworkTopologyStrategy', None))
        fake_options_map = {'options': 'map'}
        uks = rs.create('OldNetworkTopologyStrategy', fake_options_map)
        self.assertEqual(uks, _UnknownStrategy('OldNetworkTopologyStrategy', fake_options_map))
        self.assertEqual(uks.make_token_replica_map({}, []), {})

        fake_options_map = {'dc1': '3'}
        self.assertIsInstance(rs.create('NetworkTopologyStrategy', fake_options_map), NetworkTopologyStrategy)
        self.assertEqual(rs.create('NetworkTopologyStrategy', fake_options_map).dc_replication_factors,
                         NetworkTopologyStrategy(fake_options_map).dc_replication_factors)

        fake_options_map = {'options': 'map'}
        self.assertIsNone(rs.create('SimpleStrategy', fake_options_map))

        fake_options_map = {'options': 'map'}
        self.assertIsInstance(rs.create('LocalStrategy', fake_options_map), LocalStrategy)

        fake_options_map = {'options': 'map', 'replication_factor': 3}
        self.assertIsInstance(rs.create('SimpleStrategy', fake_options_map), SimpleStrategy)
        self.assertEqual(rs.create('SimpleStrategy', fake_options_map).replication_factor,
                         SimpleStrategy(fake_options_map).replication_factor)

        self.assertEqual(rs.create('xxxxxxxx', fake_options_map), _UnknownStrategy('xxxxxxxx', fake_options_map))

        self.assertRaises(NotImplementedError, rs.make_token_replica_map, None, None)
        self.assertRaises(NotImplementedError, rs.export_for_schema)
Ejemplo n.º 3
0
    def test_nts_replication_parsing(self):
        """ Test equality between passing numeric and string replication factor for NTS """
        rs = ReplicationStrategy()

        nts_int = rs.create('NetworkTopologyStrategy', {'dc1': 3, 'dc2': 5})
        nts_str = rs.create('NetworkTopologyStrategy', {
            'dc1': '3',
            'dc2': '5'
        })

        self.assertEqual(nts_int.dc_replication_factors['dc1'], 3)
        self.assertEqual(nts_str.dc_replication_factors['dc1'], 3)
        self.assertEqual(nts_int.dc_replication_factors_info['dc1'],
                         ReplicationFactor(3))
        self.assertEqual(nts_str.dc_replication_factors_info['dc1'],
                         ReplicationFactor(3))

        self.assertEqual(nts_int.export_for_schema(),
                         nts_str.export_for_schema())
        self.assertEqual(nts_int, nts_str)

        # make token replica map
        ring = [MD5Token(0), MD5Token(1), MD5Token(2)]
        hosts = [
            Host('dc1.{}'.format(host), SimpleConvictionPolicy)
            for host in range(3)
        ]
        token_to_host = dict(zip(ring, hosts))
        self.assertEqual(nts_int.make_token_replica_map(token_to_host, ring),
                         nts_str.make_token_replica_map(token_to_host, ring))
Ejemplo n.º 4
0
    def test_transient_replication_parsing(self):
        """ Test that we can PARSE a transient replication factor for SimpleStrategy """
        rs = ReplicationStrategy()

        simple_transient = rs.create('SimpleStrategy',
                                     {'replication_factor': '3/1'})
        self.assertEqual(simple_transient.replication_factor_info,
                         ReplicationFactor(3, 1))
        self.assertEqual(simple_transient.replication_factor, 2)
        self.assertIn("'replication_factor': '3/1'",
                      simple_transient.export_for_schema())

        simple_str = rs.create('SimpleStrategy', {'replication_factor': '2'})
        self.assertNotEqual(simple_transient, simple_str)

        # make token replica map
        ring = [MD5Token(0), MD5Token(1), MD5Token(2)]
        hosts = [
            Host('dc1.{}'.format(host), SimpleConvictionPolicy)
            for host in range(3)
        ]
        token_to_host = dict(zip(ring, hosts))
        self.assertEqual(
            simple_transient.make_token_replica_map(token_to_host, ring),
            simple_str.make_token_replica_map(token_to_host, ring))
Ejemplo n.º 5
0
    def test_simple_replication_type_parsing(self):
        """ Test equality between passing numeric and string replication factor for simple strategy """
        rs = ReplicationStrategy()

        simple_int = rs.create('SimpleStrategy', {'replication_factor': 3})
        simple_str = rs.create('SimpleStrategy', {'replication_factor': '3'})

        self.assertEqual(simple_int.export_for_schema(), simple_str.export_for_schema())
        self.assertEqual(simple_int, simple_str)

        # make token replica map
        ring = [MD5Token(0), MD5Token(1), MD5Token(2)]
        hosts = [Host('dc1.{}'.format(host), SimpleConvictionPolicy) for host in range(3)]
        token_to_host = dict(zip(ring, hosts))
        self.assertEqual(
            simple_int.make_token_replica_map(token_to_host, ring),
            simple_str.make_token_replica_map(token_to_host, ring)
        )
Ejemplo n.º 6
0
    def test_replication_strategy(self):
        """
        Basic code coverage testing that ensures different ReplicationStrategies
        can be initiated using parameters correctly.
        """

        rs = ReplicationStrategy()

        self.assertEqual(
            rs.create("OldNetworkTopologyStrategy", None), _UnknownStrategy("OldNetworkTopologyStrategy", None)
        )
        fake_options_map = {"options": "map"}
        uks = rs.create("OldNetworkTopologyStrategy", fake_options_map)
        self.assertEqual(uks, _UnknownStrategy("OldNetworkTopologyStrategy", fake_options_map))
        self.assertEqual(uks.make_token_replica_map({}, []), {})

        fake_options_map = {"dc1": "3"}
        self.assertIsInstance(rs.create("NetworkTopologyStrategy", fake_options_map), NetworkTopologyStrategy)
        self.assertEqual(
            rs.create("NetworkTopologyStrategy", fake_options_map).dc_replication_factors,
            NetworkTopologyStrategy(fake_options_map).dc_replication_factors,
        )

        fake_options_map = {"options": "map"}
        self.assertIsNone(rs.create("SimpleStrategy", fake_options_map))

        fake_options_map = {"options": "map"}
        self.assertIsInstance(rs.create("LocalStrategy", fake_options_map), LocalStrategy)

        fake_options_map = {"options": "map", "replication_factor": 3}
        self.assertIsInstance(rs.create("SimpleStrategy", fake_options_map), SimpleStrategy)
        self.assertEqual(
            rs.create("SimpleStrategy", fake_options_map).replication_factor,
            SimpleStrategy(fake_options_map).replication_factor,
        )

        self.assertEqual(rs.create("xxxxxxxx", fake_options_map), _UnknownStrategy("xxxxxxxx", fake_options_map))

        self.assertRaises(NotImplementedError, rs.make_token_replica_map, None, None)
        self.assertRaises(NotImplementedError, rs.export_for_schema)
Ejemplo n.º 7
0
    def test_replication_strategy(self):
        """
        Basic code coverage testing that ensures different ReplicationStrategies
        can be initiated using parameters correctly.
        """

        rs = ReplicationStrategy()

        self.assertEqual(rs.create('OldNetworkTopologyStrategy', None),
                         _UnknownStrategy('OldNetworkTopologyStrategy', None))
        fake_options_map = {'options': 'map'}
        uks = rs.create('OldNetworkTopologyStrategy', fake_options_map)
        self.assertEqual(
            uks,
            _UnknownStrategy('OldNetworkTopologyStrategy', fake_options_map))
        self.assertEqual(uks.make_token_replica_map({}, []), {})

        fake_options_map = {'dc1': '3'}
        self.assertIsInstance(
            rs.create('NetworkTopologyStrategy', fake_options_map),
            NetworkTopologyStrategy)
        self.assertEqual(
            rs.create('NetworkTopologyStrategy',
                      fake_options_map).dc_replication_factors,
            NetworkTopologyStrategy(fake_options_map).dc_replication_factors)

        fake_options_map = {'options': 'map'}
        self.assertIsNone(rs.create('SimpleStrategy', fake_options_map))

        fake_options_map = {'options': 'map'}
        self.assertIsInstance(rs.create('LocalStrategy', fake_options_map),
                              LocalStrategy)

        fake_options_map = {'options': 'map', 'replication_factor': 3}
        self.assertIsInstance(rs.create('SimpleStrategy', fake_options_map),
                              SimpleStrategy)
        self.assertEqual(
            rs.create('SimpleStrategy', fake_options_map).replication_factor,
            SimpleStrategy(fake_options_map).replication_factor)

        self.assertEqual(rs.create('xxxxxxxx', fake_options_map),
                         _UnknownStrategy('xxxxxxxx', fake_options_map))

        self.assertRaises(NotImplementedError, rs.make_token_replica_map, None,
                          None)
        self.assertRaises(NotImplementedError, rs.export_for_schema)