def __init__(self, outer, sessions, nodes, rf_factors, start, end, write_cl, read_cl, serial_cl=None): self.outer = outer self.sessions = sessions self.nodes = nodes self.rf_factors = rf_factors self.start = start self.end = end self.write_cl = write_cl self.read_cl = read_cl self.serial_cl = serial_cl outer.log( 'Testing accuracy with WRITE/READ/SERIAL consistency set to {}/{}/{} (keys : {} to {})' .format(consistency_value_to_name(write_cl), consistency_value_to_name(read_cl), consistency_value_to_name(serial_cl), start, end - 1))
def _test_insert_query_from_node(self, session, dc_idx, rf_factors, num_nodes_alive, write_cl, read_cl, serial_cl=None, check_ret=True): """ Test availability for read and write via the session passed in as a parameter. """ self.log("Connected to %s for %s/%s/%s" % (session.cluster.contact_points, consistency_value_to_name(write_cl), consistency_value_to_name(read_cl), consistency_value_to_name(serial_cl))) start = 0 end = 100 age = 30 if self._should_succeed(write_cl, rf_factors, num_nodes_alive, dc_idx): for n in xrange(start, end): self.insert_user(session, n, age, write_cl, serial_cl) else: assert_unavailable(self.insert_user, session, end, age, write_cl, serial_cl) if self._should_succeed(read_cl, rf_factors, num_nodes_alive, dc_idx): for n in xrange(start, end): self.query_user(session, n, age, read_cl, check_ret) else: assert_unavailable(self.query_user, session, end, age, read_cl, check_ret)
def __init__(self, outer, sessions, nodes, rf_factors, start, end, write_cl, read_cl, serial_cl=None): self.outer = outer self.sessions = sessions self.nodes = nodes self.rf_factors = rf_factors self.start = start self.end = end self.write_cl = write_cl self.read_cl = read_cl self.serial_cl = serial_cl outer.log('Testing accuracy with WRITE/READ/SERIAL consistency set to {}/{}/{} (keys : {} to {})' .format(consistency_value_to_name(write_cl), consistency_value_to_name(read_cl), consistency_value_to_name(serial_cl), start, end - 1))
def query_counter(self, session, id, val, consistency, check_ret=True): statement = SimpleStatement( "SELECT * from counters WHERE id = {}".format(id), consistency_level=consistency) ret = rows_to_list(session.execute(statement)) if check_ret: self.assertEqual( ret[0][1], val, "Got {} from {}, expected {} at {}".format( ret[0][1], session.cluster.contact_points, val, consistency_value_to_name(consistency))) return ret[0][1] if ret else 0
def query_user(self, session, userid, age, consistency, check_ret=True): statement = SimpleStatement( "SELECT userid, age FROM users where userid = {}".format(userid), consistency_level=consistency) res = session.execute(statement) expected = [[userid, age]] if age else [] ret = rows_to_list(res) == expected if check_ret: self.assertTrue( ret, "Got {} from {}, expected {} at {}".format( rows_to_list(res), session.cluster.contact_points, expected, consistency_value_to_name(consistency))) return ret
def query_counter(self, session, id, val, consistency, check_ret=True): statement = SimpleStatement("SELECT * from counters WHERE id = {}".format(id), consistency_level=consistency) ret = rows_to_list(session.execute(statement)) if check_ret: self.assertEqual(ret[0][1], val, "Got {} from {}, expected {} at {}".format(ret[0][1], session.cluster.contact_points, val, consistency_value_to_name(consistency))) return ret[0][1] if ret else 0
def query_user(self, session, userid, age, consistency, check_ret=True): statement = SimpleStatement("SELECT userid, age FROM users where userid = {}".format(userid), consistency_level=consistency) res = session.execute(statement) expected = [[userid, age]] if age else [] ret = rows_to_list(res) == expected if check_ret: self.assertTrue(ret, "Got {} from {}, expected {} at {}".format(rows_to_list(res), session.cluster.contact_points, expected, consistency_value_to_name(consistency))) return ret