def ask(mess, responses=["OK", "Cancel"], default=0, cancel=-1, wrap_width=60, **kwds): # If height is specified as a keyword, the Dialog object will have this haight, and the inner massage will # be displayed in a scrolling widget colLbl = kwds.pop('colLabel', "") box = Dialog(**kwds) d = box.margin lb = wrapped_label(mess, wrap_width) buts = [] for caption in responses: but = Button(caption, action=lambda x=caption: box.dismiss(x)) buts.append(but) brow = Row(buts, spacing=d) lb.width = max(lb.width, brow.width) height = kwds.get('height', None) if height and lb.height > height - (2 * brow.height) - ScrollPanel.column_margin - box.margin: lines = mess.split('\n') # ScrolledPanel refuses to render properly for now, so Tableview is used instead. w = TableView().font.size(_(colLbl))[0] lb = TableView(columns=[TableColumn(colLbl, max(lb.width, w)),], nrows=(height - (2 * brow.height) - box.margin - box.font.get_linesize()) / box.font.get_linesize(), height=height - (2 * brow.height) - (box.font.get_linesize() * 2) - box.margin) #, width=w) def num_rows(): return len(lines) lb.num_rows = num_rows lb.row_data = lambda x: (lines[x],) lb.topleft = (d, d) lb.width = max(lb.width, brow.width) col = Column([lb, brow], spacing=d, align='r') col.topleft = (d, d) if default is not None: box.enter_response = responses[default] buts[default].is_default = True else: box.enter_response = None if cancel is not None: box.cancel_response = responses[cancel] else: box.cancel_response = None box.add(col) box.shrink_wrap() def dispatchKeyForAsk(name, evt): if name == "key_down": if box.root.getKey(evt) == "Return": if default is not None: box.dismiss(responses[default]) box.dispatch_key = dispatchKeyForAsk return box.present()
def test_book_flight(self): num_tickets_to_book = 3 flight_ids = self.__get_flight_ids("American Airlines") endpoint = "http://%s/%s" % (self.profile_endpoint, "confirmBooking") table = TableView(self.log.info) table.set_headers(["Username", "Booking ID", "Status", "Class", "Num Seats"]) for index in range(1, num_tickets_to_book): username = self.username_format % index booking_data = { "username": username, "password": self.password, "flightId": choice(flight_ids), "flightSeats": choice(range(1, 3)), "bookingClass": "economy", "bankAccount": hashlib.md5( username.encode('utf-8')).hexdigest() } response = RestHelper.post_request(endpoint, booking_data) if response.status_code != 200: self.log.error("Request returned code %s: %s" % (response.status_code, response.json())) self.fail("Booking failed") response = response.json()["Msg"] table.add_row([username, response["id"], response["status"], response["bookingClass"], response["flightSeats"]]) table.display("Booking details:")
def main_curses(stdscr, lines, d): curses.curs_set(0) curses.init_pair(1, 251, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_YELLOW) # change color curses.init_pair(3, 238, curses.COLOR_BLACK) curses.init_pair(4, 237, curses.COLOR_BLACK) offset = (0, 0) table = TableView(lines, d) table_pad = curses.newpad(table.height + 1, table.width) # TODO: Get width of output pad from column offsets output_pad = curses.newpad(table.height * table.column_number + 1, table.width) draw(stdscr, table_pad, output_pad, offset, table) while True: c = stdscr.getch() if c == ord('q'): return elif c in TableView.DIRECTIONS.keys(): di, dj = TableView.DIRECTIONS[c] table.move(di, dj) elif c == ord(' '): table.toggle_select() elif c == ord('d'): table.clear_selection() elif c == ord('c'): table.select_column() elif c == ord('\n') or c == curses.KEY_ENTER: print('<enter> => print and copy selected cells') return process_output(table) offset = draw(stdscr, table_pad, output_pad, offset, table)
def main(): t = Table() t_dal = Table_DAL() t_dal.load("test.db", "animals", t) tv = TableView(t) tv.render() tv.render_text()
def __get_purged_tombstone_from_last_run(self, nodes=None): """ :return last_purged_tombstones: Dict of format, { node_ip: {'count': N, 'keys': [k1, k2, ..] }, ...} """ tail_cmd = "cat %s/var/lib/couchbase/logs/debug.log " \ % self.couchbase_base_dir \ + "| sed -n '/%s/,$p'" purged_ts_count_pattern = ".*Purged ([0-9]+) ns_config tombstone" meta_kv_keys_pattern = ".*{metakv,[ ]*<<\"/([0-9a-zA-Z_\-\.]+)\">>" start_of_line = "^\[ns_server:" start_of_line = re.compile(start_of_line) meta_kv_keys_pattern = re.compile(meta_kv_keys_pattern) purged_ts_count_pattern = re.compile(purged_ts_count_pattern) tbl_view = TableView(self.log.info) tbl_view.set_headers(["Node", "Purged Keys"]) last_purged_tombstones = dict() if nodes is None: nodes = self.cluster_util.get_nodes_in_cluster(self.cluster) for node in nodes: self.log.info("Processing debug logs from %s" % node.ip) shell = RemoteMachineShellConnection(node) output, _ = shell.execute_command( tail_cmd % self.ts_during_start[node.ip]) if not output: output, _ = shell.execute_command( " ".join(tail_cmd.split(' ')[:2])) self.log.debug("Tail stdout:\n%s" % output) o_len = len(output) target_buffer = "" total_ts_purged = 0 for index in range(o_len-1, -1, -1): line = output[index] if not start_of_line.match(line): target_buffer = line + target_buffer elif "tombstone_agent:purge:" in line: total_ts_purged = \ purged_ts_count_pattern.match(line).group(1) break else: target_buffer = "" last_purged_tombstones[node.ip] = dict() last_purged_tombstones[node.ip]["count"] = int(total_ts_purged) last_purged_tombstones[node.ip]["keys"] = \ meta_kv_keys_pattern.findall(target_buffer) tbl_view.add_row([node.ip, total_ts_purged]) shell.disconnect() tbl_view.display("Purged_keys:") self.log.debug("Purged keys :: %s" % last_purged_tombstones) return last_purged_tombstones
def print_crud_stats(self): self.table = TableView(self.log.info) self.table.set_headers(["Initial Items", "Current Items", "Items Updated", "Items Created", "Items Deleted"]) if self._iter_count != 0: self.table.add_row([str(self.start - self.initial_load_count*self.delete_perc/100*(self._iter_count-1)), str(self.end- self.initial_load_count*self.delete_perc/100*self._iter_count), str(self.update_perc - self.update_perc) + "---" + str(self.initial_load_count*self.update_perc/100), str(self.start) + "---" + str(self.end), str(self.start - self.initial_load_count*self.create_perc/100) + "---" + str(self.start + (self.initial_load_count*self.delete_perc/100) - self.initial_load_count*self.create_perc/100)]) self.table.display("Docs statistics")
def test_cancel_booking(self): endpoint = "http://%s/%s" % (self.profile_endpoint, "allBookings") booked_tickets = list() for index in range(1, 11): username = self.username_format % index auth_data = {"username": username, "password": self.password} response = RestHelper.post_request(endpoint, auth_data) if response.status_code != 200: self.log.error("Request returned code %s: %s" % (response.status_code, response.json())) self.fail("Fetching booking history failed") bookings = response.json()["Msg"][0]["bookings"] if len(bookings) > 0: booked_tickets.append([username, bookings]) target_user = choice(booked_tickets) booking_id = choice(target_user[1]) self.log.info("Cancel %s for user %s" % (booking_id, target_user[0])) endpoint = "http://%s/%s" % (self.profile_endpoint, "cancelBooking") data = {"username": target_user[0], "password": self.password, "id": booking_id} response = RestHelper.post_request(endpoint, data) if response.status_code != 200: self.log.error("Request returned code %s: %s" % (response.status_code, response.json())) self.fail("Fetching booking history failed") # Fetch booking status to confirm cancellation endpoint = "http://%s/%s" % (self.profile_endpoint, "getBooking") data = {"username": target_user[0], "password": self.password, "id": booking_id} response = RestHelper.post_request(endpoint, data) if response.status_code != 200: self.log.error("Request returned code %s: %s" % (response.status_code, response.json())) self.fail("Fetching booking history failed") response = response.json()["Msg"] table = TableView(self.log.info) table.add_row(["Booking ID", response["id"]]) table.add_row(["Flight", response["flightId"]]) table.add_row(["Status", response["status"]]) table.add_row(["Seats", "%s (%s)" % (response["flightSeats"], ", ".join(response["TicketsBooked"]))]) table.add_row(["Class", response["bookingClass"]]) table.display("Ticket status:") self.assertEqual(response["status"], "Booking Cancelled")
def __get_deleted_key_count(self, check_if_zero=False): deleted_keys = self.cluster_util.get_ns_config_deleted_keys_count() tbl = TableView(self.log.info) tbl.set_headers(["Node", "Deleted_key_count"]) for t_ip, k_count in deleted_keys.items(): tbl.add_row(["%s" % t_ip, "%s" % k_count]) tbl.display("Tombstone count on cluster nodes:") if not check_if_zero: return for t_ip, k_count in deleted_keys.items(): if k_count != 0: self.fail("%s Deleted key count %s != 0" % (t_ip, k_count))
def print_spec_details(self, spec, cycles, elapsed_time): table = TableView(self.log.info) table.set_headers(["Operation", "Value"]) table.add_row([ "Collections dropped and recreated", str(spec[MetaCrudParams.COLLECTIONS_TO_RECREATE]) ]) table.add_row([ "Scopes dropped and recreated", str(spec[MetaCrudParams.SCOPES_TO_RECREATE]) ]) table.add_row(["Cycles of data load", str(cycles)]) table.add_row(["Time Elapsed in secs", str(elapsed_time)]) table.display("Data load details")
def print_crud_stats(self): self.table = TableView(self.log.info) self.table.set_headers([ "Initial Items", "Current Items", "Items Updated", "Items Created", "Items Deleted", "Items Expired" ]) self.table.add_row([ str(self.initial_items), str(self.final_items), str(self.update_start) + "-" + str(self.update_end), str(self.create_start) + "-" + str(self.create_end), str(self.delete_start) + "-" + str(self.delete_end), str(self.expire_start) + "-" + str(self.expire_end) ]) self.table.display("Docs statistics")
def __init__(self): """ Basic widget to display an example of a table view with underlying model and proxy model Either read or directly define: a list of column names, a list of lists (row[column]) holding table data, and a dict of dicts holding information (Type, Label, Alignment, Width, and other other info) for each column name. """ super().__init__() columns = ["name", "number1", "number2", "highscore"] data = [["David", 4, 6, True], ["David", 5, 2, False], ["Sarah", 0, 2, False], ["Evan", 9, 1, True], ["Leah", 6, 4, True]] info = { "name": { "Type": "str", "Label": "Name", "Alignment": "left", "Width": 120 }, "number1": { "Type": "int", "Label": "Number 1", "Alignment": "center", "Width": 80 }, "number2": { "Type": "int", "Label": "Number 2", "Alignment": "center", "Width": 80 }, "highscore": { "Type": "bool", "Label": "High score?", "Alignment": "center", "Width": 80 } } self.table_model = TableModel(columns, data, info) self.proxy_model = ProxyModel(self.table_model) self.table_view = TableView(self, self.proxy_model, "My table") self.filter_combo = QComboBox() self.reset_button = QPushButton("Reset filters") self.setup(data) self.filter_combo.currentTextChanged.connect(self.apply_filter) self.reset_button.clicked.connect(self.proxy_model.reset_filters) self.delegates = {} self.setup_delegates()
def test_list_booking_history(self): table = TableView(self.log.info) table.set_headers(["Username", "Num tickets", "IDs"]) num_tickets_to_book = 3 endpoint = "http://%s/%s" % (self.profile_endpoint, "allBookings") for index in range(1, num_tickets_to_book): username = self.username_format % index auth_data = {"username": username, "password": self.password} response = RestHelper.post_request(endpoint, auth_data) if response.status_code != 200: self.log.error("Request returned code %s: %s" % (response.status_code, response.json())) self.fail("Fetching booking history failed") bookings = response.json()["Msg"][0]["bookings"] table.add_row([username, len(bookings), "\n".join(bookings)]) table.display("Booking history:")
def view_factory(view_name): """Very simple form of factory function Used to decouple other modules from specific view implementations. """ view = None if view_name == TableView.__name__: view = TableView() elif view_name == StatsView.__name__: view = StatsView() elif view_name == ArenaView.__name__: view = ArenaView() elif view_name == MoveStatsView.__name__: view = MoveStatsView() elif view_name == PerceptionView.__name__: view = PerceptionView() else: raise Error('Bad view name!') return view
def print_cluster_stats(self): table = TableView(self.log.info) table.set_headers([ "Node", "Services", "CPU_utilization", "Mem_total", "Mem_free", "Swap_mem_total", "Swap_mem_used" ]) rest = RestConnection(self.cluster.master) cluster_stat = rest.get_cluster_stats() for cluster_node, node_stats in cluster_stat.items(): row = list() row.append(cluster_node.split(':')[0]) row.append(str(node_stats["services"])) row.append(str(node_stats["cpu_utilization"])) row.append(str(node_stats["mem_total"])) row.append(str(node_stats["mem_free"])) row.append(str(node_stats["swap_mem_total"])) row.append(str(node_stats["swap_mem_used"])) table.add_row(row) table.display("Cluster statistics")
def check_replica_eviction(): tbl = TableView(self.log.info) tbl.set_headers([ "Node", "Memory", "WM_Threshold", "Itm_mem", "Meta_mem", "Evictable_mem", "A_rr", "R_rr" ]) while self.test_failure is None and run_eviction_check: tbl.rows = [] for kv_node in node_data.keys(): all_stats = \ node_data[kv_node]["cbstat"].all_stats(bucket.name) bucket_mem = int(all_stats["ep_max_size"]) wm_threshold = \ (float(all_stats["ep_mem_high_wat_percent"]) - float(all_stats["ep_mem_low_wat_percent"]))*100 evictable_mem = \ int(all_stats["vb_replica_itm_memory"]) \ - int(all_stats["vb_replica_meta_data_memory"]) active_rr = int(all_stats["vb_active_perc_mem_resident"]) replica_rr = int(all_stats["vb_replica_perc_mem_resident"]) tbl.add_row([ kv_node.ip, str(bucket_mem), str(wm_threshold), all_stats["vb_replica_itm_memory"], all_stats["vb_replica_meta_data_memory"], str(evictable_mem), str(active_rr), str(replica_rr) ]) if active_rr != 100 \ and evictable_mem > (bucket_mem/wm_threshold): tbl.display("Node memory stats") self.log_failure("%s - Active keys evicted before " "meeting the threshold: %s" % (kv_node.ip, all_stats)) if replica_rr > active_rr: tbl.display("Node memory stats") self.log_failure( "%s: (active_rr) %s < %s (replica_rr)" % (kv_node.ip, active_rr, replica_rr))
def test_get_flights_for_airline(self): target_airline = "American Airlines" rest_url = "http://%s/%s/%s" % (self.inventory_endpoint, "flights", urllib.parse.quote(target_airline)) response = RestHelper.get_request(rest_url) if response.status_code != 200: raise Exception("Requests status content:{0}".format( response.content)) self.log.info("Flights for airline: %s" % target_airline) table = TableView(self.log.info) table.set_headers([ "Flight Id", "Model", "Departure", "Arrival", "Departure Time", "Status" ]) for f_data in response.json(): f_data = f_data["flights"] table.add_row([ f_data["flight_id"], f_data["model"], f_data["departing_airport"], f_data["arriving_airport"], f_data["departure_date"], f_data["status"] ]) table.display("Flights for airline: %s" % target_airline)
def __init__(self): QMainWindow.__init__(self) self.setWindowTitle("Anatidae") self.resize(739, 481) self.splitter = QtWidgets.QSplitter() self.table_view = TableView(self.splitter) self.robot_tabs = RobotTabs(self.splitter) self.splitter.setStretchFactor(0, 1) self.setCentralWidget(self.splitter) self.robot_tabs.setCurrentIndex(-1) # self.menubar = QtWidgets.QMenuBar(self) # self.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(self) self.setStatusBar(self.statusbar) self.pos_label = QtWidgets.QLabel() self.cmd_label = QtWidgets.QLabel() font = QFontDatabase.systemFont(QFontDatabase.FixedFont) self.pos_label.setFont(font) self.cmd_label.setFont(font) self.statusbar.addPermanentWidget(self.cmd_label, 1) self.statusbar.addPermanentWidget(self.pos_label) self.robot_manager = RobotsManager() self.robot_tabs.set_robot_manager(self.robot_manager) self.table_view.set_robot_manager(self.robot_manager) self.table_view.setFocus() self.logger = Logger("/tmp/robot.log") #self.rsp= RadioSP("/dev/pts/5", 115200, self.logger, rid="Daneel", parent=self) self.table_view.mouse_pos_changed.connect(self.update_mouse_pos) self.table_view.pos_cmd_changed.connect(self.update_pos_cmd) self.rudps = [] for c in cs: r = RadioUDP(c, self.logger, parent=self) self.robot_manager.add_radio(r) self.rudps.append(r)
def test_timeout_with_crud_failures(self): """ Test to make sure timeout is handled in durability calls and no documents are loaded when durability cannot be met using error simulation in server node side This will validate failure in majority of nodes, where durability will surely fail for all CRUDs 1. Select a node from the cluster to simulate the specified error 2. Perform CRUD on the target bucket with given timeout 3. Using cbstats to verify no operations succeeds 4. Revert the error scenario from the cluster to resume durability 5. Validate all mutations are succeeded after reverting the error condition Note: self.sdk_timeout values is considered as 'seconds' """ # Local method to validate vb_seqno def validate_vb_seqno_stats(): """ :return retry_validation: Boolean denoting to retry validation """ retry_validation = False vb_info["post_timeout"][node.ip] = \ cbstat_obj[node.ip].vbucket_seqno(self.bucket.name) for vb_id in range(self.cluster.vbuckets): vb_id = str(vb_id) if vb_id not in affected_vbs: if vb_id in vb_info["init"][node.ip].keys() \ and vb_info["init"][node.ip][vb_id] \ != vb_info["post_timeout"][node.ip][vb_id]: self.log_failure( "Unaffected vb-%s stat updated: %s != %s" % (vb_id, vb_info["init"][node.ip][vb_id], vb_info["post_timeout"][node.ip][vb_id])) elif int(vb_id) \ in target_nodes_vbuckets[Bucket.vBucket.ACTIVE]: if vb_id in vb_info["init"][node.ip].keys() \ and vb_info["init"][node.ip][vb_id] \ != vb_info["post_timeout"][node.ip][vb_id]: self.log.warning( err_msg % (node.ip, Bucket.vBucket.ACTIVE, vb_id, vb_info["init"][node.ip][vb_id], vb_info["post_timeout"][node.ip][vb_id])) elif int(vb_id) \ in target_nodes_vbuckets[Bucket.vBucket.REPLICA]: if vb_id in vb_info["init"][node.ip].keys() \ and vb_info["init"][node.ip][vb_id] \ == vb_info["post_timeout"][node.ip][vb_id]: retry_validation = True self.log.warning( err_msg % (node.ip, Bucket.vBucket.REPLICA, vb_id, vb_info["init"][node.ip][vb_id], vb_info["post_timeout"][node.ip][vb_id])) return retry_validation shell_conn = dict() cbstat_obj = dict() error_sim = dict() target_nodes_vbuckets = dict() vb_info = dict() tasks = dict() doc_gen = dict() affected_vbs = list() target_nodes_vbuckets[Bucket.vBucket.ACTIVE] = list() target_nodes_vbuckets[Bucket.vBucket.REPLICA] = list() vb_info["init"] = dict() vb_info["post_timeout"] = dict() vb_info["afterCrud"] = dict() # Override crud_batch_size to minimum value for testing self.crud_batch_size = 5 target_nodes = self.getTargetNodes() for node in target_nodes: shell_conn[node.ip] = RemoteMachineShellConnection(node) cbstat_obj[node.ip] = Cbstats(node) target_nodes_vbuckets[Bucket.vBucket.ACTIVE] += \ cbstat_obj[node.ip].vbucket_list( self.bucket.name, vbucket_type=Bucket.vBucket.ACTIVE) target_nodes_vbuckets[Bucket.vBucket.REPLICA] += \ cbstat_obj[node.ip].vbucket_list( self.bucket.name, vbucket_type=Bucket.vBucket.REPLICA) vb_info["init"][node.ip] = cbstat_obj[node.ip].vbucket_seqno( self.bucket.name) error_sim[node.ip] = CouchbaseError(self.log, shell_conn[node.ip]) curr_time = int(time.time()) expected_timeout = curr_time + self.sdk_timeout target_vbs = target_nodes_vbuckets[Bucket.vBucket.ACTIVE] if self.nodes_init == 1: pass elif self.durability_level \ == Bucket.DurabilityLevel.PERSIST_TO_MAJORITY: target_vbs = target_nodes_vbuckets[Bucket.vBucket.REPLICA] # Create required doc_generators doc_gen["insert"] = sub_doc_generator(self.key, self.num_items / 2, self.crud_batch_size, target_vbucket=target_vbs, key_size=self.key_size) doc_gen["remove"] = sub_doc_generator_for_edit( self.key, 0, self.crud_batch_size, key_size=self.key_size, template_index=2, target_vbucket=target_vbs) doc_gen["read"] = sub_doc_generator_for_edit(self.key, 0, self.crud_batch_size, key_size=self.key_size, template_index=0, target_vbucket=target_vbs) doc_gen["upsert"] = sub_doc_generator_for_edit( self.key, int(self.num_items / 4), self.crud_batch_size, key_size=self.key_size, template_index=1, target_vbucket=target_vbs) for op_type in doc_gen.keys(): tasks[op_type] = self.task.async_load_gen_sub_docs( self.cluster, self.bucket, doc_gen[op_type], op_type, 0, path_create=True, batch_size=1, process_concurrency=8, replicate_to=self.replicate_to, persist_to=self.persist_to, durability=self.durability_level, timeout_secs=self.sdk_timeout, start_task=False) # Perform specified action for node in target_nodes: error_sim[node.ip].create(self.simulate_error, bucket_name=self.bucket.name) for op_type in doc_gen.keys(): self.task_manager.add_new_task(tasks[op_type]) # Wait for document_loader tasks to complete for op_type in doc_gen.keys(): self.task.jython_task_manager.get_task_result(tasks[op_type]) # Validate task failures if op_type == DocLoading.Bucket.DocOps.READ: # Validation for read task if len(tasks[op_type].fail.keys()) != 0: self.log_failure("Read failed for few docs: %s" % tasks[op_type].fail.keys()) else: # Validation of CRUDs - Update / Create / Delete for doc_id, crud_result in tasks[op_type].fail.items(): vb_num = self.bucket_util.get_vbucket_num_for_key( doc_id, self.cluster.vbuckets) if SDKException.DurabilityAmbiguousException \ not in str(crud_result["error"]): self.log_failure( "Invalid exception for doc %s, vb %s: %s" % (doc_id, vb_num, crud_result)) # Revert the specified error scenario for node in target_nodes: error_sim[node.ip].revert(self.simulate_error, bucket_name=self.bucket.name) # Check whether the timeout triggered properly if int(time.time()) < expected_timeout: self.log_failure("Timed-out before expected time") for op_type in doc_gen.keys(): if op_type == DocLoading.Bucket.DocOps.READ: continue while doc_gen[op_type].has_next(): doc_id, _ = doc_gen[op_type].next() affected_vbs.append( str( self.bucket_util.get_vbucket_num_for_key( doc_id, self.cluster.vbuckets))) affected_vbs = list(set(affected_vbs)) err_msg = "%s - mismatch in %s vb-%s seq_no: %s != %s" # Fetch latest stats and validate the seq_nos are not updated for node in target_nodes: retry_count = 0 max_retry = 3 while retry_count < max_retry: self.log.info("Trying to validate vbseq_no stats: %d" % (retry_count + 1)) retry_count += 1 retry_required = validate_vb_seqno_stats() if not retry_required: break self.sleep(5, "Sleep for vbseq_no stats to update") else: # This will be exited only if `break` condition is not met self.log_failure("validate_vb_seqno_stats verification failed") self.validate_test_failure() # If replicas+1 == total nodes, verify no mutation should have # succeeded with durability if self.nodes_init == self.num_replicas + 1: read_gen = doc_generator(self.key, 0, self.num_items) read_task = self.task.async_load_gen_docs( self.cluster, self.bucket, read_gen, DocLoading.Bucket.DocOps.READ, 0, batch_size=500, process_concurrency=1, timeout_secs=self.sdk_timeout) self.task_manager.get_task_result(read_task) failed_keys = TableView(self.log.error) failed_keys.set_headers(["Key", "Error"]) half_of_num_items = self.num_items / 2 for doc_key, doc_info in read_task.success.items(): key_index = int(doc_key.split("-")[1]) expected_mutated_val = 0 if key_index < half_of_num_items: expected_mutated_val = 1 mutated = json.loads(str(doc_info["value"]))["mutated"] if mutated != expected_mutated_val: failed_keys.add_row([doc_key, doc_info]) failed_keys.display("Affected mutations:") self.log.error(read_task.fail) # Doc error validation for op_type in doc_gen.keys(): task = tasks[op_type] retry_task = self.task.async_load_gen_sub_docs( self.cluster, self.bucket, doc_gen[op_type], op_type, 0, path_create=True, batch_size=1, process_concurrency=8, replicate_to=self.replicate_to, persist_to=self.persist_to, durability=self.durability_level, timeout_secs=self.sdk_timeout) self.task_manager.get_task_result(retry_task) retry_failures = set(retry_task.fail.keys()) initial_failures = set(task.fail.keys()) if len(list(retry_failures.difference(initial_failures))) != 0: self.log_failure("Docs failed during retry task for %s: %s" % (op_type, retry_task.fail)) # Verify doc count after expected CRUD failure self.bucket_util._wait_for_stats_all_buckets(self.cluster, self.cluster.buckets) self.bucket_util.verify_stats_all_buckets(self.cluster, self.num_items) # Fetch latest stats and validate the values are updated for node in target_nodes: vb_info["afterCrud"][node.ip] = \ cbstat_obj[node.ip].vbucket_seqno(self.bucket.name) if vb_info["init"][node.ip] == vb_info["afterCrud"][node.ip]: self.log_failure("vBucket seq_no stats not updated") # Disconnect the shell connection for node in target_nodes: shell_conn[node.ip].disconnect() self.validate_test_failure()
def test_timeout_with_crud_failures(self): """ Test to make sure timeout is handled in durability calls and no documents are loaded when durability cannot be met using error simulation in server node side This will validate failure in majority of nodes, where durability will surely fail for all CRUDs 1. Select a node from the cluster to simulate the specified error 2. Perform CRUD on the target bucket with given timeout 3. Using cbstats to verify no operations succeeds 4. Revert the error scenario from the cluster to resume durability 5. Validate all mutations are succeeded after reverting the error condition Note: self.sdk_timeout values is considered as 'seconds' """ # Local methods to validate vb_seqno def compare_vb_stat(stat_1, stat_2, vb, comparison="!="): keys_to_check = ["high_seqno", "high_completed_seqno"] result = True for key in keys_to_check: if vb in stat_1.keys(): if stat_1[vb]["uuid"] != stat_2[vb]["uuid"]: self.log_failure( "Mismatch in vb-%s UUID. %s != %s" % (vb, stat_1[vb]["uuid"], stat_2[vb]["uuid"])) if comparison == "!=": if stat_1[vb][key] != stat_2[vb][key]: result = False self.log.warning( "Mismatch in vb-%s stat %s. %s != %s" % (vb, key, stat_1[vb][key], stat_2[vb][key])) elif stat_1[vb][key] == stat_2[vb][key]: result = False self.log.warning( "Stat not updated for vb-%s stat %s. " "%s == %s" % (vb, key, stat_1[vb][key], stat_2[vb][key])) return result def validate_vb_seqno_stats(): """ :return retry_validation: Boolean denoting to retry validation """ retry_validation = False vb_info["post_timeout"][node.ip] = \ cbstat_obj[node.ip].vbucket_seqno(self.bucket.name) for tem_vb_num in range(self.cluster_util.vbuckets): tem_vb_num = str(tem_vb_num) if tem_vb_num not in affected_vbs: if compare_vb_stat(vb_info["init"][node.ip], vb_info["post_timeout"][node.ip], tem_vb_num) is False: self.log_failure("Unaffected vb-%s stat" % tem_vb_num) elif int(tem_vb_num) in target_nodes_vbuckets["active"]: if compare_vb_stat(vb_info["init"][node.ip], vb_info["post_timeout"][node.ip], tem_vb_num) is False: self.log.warning("%s - mismatch in %s vb-%s seq_no" % (node.ip, "active", tem_vb_num)) elif int(tem_vb_num) in target_nodes_vbuckets["replica"]: if compare_vb_stat(vb_info["init"][node.ip], vb_info["post_timeout"][node.ip], tem_vb_num, comparison="==") is False: retry_validation = True self.log.warning("%s - mismatch in %s vb-%s seq_no" % (node.ip, "replica", tem_vb_num)) return retry_validation shell_conn = dict() cbstat_obj = dict() error_sim = dict() target_nodes_vbuckets = dict() vb_info = dict() tasks = dict() doc_gen = dict() affected_vbs = list() target_nodes_vbuckets["active"] = [] target_nodes_vbuckets["replica"] = [] vb_info["init"] = dict() vb_info["post_timeout"] = dict() vb_info["afterCrud"] = dict() # Override crud_batch_size to minimum value for testing self.crud_batch_size = 5 self.key = "test_collections" self.sdk_timeout = 3 # Select target vbucket type to load_docs target_vb_type = "replica" if self.simulate_error == CouchbaseError.STOP_PERSISTENCE \ and self.durability_level \ == Bucket.DurabilityLevel.MAJORITY_AND_PERSIST_TO_ACTIVE: target_vb_type = "active" # Create required scope/collection for successful CRUD operation if self.scope_name != CbServer.default_scope: self.scope_name = self.bucket_util.get_random_name() self.collection_name = self.bucket_util.get_random_name() self.log.info("Creating scope::collection %s::%s" % (self.scope_name, self.collection_name)) self.create_scope_collection() # Load docs into created collection self.log.info("Loading data into created collection") load_gen = doc_generator(self.key, 0, self.num_items) task = self.task.async_load_gen_docs( self.cluster, self.bucket, load_gen, "create", 0, scope=self.scope_name, collection=self.collection_name, sdk_client_pool=self.sdk_client_pool, batch_size=200, process_concurrency=8, timeout_secs=60) self.task_manager.get_task_result(task) if self.subdoc_test: load_gen = sub_doc_generator(self.key, 0, self.num_items / 2) task = self.task.async_load_gen_sub_docs( self.cluster, self.bucket, load_gen, Bucket_Op.SubDocOps.INSERT, timeout_secs=self.sdk_timeout, compression=self.sdk_compression, path_create=True, batch_size=100, process_concurrency=8, durability=self.durability_level, scope=self.scope_name, collection=self.collection_name, sdk_client_pool=self.sdk_client_pool) self.task_manager.get_task_result(task) self.bucket.scopes[self.scope_name].collections[ self.collection_name].num_items = self.num_items target_nodes = DurabilityHelper.getTargetNodes(self.cluster, self.nodes_init, self.num_nodes_affected) for node in target_nodes: shell_conn[node.ip] = RemoteMachineShellConnection(node) cbstat_obj[node.ip] = Cbstats(shell_conn[node.ip]) target_nodes_vbuckets["active"] += \ cbstat_obj[node.ip].vbucket_list(self.bucket.name, vbucket_type="active") target_nodes_vbuckets["replica"] += \ cbstat_obj[node.ip].vbucket_list(self.bucket.name, vbucket_type="replica") vb_info["init"][node.ip] = cbstat_obj[node.ip].vbucket_seqno( self.bucket.name) error_sim[node.ip] = CouchbaseError(self.log, shell_conn[node.ip]) curr_time = int(time.time()) expected_timeout = curr_time + self.sdk_timeout if target_vb_type == "active": target_vbs = list( set(target_nodes_vbuckets[target_vb_type]).difference( set(target_nodes_vbuckets["replica"]))) else: target_vbs = list( set(target_nodes_vbuckets[target_vb_type]).difference( set(target_nodes_vbuckets["active"]))) # Create required doc_generators doc_gen["create"] = doc_generator(self.key, self.num_items, self.crud_batch_size, target_vbucket=target_vbs) doc_gen["delete"] = doc_generator(self.key, 0, self.crud_batch_size, target_vbucket=target_vbs) doc_gen["read"] = doc_generator(self.key, int(self.num_items / 3), self.crud_batch_size, target_vbucket=target_vbs) doc_gen["update"] = doc_generator(self.key, int(self.num_items / 2), self.crud_batch_size, target_vbucket=target_vbs) # Create required subdoc generators doc_gen["insert"] = sub_doc_generator(self.key, int(self.num_items / 2), self.crud_batch_size, target_vbucket=target_vbs) doc_gen["upsert"] = sub_doc_generator_for_edit( self.key, 0, self.crud_batch_size, template_index=1, target_vbucket=target_vbs) doc_gen["remove"] = sub_doc_generator(self.key, 0, self.crud_batch_size, target_vbucket=target_vbs) # Perform specified action for node in target_nodes: error_sim[node.ip].create(self.simulate_error, bucket_name=self.bucket.name) self.sleep(5, "Wait for error_simulation to take effect") ops_to_perform = [ Bucket_Op.DocOps.CREATE, Bucket_Op.DocOps.UPDATE, Bucket_Op.DocOps.READ, Bucket_Op.DocOps.DELETE ] if self.subdoc_test: ops_to_perform = [ Bucket_Op.SubDocOps.INSERT, Bucket_Op.SubDocOps.UPSERT, Bucket_Op.SubDocOps.REMOVE ] for op_type in ops_to_perform: self.log.info("Starting doc op %s" % op_type) if op_type in Bucket_Op.DOC_OPS: tasks[op_type] = self.task.async_load_gen_docs( self.cluster, self.bucket, doc_gen[op_type], op_type, 0, scope=self.scope_name, collection=self.collection_name, sdk_client_pool=self.sdk_client_pool, batch_size=1, process_concurrency=8, durability=self.durability_level, timeout_secs=self.sdk_timeout, suppress_error_table=True, print_ops_rate=False, skip_read_on_error=True) else: tasks[op_type] = self.task.async_load_gen_sub_docs( self.cluster, self.bucket, doc_gen[op_type], op_type, 0, scope=self.scope_name, collection=self.collection_name, sdk_client_pool=self.sdk_client_pool, path_create=True, batch_size=1, process_concurrency=8, durability=self.durability_level, timeout_secs=self.sdk_timeout, print_ops_rate=False) self.task.jython_task_manager.get_task_result(tasks[op_type]) # Validate task failures if op_type == Bucket_Op.DocOps.READ: # Validation for read task if len(tasks[op_type].fail.keys()) != 0: self.log_failure("Read failed for few docs: %s" % tasks[op_type].fail.keys()) else: # Validation of CRUDs - Update / Create / Delete for doc_id, crud_result in tasks[op_type].fail.items(): vb_num = self.bucket_util.get_vbucket_num_for_key( doc_id, self.cluster_util.vbuckets) if SDKException.DurabilityAmbiguousException \ not in str(crud_result["error"]): self.log_failure( "Invalid exception for doc %s, vb %s: %s" % (doc_id, vb_num, crud_result)) # Revert the specified error scenario for node in target_nodes: error_sim[node.ip].revert(self.simulate_error, bucket_name=self.bucket.name) # Check whether the timeout triggered properly if int(time.time()) < expected_timeout: self.log_failure("Timed-out before expected time") for op_type in ops_to_perform: if op_type == Bucket_Op.DocOps.READ: continue while doc_gen[op_type].has_next(): doc_id, _ = doc_gen[op_type].next() affected_vbs.append( str( self.bucket_util.get_vbucket_num_for_key( doc_id, self.cluster_util.vbuckets))) affected_vbs = list(set(affected_vbs)) # Fetch latest stats and validate the seq_nos are not updated for node in target_nodes: retry_count = 0 max_retry = 3 while retry_count < max_retry: self.log.info("Trying to validate vbseq_no stats: %d" % (retry_count + 1)) retry_count += 1 retry_required = validate_vb_seqno_stats() if not retry_required: break self.sleep(5, "Sleep for vbseq_no stats to update") else: # This will be exited only if `break` condition is not met self.log_failure("validate_vb_seqno_stats verification failed") self.validate_test_failure() # Get SDK Client from client_pool sdk_client = self.sdk_client_pool.get_client_for_bucket( self.bucket, self.scope_name, self.collection_name) # Doc error validation for op_type in ops_to_perform: task = tasks[op_type] if self.nodes_init == 1 \ and op_type != Bucket_Op.DocOps.READ \ and len(task.fail.keys()) != (doc_gen[op_type].end - doc_gen[op_type].start): self.log_failure( "Failed keys %d are less than expected %d" % (len(task.fail.keys()), (doc_gen[op_type].end - doc_gen[op_type].start))) # Create table objects for display table_view = TableView(self.log.error) ambiguous_table_view = TableView(self.log.info) table_view.set_headers(["Key", "vBucket", "Exception"]) ambiguous_table_view.set_headers(["Key", "vBucket"]) # Iterate failed keys for validation for doc_key, doc_info in task.fail.items(): vb_for_key = self.bucket_util.get_vbucket_num_for_key(doc_key) if SDKException.DurabilityAmbiguousException \ not in str(doc_info["error"]): table_view.add_row( [doc_key, vb_for_key, doc_info["error"]]) ambiguous_table_view.add_row([doc_key, str(vb_for_key)]) if op_type not in Bucket_Op.SUB_DOC_OPS: retry_success = \ self.durability_helper.retry_for_ambiguous_exception( sdk_client, op_type, doc_key, doc_info) if not retry_success: self.log_failure("%s failed in retry for %s" % (op_type, doc_key)) # Display the tables (if any errors) table_view.display("Unexpected exception during %s" % op_type) ambiguous_table_view.display("D_Ambiguous exception during %s" % op_type) # Release the acquired client self.sdk_client_pool.release_client(sdk_client) # Verify doc count after expected CRUD failure self.bucket_util._wait_for_stats_all_buckets() self.bucket_util.validate_docs_per_collections_all_buckets() # Fetch latest stats and validate the values are updated for node in target_nodes: vb_info["afterCrud"][node.ip] = \ cbstat_obj[node.ip].vbucket_seqno(self.bucket.name) if vb_info["init"][node.ip] == vb_info["afterCrud"][node.ip]: self.log_failure("vBucket seq_no stats not updated") # Disconnect the shell connection for node in target_nodes: shell_conn[node.ip].disconnect() self.validate_test_failure()
def test_maxttl_with_sync_writes(self): """ 1. Load few docs without TTL 2. Load few docs with TTL set in parallel to #1 3. Validate docs get expiry after the TTL time :return: """ def_bucket = self.cluster.buckets[0] self.maxttl = self.input.param("doc_ttl", self.maxttl) doc_ops_type = self.input.param("doc_ops_type", "sync;sync").split(";") # Create default doc_load options for TTL and non-TTL tasks non_ttl_task_property = dict() ttl_task_property = dict() # Create generators for TTL and non_TTL loading self.log.info("Creating doc_generators") ttl_gen_create = doc_generator(self.key, 0, self.num_items, doc_size=self.doc_size, doc_type=self.doc_type, target_vbucket=self.target_vbucket, vbuckets=self.cluster.vbuckets) non_ttl_gen_create = doc_generator(self.key, self.num_items, self.num_items * 2, doc_size=self.doc_size, doc_type=self.doc_type, target_vbucket=self.target_vbucket, vbuckets=self.cluster.vbuckets) # Set durability levels based on doc_ops_type non_ttl_task_property["op_type"] = "create" ttl_task_property["op_type"] = "create" if doc_ops_type[0] == "sync": non_ttl_task_property["replicate_to"] = 0 non_ttl_task_property["persist_to"] = 0 non_ttl_task_property["durability"] = self.durability_level else: non_ttl_task_property["replicate_to"] = self.replicate_to non_ttl_task_property["persist_to"] = self.persist_to non_ttl_task_property["durability"] = "None" if doc_ops_type[1] == "sync": ttl_task_property["replicate_to"] = 0 ttl_task_property["persist_to"] = 0 ttl_task_property["durability"] = self.durability_level else: ttl_task_property["replicate_to"] = self.replicate_to ttl_task_property["persist_to"] = self.persist_to ttl_task_property["durability"] = "None" self.load_docs_in_parallel(def_bucket, non_ttl_gen_create, ttl_gen_create, non_ttl_task_property, ttl_task_property) # Validate doc_count before expiry of docs self.bucket_util._wait_for_stats_all_buckets(self.cluster, self.cluster.buckets) self.bucket_util.verify_stats_all_buckets(self.cluster, self.num_items * 2) self.sleep(self.maxttl, "Sleep for maxTTL time") self.bucket_util._expiry_pager(self.cluster) self.sleep(25, "Waiting for items to be purged") # Read all expired docs to validate EONENT status ttl_task = self.task.async_load_gen_docs( self.cluster, def_bucket, ttl_gen_create, "read", self.maxttl, batch_size=10, process_concurrency=8, timeout_secs=self.sdk_timeout, compression=self.sdk_compression, sdk_client_pool=self.sdk_client_pool) self.task.jython_task_manager.get_task_result(ttl_task) # Max-TTL doc expiry validation self.log.info("Validating expiry of docs") if len(ttl_task.success.keys()) != 0: self.fail("Items present after MaxTTL time: %s" % ttl_task.success.keys()) invalid_exception_tbl = TableView(self.log.info) invalid_exception_tbl.set_headers(["Doc_Key", "CAS"]) for doc_key, result in ttl_task.fail.items(): if result["cas"] != 0 and result["error"] is not None: invalid_exception_tbl.add_row([doc_key, result["cas"]]) invalid_exception_tbl.display("Invalid exceptions for following keys") if len(invalid_exception_tbl.rows) != 0: self.fail("Seen invalid document exception") # Validate doc_count after doc_expiry self.bucket_util._wait_for_stats_all_buckets(self.cluster, self.cluster.buckets) self.bucket_util.verify_stats_all_buckets(self.cluster, self.num_items) # Document mutations after doc_expiry non_ttl_task_property["op_type"] = "update" self.load_docs_in_parallel(def_bucket, non_ttl_gen_create, ttl_gen_create, non_ttl_task_property, ttl_task_property) # Validate doc_count before expiry of docs self.bucket_util._wait_for_stats_all_buckets(self.cluster, self.cluster.buckets) self.bucket_util.verify_stats_all_buckets(self.cluster, self.num_items * 2)
def test_timeout_with_crud_failures(self): """ Test to make sure timeout is handled in durability calls and no documents are loaded when durability cannot be met using error simulation in server node side This will validate failure in majority of nodes, where durability will surely fail for all CRUDs 1. Select a node from the cluster to simulate the specified error 2. Perform CRUD on the target bucket with given timeout 3. Using cbstats to verify no operations succeeds 4. Revert the error scenario from the cluster to resume durability 5. Validate all mutations are succeeded after reverting the error condition Note: self.sdk_timeout values is considered as 'seconds' """ # Local method to validate vb_seqno def validate_vb_seqno_stats(): """ :return retry_validation: Boolean denoting to retry validation """ retry_validation = False vb_info["post_timeout"][node.ip] = \ cbstat_obj[node.ip].vbucket_seqno(self.bucket.name) for vb_num in range(self.vbuckets): vb_num = str(vb_num) if vb_num not in affected_vbs: if vb_info["init"][node.ip][vb_num] \ != vb_info["post_timeout"][node.ip][vb_num]: self.log_failure( "Unaffected vb-%s stat updated: %s != %s" % (vb_num, vb_info["init"][node.ip][vb_num], vb_info["post_timeout"][node.ip][vb_num])) elif int(vb_num) in target_nodes_vbuckets["active"]: if vb_info["init"][node.ip][vb_num] \ != vb_info["post_timeout"][node.ip][vb_num]: self.log_failure( err_msg % (node.ip, "active", vb_num, vb_info["init"][node.ip][vb_num], vb_info["post_timeout"][node.ip][vb_num])) elif int(vb_num) in target_nodes_vbuckets["replica"]: if vb_info["init"][node.ip][vb_num] \ == vb_info["post_timeout"][node.ip][vb_num]: retry_validation = True self.log.warning( err_msg % (node.ip, "replica", vb_num, vb_info["init"][node.ip][vb_num], vb_info["post_timeout"][node.ip][vb_num])) return retry_validation shell_conn = dict() cbstat_obj = dict() error_sim = dict() target_nodes_vbuckets = dict() vb_info = dict() tasks = dict() doc_gen = dict() affected_vbs = list() target_nodes_vbuckets["active"] = [] target_nodes_vbuckets["replica"] = [] vb_info["init"] = dict() vb_info["post_timeout"] = dict() vb_info["afterCrud"] = dict() # Override crud_batch_size to minimum value for testing self.crud_batch_size = 5 timeout_err_str = self.durability_helper.EXCEPTIONS["request_timeout"] ambiguous_err_str = self.durability_helper.EXCEPTIONS["ambiguous"] # Create required doc_generators doc_gen["insert"] = sub_doc_generator( self.key, self.num_items / 2, self.num_items / 2 + self.crud_batch_size) doc_gen["remove"] = sub_doc_generator_for_edit(self.key, 0, self.crud_batch_size, template_index=2) doc_gen["read"] = sub_doc_generator_for_edit(self.key, 0, self.crud_batch_size, template_index=0) doc_gen["upsert"] = sub_doc_generator_for_edit( self.key, int(self.num_items / 4), int(self.num_items / 4) + self.crud_batch_size, template_index=1) target_nodes = self.getTargetNodes() for node in target_nodes: shell_conn[node.ip] = RemoteMachineShellConnection(node) cbstat_obj[node.ip] = Cbstats(shell_conn[node.ip]) target_nodes_vbuckets["active"] += \ cbstat_obj[node.ip].vbucket_list(self.bucket.name, vbucket_type="active") target_nodes_vbuckets["replica"] += \ cbstat_obj[node.ip].vbucket_list(self.bucket.name, vbucket_type="replica") vb_info["init"][node.ip] = cbstat_obj[node.ip].vbucket_seqno( self.bucket.name) error_sim[node.ip] = CouchbaseError(self.log, shell_conn[node.ip]) curr_time = int(time.time()) expected_timeout = curr_time + self.sdk_timeout for op_type in doc_gen.keys(): tasks[op_type] = self.task.async_load_gen_sub_docs( self.cluster, self.bucket, doc_gen[op_type], op_type, 0, path_create=True, batch_size=1, process_concurrency=8, replicate_to=self.replicate_to, persist_to=self.persist_to, durability=self.durability_level, timeout_secs=self.sdk_timeout, start_task=False) # Perform specified action for node in target_nodes: error_sim[node.ip].create(self.simulate_error, bucket_name=self.bucket.name) for op_type in doc_gen.keys(): self.task_manager.add_new_task(tasks[op_type]) # Wait for document_loader tasks to complete for op_type in doc_gen.keys(): self.task.jython_task_manager.get_task_result(tasks[op_type]) # Validate task failures if op_type == "read": # Validation for read task for doc_id, crud_result in tasks[op_type].success.items(): vb_num = self.bucket_util.get_vbucket_num_for_key( doc_id, self.vbuckets) if vb_num in target_nodes_vbuckets["active"]: self.log_failure("Read succeeded for %s present in " "stopped active vbucket: %s" % (doc_id, vb_num)) self.durability_helper.validate_durability_exception( tasks[op_type].fail, self.durability_helper.EXCEPTIONS["request_timeout"]) else: # Validation of CRUDs - Update / Create / Delete if len(tasks[op_type].success.keys()) != 0: self.log_failure("Few keys succeeded for %s: %s" % (op_type, tasks[op_type].success.keys())) for doc_id, crud_result in tasks[op_type].fail.items(): vb_num = self.bucket_util.get_vbucket_num_for_key( doc_id, self.vbuckets) if vb_num in target_nodes_vbuckets["active"]: if timeout_err_str not in str(crud_result["error"]): self.log_failure( "Invalid exception for doc %s, vb %s: %s" % (doc_id, vb_num, crud_result)) else: if ambiguous_err_str not in str(crud_result["error"]): self.log_failure( "Invalid exception for doc %s, vb %s: %s" % (doc_id, vb_num, crud_result)) # Revert the specified error scenario for node in target_nodes: error_sim[node.ip].revert(self.simulate_error, bucket_name=self.bucket.name) # Check whether the timeout triggered properly if int(time.time()) < expected_timeout: self.log_failure("Timed-out before expected time") for op_type in doc_gen.keys(): if op_type == "read": continue while doc_gen[op_type].has_next(): doc_id, _ = doc_gen[op_type].next() affected_vbs.append( str( self.bucket_util.get_vbucket_num_for_key( doc_id, self.vbuckets))) affected_vbs = list(set(affected_vbs)) err_msg = "%s - mismatch in %s vb-%s seq_no: %s != %s" # Fetch latest stats and validate the seq_nos are not updated for node in target_nodes: retry_count = 0 max_retry = 3 while retry_count < max_retry: self.log.info("Trying to validate vbseq_no stats: %d" % (retry_count + 1)) retry_count += 1 retry_required = validate_vb_seqno_stats() if not retry_required: break self.sleep(5, "Sleep for vbseq_no stats to update") else: # This will be exited only if `break` condition is not met self.log_failure("validate_vb_seqno_stats verification failed") self.validate_test_failure() # If replicas+1 == total nodes, verify no mutation should have # succeeded with durability if self.nodes_init == self.num_replicas + 1: read_gen = doc_generator(self.key, 0, self.num_items) read_task = self.task.async_load_gen_docs( self.cluster, self.bucket, read_gen, "read", 0, batch_size=500, process_concurrency=1, timeout_secs=self.sdk_timeout) self.task_manager.get_task_result(read_task) failed_keys = TableView(self.log.error) failed_keys.set_headers(["Key", "Error"]) for doc_key, doc_info in read_task.success.items(): mutated = json.loads(str(doc_info["value"]))["mutated"] if mutated != 0: failed_keys.add_row([doc_key, doc_info]) failed_keys.display("Affected mutations:") self.log.error(read_task.fail) # SDK client for retrying AMBIGUOUS for unexpected keys sdk_client = SDKClient(RestConnection(self.cluster.master), self.bucket) # Doc error validation for op_type in doc_gen.keys(): task = tasks[op_type] if self.nodes_init == 1 \ and len(task.fail.keys()) != (doc_gen[op_type].end - doc_gen[op_type].start): self.log_failure( "Failed keys %d are less than expected %d" % (len(task.fail.keys()), (doc_gen[op_type].end - doc_gen[op_type].start))) # Create table objects for display table_view = TableView(self.log.error) ambiguous_table_view = TableView(self.log.error) table_view.set_headers(["Key", "Exception"]) ambiguous_table_view.set_headers(["Key", "vBucket"]) # Iterate failed keys for validation for doc_key, doc_info in task.fail.items(): vb_for_key = self.bucket_util.get_vbucket_num_for_key(doc_key) if vb_for_key in target_nodes_vbuckets["active"]: expected_exception = \ self.durability_helper.EXCEPTIONS["request_timeout"] elif vb_for_key in target_nodes_vbuckets["replica"]: expected_exception = \ self.durability_helper.EXCEPTIONS["ambiguous"] else: expected_exception = \ self.durability_helper.EXCEPTIONS["ambiguous"] ambiguous_table_view.add_row([doc_key, vb_for_key]) retry_success = \ self.durability_helper.retry_for_ambiguous_exception( sdk_client, op_type, doc_key, doc_info) if not retry_success: self.log_failure("%s failed in retry for %s" % (op_type, doc_key)) if expected_exception not in str(doc_info["error"]): table_view.add_row([doc_key, doc_info["error"]]) # Display the tables (if any errors) table_view.display("Unexpected exception during %s" % op_type) ambiguous_table_view.display("Ambiguous exception during %s" % op_type) # Close the SDK connection sdk_client.close() # Verify doc count after expected CRUD failure self.bucket_util._wait_for_stats_all_buckets() self.bucket_util.verify_stats_all_buckets(self.num_items) # Retry the same CRUDs after reverting the failure environment tasks = list() for op_type in doc_gen.keys(): tasks.append( self.task.async_load_gen_docs(self.cluster, self.bucket, doc_gen[op_type], op_type, 0, batch_size=10, process_concurrency=1, replicate_to=self.replicate_to, persist_to=self.persist_to, durability=self.durability_level, timeout_secs=self.sdk_timeout)) # Wait for document_loader tasks to complete for task in tasks: self.task.jython_task_manager.get_task_result(task) if len(task.fail.keys()) != 0: self.log_failure( "Failures with no error condition: {0}, {1}".format( task.fail, task.fail.keys())) # Verify initial doc load count self.bucket_util._wait_for_stats_all_buckets() self.bucket_util.verify_stats_all_buckets(self.num_items) # Fetch latest stats and validate the values are updated for node in target_nodes: vb_info["afterCrud"][node.ip] = \ cbstat_obj[node.ip].vbucket_seqno(self.bucket.name) if vb_info["init"][node.ip] == vb_info["afterCrud"][node.ip]: self.log_failure("vBucket seq_no stats not updated") # Disconnect the shell connection for node in target_nodes: shell_conn[node.ip].disconnect() self.validate_test_failure()
def ask(mess, responses=("OK", "Cancel"), default=0, cancel=-1, wrap_width=60, **kwds): # If height is specified as a keyword, the Dialog object will have this haight, and the inner massage will # be displayed in a scrolling widget # If 'responses_tooltips' it present in kwds, it must be dict with 'responses' as keys and the tooltips as values. # If 'tie_widget_to' is in kwds keys and the value is True, the global 'ask_tied_to' will be set up to the 'box'. # When called again with 'tie_widget_to', if 'ask_tied_to' is not None, the function returns a dummy answer. global ask_tied_to responses_tooltips = kwds.pop('responses_tooltips', {}) tie_widget_to = kwds.pop('tie_widget_to', None) # Return a dummy answer if tie_windget_to is True and the global 'ask_tied_to' is not None if tie_widget_to and ask_tied_to: return "_OK" colLbl = kwds.pop('colLabel', "") box = Dialog(**kwds) d = box.margin lb = wrapped_label(mess, wrap_width) buts = [] for caption in responses: but = Button(caption, action=lambda x=caption: box.dismiss(x)) if caption in responses_tooltips.keys(): but.tooltipText = responses_tooltips[caption] buts.append(but) brow = Row(buts, spacing=d) lb.width = max(lb.width, brow.width) height = kwds.get('height', None) if height and lb.height > height - ( 2 * brow.height) - ScrollPanel.column_margin - box.margin: lines = mess.split('\n') # ScrolledPanel refuses to render properly for now, so Tableview is used instead. w = TableView().font.size(_(colLbl))[0] lb = TableView( columns=[ TableColumn(colLbl, max(lb.width, w)), ], nrows=(height - (2 * brow.height) - box.margin - box.font.get_linesize()) / box.font.get_linesize(), height=height - (2 * brow.height) - (box.font.get_linesize() * 2) - box.margin) #, width=w) def num_rows(): return len(lines) lb.num_rows = num_rows lb.row_data = lambda x: (lines[x], ) lb.topleft = (d, d) lb.width = max(lb.width, brow.width) col = Column([lb, brow], spacing=d, align='r') col.topleft = (d, d) if default is not None: box.enter_response = responses[default] buts[default].is_default = True else: box.enter_response = None if cancel is not None: box.cancel_response = responses[cancel] else: box.cancel_response = None box.add(col) box.shrink_wrap() def dispatchKeyForAsk(name, evt): if name == "key_down" and box.root.getKey( evt) == "Return" and default is not None: box.dismiss(responses[default]) else: Dialog.dispatch_key(box, name, evt) box.dispatch_key = dispatchKeyForAsk if tie_widget_to: ask_tied_to = box ask_tied_tos.append(box) return box.present()
def test_basic_ops(self): """ Basic test for Sub-doc CRUD operations """ doc_op = self.input.param("op_type", None) def_bucket = self.bucket_util.buckets[0] supported_d_levels = self.bucket_util.get_supported_durability_levels() # Stat validation reference variables verification_dict = dict() verification_dict["ops_create"] = self.num_items verification_dict["ops_update"] = 0 verification_dict["ops_delete"] = 0 verification_dict["rollback_item_count"] = 0 verification_dict["sync_write_aborted_count"] = 0 verification_dict["sync_write_committed_count"] = 0 if self.durability_level in supported_d_levels: verification_dict["sync_write_committed_count"] += self.num_items # Initial validation failed = self.durability_helper.verify_vbucket_details_stats( def_bucket, self.cluster_util.get_kv_nodes(), vbuckets=self.cluster_util.vbuckets, expected_val=verification_dict) if failed: self.fail("Cbstat vbucket-details verification failed") if self.target_vbucket and type(self.target_vbucket) is not list: self.target_vbucket = [self.target_vbucket] self.log.info("Creating doc_generator..") # Load basic docs into bucket doc_create = sub_doc_generator(self.key, 0, self.num_items, key_size=self.key_size, doc_size=self.sub_doc_size, target_vbucket=self.target_vbucket, vbuckets=self.cluster_util.vbuckets) self.log.info("Loading {0} docs into the bucket: {1}".format( self.num_items, def_bucket)) task = self.task.async_load_gen_sub_docs( self.cluster, def_bucket, doc_create, DocLoading.Bucket.SubDocOps.INSERT, self.maxttl, path_create=True, batch_size=10, process_concurrency=8, replicate_to=self.replicate_to, persist_to=self.persist_to, durability=self.durability_level, timeout_secs=self.sdk_timeout) self.task.jython_task_manager.get_task_result(task) self.log.info("Wait for ep_all_items_remaining to become '0'") self.bucket_util._wait_for_stats_all_buckets() # Update verification_dict and validate verification_dict["ops_update"] += self.num_items if self.durability_level in supported_d_levels: verification_dict["sync_write_committed_count"] += self.num_items failed = self.durability_helper.verify_vbucket_details_stats( def_bucket, self.cluster_util.get_kv_nodes(), vbuckets=self.cluster_util.vbuckets, expected_val=verification_dict) if failed: self.fail("Cbstat vbucket-details verification failed") # Verify initial doc load count self.log.info("Validating doc_count in buckets") self.bucket_util.verify_stats_all_buckets(self.num_items) self.log.info("Creating doc_generator for doc_op") num_item_start_for_crud = int(self.num_items / 2) template_index = 0 if doc_op == DocLoading.Bucket.SubDocOps.REMOVE: template_index = 2 sub_doc_gen = sub_doc_generator_for_edit(self.key, start=0, end=num_item_start_for_crud, key_size=self.key_size, template_index=template_index) if doc_op == DocLoading.Bucket.SubDocOps.UPSERT: self.log.info("Performing 'upsert' mutation over the sub-docs") task = self.task.async_load_gen_sub_docs( self.cluster, def_bucket, sub_doc_gen, doc_op, self.maxttl, path_create=True, batch_size=10, process_concurrency=8, replicate_to=self.replicate_to, persist_to=self.persist_to, durability=self.durability_level, timeout_secs=self.sdk_timeout) self.task.jython_task_manager.get_task_result(task) verification_dict["ops_update"] += \ (sub_doc_gen.end - sub_doc_gen.start + len(task.fail.keys())) if self.durability_level in supported_d_levels: verification_dict["sync_write_committed_count"] += \ num_item_start_for_crud # Edit doc_gen template to read the mutated value as well sub_doc_gen.template = \ sub_doc_gen.template.replace(" }}", ", \"mutated\": \"\" }}") # Read all the values to validate update operation task = self.task.async_load_gen_sub_docs( self.cluster, def_bucket, sub_doc_gen, "read", 0, batch_size=100, process_concurrency=8, timeout_secs=self.sdk_timeout) self.task.jython_task_manager.get_task_result(task) op_failed_tbl = TableView(self.log.error) op_failed_tbl.set_headers(["Update failed key", "Value"]) for key, value in task.success.items(): doc_value = value["value"] failed_row = [key, doc_value] if doc_value[0] != 2: op_failed_tbl.add_row(failed_row) elif doc_value[1] != "LastNameUpdate": op_failed_tbl.add_row(failed_row) elif doc_value[2] != "TypeChange": op_failed_tbl.add_row(failed_row) elif doc_value[3] != "CityUpdate": op_failed_tbl.add_row(failed_row) elif json.loads(str(doc_value[4])) != ["get", "up"]: op_failed_tbl.add_row(failed_row) op_failed_tbl.display("Update failed for keys:") if len(op_failed_tbl.rows) != 0: self.fail("Update failed for few keys") elif doc_op == DocLoading.Bucket.SubDocOps.REMOVE: self.log.info("Performing 'remove' mutation over the sub-docs") task = self.task.async_load_gen_sub_docs( self.cluster, def_bucket, sub_doc_gen, doc_op, 0, batch_size=10, process_concurrency=8, replicate_to=self.replicate_to, persist_to=self.persist_to, durability=self.durability_level, timeout_secs=self.sdk_timeout) self.task.jython_task_manager.get_task_result(task) verification_dict["ops_update"] += \ (sub_doc_gen.end - sub_doc_gen.start + len(task.fail.keys())) if self.durability_level in supported_d_levels: verification_dict["sync_write_committed_count"] += \ num_item_start_for_crud # Edit doc_gen template to read the mutated value as well sub_doc_gen.template = sub_doc_gen.template \ .replace(" }}", ", \"mutated\": \"\" }}") # Read all the values to validate update operation task = self.task.async_load_gen_sub_docs( self.cluster, def_bucket, sub_doc_gen, "read", 0, batch_size=100, process_concurrency=8, timeout_secs=self.sdk_timeout) self.task.jython_task_manager.get_task_result(task) op_failed_tbl = TableView(self.log.error) op_failed_tbl.set_headers(["Delete failed key", "Value"]) for key, value in task.success.items(): doc_value = value["value"] failed_row = [key, doc_value] if doc_value[0] != 2: op_failed_tbl.add_row(failed_row) for index in range(1, len(doc_value)): if doc_value[index] != "PATH_NOT_FOUND": op_failed_tbl.add_row(failed_row) for key, value in task.fail.items(): op_failed_tbl.add_row([key, value["value"]]) op_failed_tbl.display("Delete failed for keys:") if len(op_failed_tbl.rows) != 0: self.fail("Delete failed for few keys") else: self.log.warning("Unsupported doc_operation") self.log.info("Wait for ep_all_items_remaining to become '0'") self.bucket_util._wait_for_stats_all_buckets() # Validate verification_dict and validate failed = self.durability_helper.verify_vbucket_details_stats( def_bucket, self.cluster_util.get_kv_nodes(), vbuckets=self.cluster_util.vbuckets, expected_val=verification_dict) if failed: self.fail("Cbstat vbucket-details verification failed") self.log.info("Validating doc_count") self.bucket_util.verify_stats_all_buckets(self.num_items)
def test_basic_ops(self): """ Basic test for Sub-doc CRUD operations A test in which `self.num_items` documents are created. Half of the documents are updated or deleted depending on the supplied `op_type`. """ doc_op = self.input.param("op_type", None) def_bucket = self.cluster.buckets[0] # Stat validation reference variables verification_dict = dict() verification_dict["ops_create"] = self.num_items verification_dict["ops_update"] = 0 verification_dict["ops_delete"] = 0 verification_dict["rollback_item_count"] = 0 verification_dict["sync_write_aborted_count"] = 0 verification_dict["sync_write_committed_count"] = 0 if self.is_sync_write_enabled: verification_dict["sync_write_committed_count"] += self.num_items # Initial validation failed = self.durability_helper.verify_vbucket_details_stats( def_bucket, self.cluster_util.get_kv_nodes(self.cluster), vbuckets=self.cluster.vbuckets, expected_val=verification_dict) if failed: self.fail("Cbstat vbucket-details verification failed") if self.target_vbucket and type(self.target_vbucket) is not list: self.target_vbucket = [self.target_vbucket] self.log.info("Creating doc_generator..") # Insert `self.num_items` documents doc_create = sub_doc_generator( self.key, 0, self.num_items, key_size=self.key_size, doc_size=self.sub_doc_size, target_vbucket=self.target_vbucket, vbuckets=self.cluster.vbuckets) self.log.info("Loading {0} docs into the bucket: {1}" .format(self.num_items, def_bucket)) task = self.task.async_load_gen_sub_docs( self.cluster, def_bucket, doc_create, DocLoading.Bucket.SubDocOps.INSERT, self.maxttl, path_create=True, batch_size=10, process_concurrency=8, replicate_to=self.replicate_to, persist_to=self.persist_to, durability=self.durability_level, timeout_secs=self.sdk_timeout) self.task.jython_task_manager.get_task_result(task) self.log.info("Wait for ep_all_items_remaining to become '0'") self.bucket_util._wait_for_stats_all_buckets(self.cluster, self.cluster.buckets) # The documents that could not be inserted insert_failures = len(task.fail.keys()) # Update verification_dict and validate verification_dict["ops_update"] += self.num_items - insert_failures if self.is_sync_write_enabled: verification_dict["sync_write_committed_count"] += self.num_items - insert_failures verification_dict["sync_write_aborted_count"] += insert_failures failed = self.durability_helper.verify_vbucket_details_stats( def_bucket, self.cluster_util.get_kv_nodes(self.cluster), vbuckets=self.cluster.vbuckets, expected_val=verification_dict) if failed: self.fail("Cbstat vbucket-details verification failed") # Verify initial doc load count self.log.info("Validating doc_count in buckets") self.bucket_util.verify_stats_all_buckets(self.cluster, self.num_items) self.log.info("Creating doc_generator for doc_op") num_item_start_for_crud = int(self.num_items / 2) template_index = 0 if doc_op == DocLoading.Bucket.SubDocOps.REMOVE: template_index = 2 sub_doc_gen = sub_doc_generator_for_edit( self.key, start=0, end=num_item_start_for_crud, key_size=self.key_size, template_index=template_index) if doc_op == DocLoading.Bucket.SubDocOps.UPSERT: self.log.info("Performing 'upsert' mutation over the sub-docs") task = self.task.async_load_gen_sub_docs( self.cluster, def_bucket, sub_doc_gen, doc_op, self.maxttl, path_create=True, batch_size=10, process_concurrency=8, replicate_to=self.replicate_to, persist_to=self.persist_to, durability=self.durability_level, timeout_secs=self.sdk_timeout) self.task.jython_task_manager.get_task_result(task) # The documents keys for which the update failed update_failures = len(task.fail.keys()) verification_dict["ops_update"] += \ num_item_start_for_crud - update_failures if self.is_sync_write_enabled: verification_dict["sync_write_committed_count"] += \ num_item_start_for_crud - update_failures # Edit doc_gen template to read the mutated value as well sub_doc_gen.template = \ sub_doc_gen.template.replace(" }}", ", \"mutated\": \"\" }}") # Read all the values to validate update operation task = self.task.async_load_gen_sub_docs( self.cluster, def_bucket, sub_doc_gen, "read", 0, batch_size=100, process_concurrency=8, timeout_secs=self.sdk_timeout) self.task.jython_task_manager.get_task_result(task) # A set of expected values following a read operation expected_values = {'StateUpdate', 2, 'LastNameUpdate', 'TypeChange', 'CityUpdate', 'FirstNameUpdate'} op_failed_tbl = TableView(self.log.error) op_failed_tbl.set_headers(["Update failed key", "Value"]) # If the values of attributes does not match the # expected value, append op to list of failed ops. for key, value in task.success.items(): if expected_values != set(value["value"]): op_failed_tbl.add_row([key, value["value"]]) op_failed_tbl.display("Update failed for keys:") # Expect the non-updated values to match the update failures self.assertEqual(len(op_failed_tbl.rows), update_failures, "") elif doc_op == DocLoading.Bucket.SubDocOps.REMOVE: self.log.info("Performing 'remove' mutation over the sub-docs") task = self.task.async_load_gen_sub_docs( self.cluster, def_bucket, sub_doc_gen, doc_op, 0, batch_size=10, process_concurrency=8, replicate_to=self.replicate_to, persist_to=self.persist_to, durability=self.durability_level, timeout_secs=self.sdk_timeout) self.task.jython_task_manager.get_task_result(task) # The number of documents that could not be removed remove_failures = len(task.fail.keys()) verification_dict["ops_update"] += \ num_item_start_for_crud - remove_failures if self.is_sync_write_enabled: verification_dict["sync_write_committed_count"] += \ num_item_start_for_crud - remove_failures # Edit doc_gen template to read the mutated value as well sub_doc_gen.template = sub_doc_gen.template \ .replace(" }}", ", \"mutated\": \"\" }}") # Read all the values to validate update operation task = self.task.async_load_gen_sub_docs( self.cluster, def_bucket, sub_doc_gen, "read", 0, batch_size=100, process_concurrency=8, timeout_secs=self.sdk_timeout) self.task.jython_task_manager.get_task_result(task) op_failed_tbl = TableView(self.log.error) op_failed_tbl.set_headers(["Delete failed key", "Value"]) # Collect read operations that failed for key, value in task.fail.items(): op_failed_tbl.add_row([key, value["error"]]) op_failed_tbl.display("Delete succeeded for keys:") # Expect the reads to have failed indicating the sub-documents are # no longer accessible. self.assertEqual(len(op_failed_tbl.rows), num_item_start_for_crud, "Delete failed for few keys") else: self.log.warning("Unsupported doc_operation") self.log.info("Wait for ep_all_items_remaining to become '0'") self.bucket_util._wait_for_stats_all_buckets(self.cluster, self.cluster.buckets) # Validate verification_dict and validate failed = self.durability_helper.verify_vbucket_details_stats( def_bucket, self.cluster_util.get_kv_nodes(self.cluster), vbuckets=self.cluster.vbuckets, expected_val=verification_dict) if failed: self.fail("Cbstat vbucket-details verification failed") self.log.info("Validating doc_count") self.bucket_util.verify_stats_all_buckets(self.cluster, self.num_items)
def setUp(self): super(ConcurrentFailoverTests, self).setUp() self.log_setup_status(self.__class__.__name__, "started", self.setUp.__name__) ####################################################################### # List of params to be used for failover # self.timeout from AutoFailoverBaseTest # self.max_count from AutoFailoverBaseTest # To track the triggered failover events self.fo_events = 0 # failover_order to be used for failover_order_tests # Format: # kv:kv-kv:index_query # * Iteration marked by '-' # * Nodes marked by ':' # * Service within a node denoted by '_' (underscore) # In the above case, # - Loop #0 :: 2 KV nodes will be failed # - Loop #1 :: 1 KV + 1 node running n1ql+index will be failed self.failover_order = \ self.input.param("failover_order", "kv").split("-") self.failover_method = \ self.input.param("failover_method", CouchbaseError.STOP_MEMCACHED) # Failover type determines the order of FO (Auto/Graceful/Hard). # Length of this should match the len(self.failover_order) # Example -> auto-graceful-auto # This expects first set of nodes from failover_order to undergo # AUTO FO followed by GRACEFUL FO of nodes through API and then # followed by AUTO FO of 3rd set of nodes as defined by failover_order self.failover_type = \ self.input.param("failover_type", CbServer.Failover.Type.AUTO).split("-") # End of params to be used for failover ####################################################################### self.load_during_fo = self.input.param("load_during_fo", False) self.log.info("Updating Auto-failover settings") self.rest.update_autofailover_settings(enabled=True, timeout=self.timeout, maxCount=self.max_count) # Find the bucket with least replica to check the Auto-FO possibility self.min_bucket_replica = Bucket.ReplicaNum.THREE for bucket in self.cluster.buckets: if bucket.replicaNumber < self.min_bucket_replica: self.min_bucket_replica = bucket.replicaNumber # Hold the dict of {node_obj_to_fail: failover_type, ...} self.nodes_to_fail = None # To display test execution status self.test_status_tbl = TableView(self.log.critical) self.auto_fo_settings_tbl = TableView(self.log.critical) self.test_status_tbl.set_headers( ["Node", "Services", "Node status", "Failover type"]) self.auto_fo_settings_tbl.set_headers([ "Enabled", "Auto FO count", "Max Events configured", "Auto FO timeout", "Disk Auto FO", "Disk Auto FO timeout" ]) self.validate_failover_settings(True, self.timeout, 0, self.max_count) # Init sdk_client_pool if not initialized before if self.sdk_client_pool is None: self.init_sdk_pool_object() CollectionBase.create_sdk_clients( self.task_manager.number_of_threads, self.cluster.master, self.cluster.buckets, self.sdk_client_pool, self.sdk_compression) # Perform initial collection load self.__load_initial_collection_data() self.log_setup_status(self.__class__.__name__, "complete", self.setUp.__name__)
def test_doc_size(self): def check_durability_failures(): self.log.error(task.sdk_acked_curd_failed.keys()) self.log.error(task.sdk_exception_crud_succeed.keys()) self.assertTrue( len(task.sdk_acked_curd_failed) == 0, "Durability failed for docs: %s" % task.sdk_acked_curd_failed.keys()) self.assertTrue( len(task.sdk_exception_crud_succeed) == 0, "Durability failed for docs: %s" % task.sdk_acked_curd_failed.keys()) """ Basic tests for document CRUD operations using JSON docs """ doc_op = self.input.param("doc_op", None) def_bucket = self.bucket_util.buckets[0] ignore_exceptions = list() retry_exceptions = list() # Stat validation reference variables verification_dict = dict() ref_val = dict() ref_val["ops_create"] = 0 ref_val["ops_update"] = 0 ref_val["ops_delete"] = 0 ref_val["rollback_item_count"] = 0 ref_val["sync_write_aborted_count"] = 0 ref_val["sync_write_committed_count"] = 0 one_less_node = self.nodes_init == self.num_replicas if self.durability_level: pass #ignore_exceptions.append( # "com.couchbase.client.core.error.RequestTimeoutException") if self.target_vbucket and type(self.target_vbucket) is not list: self.target_vbucket = [self.target_vbucket] self.log.info("Creating doc_generator..") # Load basic docs into bucket doc_create = doc_generator(self.key, 0, self.num_items, doc_size=self.doc_size, doc_type=self.doc_type, target_vbucket=self.target_vbucket, vbuckets=self.vbuckets) self.log.info("Loading {0} docs into the bucket: {1}".format( self.num_items, def_bucket)) task = self.task.async_load_gen_docs( self.cluster, def_bucket, doc_create, "create", 0, batch_size=self.batch_size, process_concurrency=self.process_concurrency, replicate_to=self.replicate_to, persist_to=self.persist_to, durability=self.durability_level, timeout_secs=self.sdk_timeout, ryow=self.ryow, check_persistence=self.check_persistence) self.task.jython_task_manager.get_task_result(task) if self.ryow: check_durability_failures() # Retry doc_exception code self.log.info("Validating failed doc's (if any) exceptions") doc_op_info_dict = dict() doc_op_info_dict[task] = self.bucket_util.get_doc_op_info_dict( def_bucket, "create", exp=0, replicate_to=self.replicate_to, persist_to=self.persist_to, durability=self.durability_level, timeout=self.sdk_timeout, time_unit="seconds", ignore_exceptions=ignore_exceptions, retry_exceptions=retry_exceptions) self.bucket_util.verify_doc_op_task_exceptions(doc_op_info_dict, self.cluster) if len(doc_op_info_dict[task]["unwanted"]["fail"].keys()) != 0: self.fail("Failures in retry doc CRUDs: {0}".format( doc_op_info_dict[task]["unwanted"]["fail"])) self.log.info("Wait for ep_all_items_remaining to become '0'") self.bucket_util._wait_for_stats_all_buckets() # Update ref_val ref_val["ops_create"] = self.num_items + len(task.fail.keys()) ref_val["sync_write_committed_count"] = self.num_items # Validate vbucket stats verification_dict["ops_create"] = ref_val["ops_create"] verification_dict["rollback_item_count"] = \ ref_val["rollback_item_count"] if self.durability_level: verification_dict["sync_write_aborted_count"] = \ ref_val["sync_write_aborted_count"] verification_dict["sync_write_committed_count"] = \ ref_val["sync_write_committed_count"] failed = self.durability_helper.verify_vbucket_details_stats( def_bucket, self.cluster_util.get_kv_nodes(), vbuckets=self.vbuckets, expected_val=verification_dict, one_less_node=one_less_node) if failed: self.fail("Cbstat vbucket-details verification failed") # Verify initial doc load count self.log.info("Validating doc_count in buckets") self.bucket_util.verify_stats_all_buckets(self.num_items) self.log.info("Creating doc_generator for doc_op") num_item_start_for_crud = int(self.num_items / 2) doc_update = doc_generator(self.key, 0, num_item_start_for_crud, doc_size=self.doc_size, doc_type=self.doc_type, target_vbucket=self.target_vbucket, vbuckets=self.vbuckets) expected_num_items = self.num_items num_of_mutations = 1 if doc_op == "update": self.log.info("Performing 'update' mutation over the docs") task = self.task.async_load_gen_docs( self.cluster, def_bucket, doc_update, "update", 0, batch_size=self.batch_size, process_concurrency=self.process_concurrency, replicate_to=self.replicate_to, persist_to=self.persist_to, durability=self.durability_level, timeout_secs=self.sdk_timeout, ryow=self.ryow, check_persistence=self.check_persistence) self.task.jython_task_manager.get_task_result(task) ref_val["ops_update"] = (doc_update.end - doc_update.start + len(task.fail.keys())) if self.durability_level: ref_val["sync_write_committed_count"] += \ (doc_update.end - doc_update.start) if self.ryow: check_durability_failures() # Read all the values to validate update operation task = self.task.async_load_gen_docs( self.cluster, def_bucket, doc_update, "read", 0, batch_size=self.batch_size, process_concurrency=self.process_concurrency, timeout_secs=self.sdk_timeout) self.task.jython_task_manager.get_task_result(task) op_failed_tbl = TableView(self.log.error) op_failed_tbl.set_headers(["Update failed key", "CAS", "Value"]) for key, value in task.success.items(): if json.loads(str(value["value"]))["mutated"] != 1: op_failed_tbl.add_row([key, value["cas"], value["value"]]) op_failed_tbl.display("Update failed for keys:") if len(op_failed_tbl.rows) != 0: self.fail("Update failed for few keys") elif doc_op == "delete": self.log.info("Performing 'delete' mutation over the docs") task = self.task.async_load_gen_docs( self.cluster, def_bucket, doc_update, "delete", 0, batch_size=self.batch_size, process_concurrency=self.process_concurrency, replicate_to=self.replicate_to, persist_to=self.persist_to, durability=self.durability_level, timeout_secs=self.sdk_timeout, ryow=self.ryow, check_persistence=self.check_persistence) self.task.jython_task_manager.get_task_result(task) expected_num_items = self.num_items \ - (self.num_items - num_item_start_for_crud) ref_val["ops_delete"] = (doc_update.end - doc_update.start + len(task.fail.keys())) if self.durability_level: ref_val["sync_write_committed_count"] += \ (doc_update.end - doc_update.start) if self.ryow: check_durability_failures() # Read all the values to validate update operation task = self.task.async_load_gen_docs(self.cluster, def_bucket, doc_update, "read", 0, batch_size=10, process_concurrency=8, timeout_secs=self.sdk_timeout) self.task.jython_task_manager.get_task_result(task) op_failed_tbl = TableView(self.log.error) op_failed_tbl.set_headers(["Delete failed key", "CAS", "Value"]) for key, value in task.success.items(): op_failed_tbl.add_row([key, value["cas"], value["value"]]) op_failed_tbl.display("Delete failed for keys:") if len(op_failed_tbl.rows) != 0: self.fail("Delete failed for few keys") else: self.log.warning("Unsupported doc_operation") self.log.info("Wait for ep_all_items_remaining to become '0'") self.bucket_util._wait_for_stats_all_buckets() # Validate vbucket stats verification_dict["ops_create"] = ref_val["ops_create"] verification_dict["ops_update"] = ref_val["ops_update"] verification_dict["ops_delete"] = ref_val["ops_delete"] verification_dict["rollback_item_count"] = \ ref_val["rollback_item_count"] if self.durability_level: verification_dict["sync_write_aborted_count"] = \ ref_val["sync_write_aborted_count"] verification_dict["sync_write_committed_count"] = \ ref_val["sync_write_committed_count"] failed = self.durability_helper.verify_vbucket_details_stats( def_bucket, self.cluster_util.get_kv_nodes(), vbuckets=self.vbuckets, expected_val=verification_dict, one_less_node=one_less_node) if failed: self.fail("Cbstat vbucket-details verification failed") self.log.info("Validating doc_count") self.bucket_util.verify_stats_all_buckets(expected_num_items)
"Observer Design Pattern Concept" from data_model import DataModel from data_controller import DataController from pie_graph_view import PieGraphView from bar_graph_view import BarGraphView from table_view import TableView # A local data view that the hypothetical external controller updates DATA_MODEL = DataModel() # Add some visualisation that use the dataview PIE_GRAPH_VIEW = PieGraphView(DATA_MODEL) BAR_GRAPH_VIEW = BarGraphView(DATA_MODEL) TABLE_VIEW = TableView(DATA_MODEL) # A hypothetical data controller running in a different process DATA_CONTROLLER = DataController() # The hypothetical external data controller updates some data DATA_CONTROLLER.notify([1, 2, 3]) # Client now removes a local BAR_GRAPH BAR_GRAPH_VIEW.delete() # The hypothetical external data controller updates the data again DATA_CONTROLLER.notify([4, 5, 6])