@@ -85,6 +85,89 @@ def test_replication_strategy(self):
8585 self .assertRaises (NotImplementedError , rs .make_token_replica_map , None , None )
8686 self .assertRaises (NotImplementedError , rs .export_for_schema )
8787
88+ def test_simple_replication_type_parsing (self ):
89+ """ Test equality between passing numeric and string replication factor for simple strategy """
90+ rs = ReplicationStrategy ()
91+
92+ simple_int = rs .create ('SimpleStrategy' , {'replication_factor' : 3 })
93+ simple_str = rs .create ('SimpleStrategy' , {'replication_factor' : '3' })
94+
95+ self .assertEqual (simple_int .export_for_schema (), simple_str .export_for_schema ())
96+ self .assertEqual (simple_int , simple_str )
97+
98+ # make token replica map
99+ ring = [MD5Token (0 ), MD5Token (1 ), MD5Token (2 )]
100+ hosts = [Host ('dc1.{}' .format (host ), SimpleConvictionPolicy ) for host in range (3 )]
101+ token_to_host = dict (zip (ring , hosts ))
102+ self .assertEqual (
103+ simple_int .make_token_replica_map (token_to_host , ring ),
104+ simple_str .make_token_replica_map (token_to_host , ring )
105+ )
106+
107+ def test_transient_replication_parsing (self ):
108+ """ Test that we can PARSE a transient replication factor for SimpleStrategy """
109+ rs = ReplicationStrategy ()
110+
111+ simple_transient = rs .create ('SimpleStrategy' , {'replication_factor' : '3/1' })
112+ self .assertEqual (simple_transient .replication_factor , 3 )
113+ self .assertEqual (simple_transient .transient_replicas , 1 )
114+ self .assertIn ("'replication_factor': '3/1'" , simple_transient .export_for_schema ())
115+
116+ simple_str = rs .create ('SimpleStrategy' , {'replication_factor' : '3' })
117+ self .assertNotEqual (simple_transient , simple_str )
118+
119+ # make token replica map
120+ ring = [MD5Token (0 ), MD5Token (1 ), MD5Token (2 )]
121+ hosts = [Host ('dc1.{}' .format (host ), SimpleConvictionPolicy ) for host in range (3 )]
122+ token_to_host = dict (zip (ring , hosts ))
123+ self .assertEqual (
124+ simple_transient .make_token_replica_map (token_to_host , ring ),
125+ simple_str .make_token_replica_map (token_to_host , ring )
126+ )
127+
128+ def test_nts_replication_parsing (self ):
129+ """ Test equality between passing numeric and string replication factor for NTS """
130+ rs = ReplicationStrategy ()
131+
132+ nts_int = rs .create ('NetworkTopologyStrategy' , {'dc1' : 3 , 'dc2' : 5 })
133+ nts_str = rs .create ('NetworkTopologyStrategy' , {'dc1' : '3' , 'dc2' : '5' })
134+
135+ self .assertEqual (nts_int .dc_replication_factors ['dc1' ], 3 )
136+ self .assertEqual (nts_str .dc_replication_factors ['dc1' ], 3 )
137+
138+ self .assertEqual (nts_int .export_for_schema (), nts_str .export_for_schema ())
139+ self .assertEqual (nts_int , nts_str )
140+
141+ # make token replica map
142+ ring = [MD5Token (0 ), MD5Token (1 ), MD5Token (2 )]
143+ hosts = [Host ('dc1.{}' .format (host ), SimpleConvictionPolicy ) for host in range (3 )]
144+ token_to_host = dict (zip (ring , hosts ))
145+ self .assertEqual (
146+ nts_int .make_token_replica_map (token_to_host , ring ),
147+ nts_str .make_token_replica_map (token_to_host , ring )
148+ )
149+
150+ def test_nts_transient_parsing (self ):
151+ """ Test that we can PARSE a transient replication factor for NTS """
152+ rs = ReplicationStrategy ()
153+
154+ nts_transient = rs .create ('NetworkTopologyStrategy' , {'dc1' : '3/1' , 'dc2' : '5/1' })
155+ self .assertEqual (nts_transient .dc_replication_factors ['dc1' ], '3/1' )
156+ self .assertEqual (nts_transient .dc_replication_factors ['dc2' ], '5/1' )
157+ self .assertIn ("'dc1': '3/1', 'dc2': '5/1'" , nts_transient .export_for_schema ())
158+
159+ nts_str = rs .create ('NetworkTopologyStrategy' , {'dc1' : '3' , 'dc2' : '5' })
160+ self .assertNotEqual (nts_transient , nts_str )
161+
162+ # make token replica map
163+ ring = [MD5Token (0 ), MD5Token (1 ), MD5Token (2 )]
164+ hosts = [Host ('dc1.{}' .format (host ), SimpleConvictionPolicy ) for host in range (3 )]
165+ token_to_host = dict (zip (ring , hosts ))
166+ self .assertEqual (
167+ nts_transient .make_token_replica_map (token_to_host , ring ),
168+ nts_str .make_token_replica_map (token_to_host , ring )
169+ )
170+
88171 def test_nts_make_token_replica_map (self ):
89172 token_to_host_owner = {}
90173
0 commit comments