def setUpClass(cls): add_tier() cls._handles = list() cls._drop_requests = list() global table_names table_names = list() num_tables = 3 # # In pod env create 1 handle, otherwise create 2 handles for additional # testing # cls._num_handles = 1 if is_pod() else 2 for handle in range(cls._num_handles): add_tenant(tenant_id + str(handle)) table_names.append(list()) cls._drop_requests.append(list()) cls._handles.append(get_handle(tenant_id + str(handle))) for table in range(handle + num_tables): table_names[handle].append(table_name + str(table)) for table in range(handle + num_tables): # # Add a sleep for a pod to let things happen # if is_pod(): sleep(60) drop_statement = ('DROP TABLE IF EXISTS ' + table_names[handle][table]) drop_request = TableRequest().set_statement(drop_statement) cls._drop_requests[handle].append(drop_request) cls._result = cls._handles[handle].table_request(drop_request) cls._result.wait_for_state(cls._handles[handle], table_names[handle][table], State.DROPPED, wait_timeout, 1000) create_statement = ('CREATE TABLE ' + table_names[handle][table] + '(\ fld_id INTEGER, fld_long LONG, fld_float FLOAT, fld_double DOUBLE, \ fld_bool BOOLEAN, fld_str STRING, fld_bin BINARY, fld_time TIMESTAMP(2), \ fld_num NUMBER, fld_json JSON, fld_arr ARRAY(STRING), fld_map MAP(STRING), \ fld_rec RECORD(fld_id LONG, fld_bool BOOLEAN, fld_str STRING), \ PRIMARY KEY(fld_id)) USING TTL 16 HOURS') limits = TableLimits(5000, 5000, 50) create_request = TableRequest().set_statement( create_statement).set_table_limits(limits) cls._result = cls._handles[handle].table_request( create_request) cls._result.wait_for_state(cls._handles[handle], table_names[handle][table], State.ACTIVE, wait_timeout, 1000)
def table_request(cls, request, test_handle=None): test_handle = cls.handle if test_handle is None else test_handle # # Optionally delay to handle the 4 DDL ops/minute limit # in the real service # if is_pod(): sleep(30) test_handle.do_table_request(request, wait_timeout, 1000)
def _do_table_request(self, request): # # Optionally delay to handle the 4 DDL ops/minute limit # in the real service # if is_pod(): sleep(30) result = self.handle.table_request(request) result.wait_for_completion(self.handle, wait_timeout, 1000)
def table_request(cls, request, state): # # Optionally delay to handle the 4 DDL ops/minute limit # in the real service # if is_pod(): sleep(20) result = cls._handle.table_request(request) result.wait_for_state_with_res(cls._handle, state, wait_timeout, 1000)
def testGetTableNormal(self): self.get_table_request.set_table_name(table_name) result = self.handle.get_table(self.get_table_request) if is_minicloud() or is_pod(): self.check_table_result(result, State.ACTIVE, table_limits) else: self.check_table_result(result, State.ACTIVE, table_limits, has_operation_id=False)
def testGetTableWithOperationId(self): drop_request = TableRequest().set_statement('DROP TABLE IF EXISTS ' + table_name) table_result = self.handle.table_request(drop_request) self.get_table_request.set_table_name(table_name).set_operation_id( table_result.get_operation_id()) result = self.handle.get_table(self.get_table_request) if is_minicloud() or is_pod(): self.check_table_result(result, [State.DROPPING, State.DROPPED], table_limits) else: self.check_table_result(result, [State.DROPPING, State.DROPPED]) table_result.wait_for_completion(self.handle, wait_timeout, 1000)
def setUpClass(cls): add_tier() cls.handles = list() global table_names table_names = list() num_tables = 3 # # In pod env create 1 handle, otherwise create 2 handles for additional # testing # num_handles = 1 if is_prod_pod() or is_onprem() else 2 for handle in range(num_handles): tenant = tenant_id + ('' if handle == 0 else str(handle)) add_tenant(tenant) table_names.append(list()) cls.handles.append(get_handle(tenant)) for table in range(handle + num_tables): tb_name = table_name + str(table) table_names[handle].append(tb_name) # # Add a sleep for a pod to let things happen # if is_pod(): sleep(60) drop_request = TableRequest().set_statement( 'DROP TABLE IF EXISTS ' + tb_name) cls.table_request(drop_request, cls.handles[handle]) create_statement = ('CREATE TABLE ' + tb_name + '(fld_id INTEGER, \ fld_long LONG, fld_float FLOAT, fld_double DOUBLE, fld_bool BOOLEAN, \ fld_str STRING, fld_bin BINARY, fld_time TIMESTAMP(2), fld_num NUMBER, \ fld_json JSON, fld_arr ARRAY(STRING), fld_map MAP(STRING), \ fld_rec RECORD(fld_id LONG, fld_bool BOOLEAN, fld_str STRING), \ PRIMARY KEY(fld_id)) USING TTL 16 HOURS') limits = TableLimits(10, 10, 1) create_request = TableRequest().set_statement( create_statement).set_table_limits(limits) cls.table_request(create_request, cls.handles[handle])
def table_request(cls, request, test_handle=None): test_handle = cls.handle if test_handle is None else test_handle # # Optionally delay to handle the 4 DDL ops/minute limit # in the real service # if is_pod(): sleep(20) # TODO: For minicloud, the SC module doesn't return operation id for # now. In TableResult.wait_for_completion, it check if the operation id # is none, if none, raise IllegalArgumentException, at the moment we # should ignore this exception in minicloud testing. This affects drop # table as well as create/drop index. When the SC is changed to return # the operation id, the test need to be changed. if is_minicloud(): result = test_handle.table_request(request) TableResult.wait_for_state(test_handle, [State.ACTIVE, State.DROPPED], wait_timeout, 1000, result=result) else: test_handle.do_table_request(request, wait_timeout, 1000)
def setUp(self): self.handles = list() self.num_handles = 1 if is_pod() else 2 for handle in range(self.num_handles): self.handles.append(get_handle(tenant_id + str(handle))) self.list_tables_request = ListTablesRequest().set_timeout(timeout)