Esempio n. 1
0
    def test_addreplica_pid_group(self, pid_group, exp_msg):
        """
        添加副本一次执行多个分片
        :return:
        """
        name = 't{}'.format(time.time())
        infoLogger.info(name)
        metadata_path = '{}/metadata.txt'.format(self.testpath)
        m = utils.gen_table_metadata(
            '"{}"'.format(name), '"kLatestTime"', 100, 8,
            ('table_partition', '"{}"'.format(self.leader), '"0-5"', 'true'))
        utils.gen_table_metadata_file(m, metadata_path)
        rs1 = self.ns_create(self.ns_leader, metadata_path)
        self.assertIn('Create table ok', rs1)
        rs2 = self.ns_addreplica(self.ns_leader, name, pid_group, self.slave1)
        self.assertIn(exp_msg, rs2)
        if 'AddReplica ok' in rs2:
            time.sleep(20)
            rs3 = self.showtable(self.ns_leader, name)
            self.tid = int(rs3.keys()[0][1])
            self.assertIn((name, str(self.tid), '0', self.slave1), rs3)
            if pid_group == "0-3":
                self.assertIn((name, str(self.tid), '1', self.slave1), rs3)
                self.assertIn((name, str(self.tid), '2', self.slave1), rs3)
                self.assertIn((name, str(self.tid), '3', self.slave1), rs3)
            elif pid_group == '0,2,3':
                self.assertIn((name, str(self.tid), '2', self.slave1), rs3)
                self.assertIn((name, str(self.tid), '3', self.slave1), rs3)

        self.ns_drop(self.ns_leader, name)
Esempio n. 2
0
 def setUp(self):
     infoLogger.info('\nTEST CASE NAME: {} {} {}'.format(
         self, self._testMethodDoc,
         '\n' + '|' * 50 + ' SETUP STARTED ' + '|' * 50 + '\n'))
     try:
         self.ns_leader = utils.exe_shell('head -n 1 {}/ns_leader'.format(
             self.testpath))
         nss = copy.deepcopy(conf.ns_endpoints)
         nss.remove(self.ns_leader)
         self.ns_slaver = nss[0]
         self.ns_leader_path = utils.exe_shell(
             'tail -n 1 {}/ns_leader'.format(self.testpath))
         self.tid = random.randint(1, 1000)
         self.pid = random.randint(1, 1000)
         if conf.cluster_mode == "cluster":
             self.clear_ns_table(self.ns_leader)
         else:
             for edp in conf.tb_endpoints:
                 self.clear_tb_table(edp)
         #remote env
         self.alias = 'rem'
         self.ns_leader_r = utils.exe_shell(
             'head -n 1 {}/ns_leader_remote'.format(self.testpath))
         nss_r = copy.deepcopy(conf.ns_endpoints_r)
         nss_r.remove(self.ns_leader_r)
         self.ns_slaver_r = nss_r[0]
         self.ns_leader_path_r = utils.exe_shell(
             'tail -n 1 {}/ns_leader_remote'.format(self.testpath))
         self.clear_ns_table(self.ns_leader_r)
         for edp in conf.tb_endpoints_r:
             self.clear_tb_table(edp)
     except Exception as e:
         traceback.print_exc(file=sys.stdout)
     infoLogger.info('\n\n' + '=' * 50 + ' SETUP FINISHED ' + '=' * 50 +
                     '\n')
Esempio n. 3
0
    def test_addreplica_offline(self):
        """
        添加一个offline的副本,添加失败
        :return:
        """
        self.start_client(self.slave1)
        metadata_path = '{}/metadata.txt'.format(self.testpath)
        name = '"tname{}"'.format(time.time())
        infoLogger.info(name)
        m = utils.gen_table_metadata(
            name,
            None,
            144000,
            2,
            ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'),
        )
        utils.gen_table_metadata_file(m, metadata_path)
        rs = self.ns_create(self.ns_leader, metadata_path)
        self.assertIn('Create table ok', rs)

        self.stop_client(self.slave1)
        time.sleep(10)

        infoLogger.info(self.showtablet(self.ns_leader))
        rs2 = self.addreplica(self.ns_leader, name, 1, 'ns_client',
                              self.slave1)
        self.assertIn('Fail to addreplica', rs2)
        self.start_client(self.slave1)
        self.ns_drop(self.ns_leader, name)
Esempio n. 4
0
    def test_addreplica_args_invalid(self, tname, pid, endpoint,
                                     exp_msg):  # RTIDB-201
        """
        建表时带副本,然后添加新副本时,参数异常检查
        :return:
        """
        name = 't{}'.format(time.time())
        infoLogger.info(name)
        metadata_path = '{}/metadata.txt'.format(self.testpath)
        m = utils.gen_table_metadata(
            '"{}"'.format(name), '"kLatestTime"', 100, 8,
            ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'),
            ('table_partition', '"{}"'.format(self.slave1), '"0-1"', 'false'))
        utils.gen_table_metadata_file(m, metadata_path)
        rs1 = self.ns_create(self.ns_leader, metadata_path)
        self.assertIn('Create table ok', rs1)

        table_name = name if tname is None else tname
        tpid = 1 if pid is None else pid
        tendpoint = self.slave2 if endpoint is None else endpoint

        rs2 = self.addreplica(self.ns_leader, table_name, tpid, 'ns_client',
                              tendpoint)
        self.assertIn(exp_msg, rs2)
        self.ns_drop(self.ns_leader, name)
Esempio n. 5
0
 def start_client(self, endpoint, role='tablet'):
     client_path = self.node_path_dict[endpoint]
     if role == 'tablet' or role == 'nameserver':
         conf = role
     else:
         pass
     cmd = '{}/fedb --flagfile={}/conf/{}.flags'.format(
         self.testpath, client_path, conf)
     infoLogger.info(cmd)
     args = shlex.split(cmd)
     need_start = False
     for _ in range(20):
         rs = utils.exe_shell('lsof -i:{}|grep -v "PID"'.format(
             endpoint.split(':')[1]))
         if 'fedb' not in rs:
             need_start = True
             time.sleep(1)
             subprocess.Popen(
                 args,
                 stdout=open('{}/info.log'.format(client_path), 'a'),
                 stderr=open('{}/warning.log'.format(client_path), 'a'))
         else:
             time.sleep(1)
             rs = utils.exe_shell('lsof -i:{}|grep -v "PID"'.format(
                 endpoint.split(':')[1]))
             if 'fedb' in rs:
                 return True, need_start
     return False, need_start
Esempio n. 6
0
 def test_addreplica_no_snapshot(self):
     """
     没有snapshot,添加副本成功,数据追加成功
     :return:
     """
     metadata_path = '{}/metadata.txt'.format(self.testpath)
     name = 'tname{}'.format(time.time())
     infoLogger.info(name)
     m = utils.gen_table_metadata(
         '"{}"'.format(name),
         None,
         144000,
         2,
         ('table_partition', '"{}"'.format(self.leader), '"0-2"', 'true'),
     )
     utils.gen_table_metadata_file(m, metadata_path)
     rs1 = self.ns_create(self.ns_leader, metadata_path)
     self.assertIn('Create table ok', rs1)
     rs2 = self.showtable(self.ns_leader, name)
     tid = rs2.keys()[0][1]
     rs3 = self.put(self.leader, tid, 1, 'testkey0',
                    self.now() + 9999, 'testvalue0')
     self.assertIn('Put ok', rs3)
     rs4 = self.addreplica(self.ns_leader, name, 1, 'ns_client',
                           self.slave1)
     self.assertIn('AddReplica ok', rs4)
     time.sleep(5)
     rs5 = self.showtable(self.ns_leader, name)
     self.assertIn((name, tid, '1', self.leader), rs5.keys())
     self.assertIn((name, tid, '1', self.slave1), rs5.keys())
     self.assertIn(
         'testvalue0',
         self.scan(self.slave1, tid, 1, 'testkey0',
                   self.now() + 9999, 1))
     self.ns_drop(self.ns_leader, name)
Esempio n. 7
0
    def test_ns_drop_table(self):
        """
        通过ns建的表,可以通过ns全部drop掉,drop后gettablestatus为空
        :return:
        """
        metadata_path = '{}/metadata.txt'.format(self.testpath)
        name = 'tname{}'.format(time.time())
        m = utils.gen_table_metadata(
            '"{}"'.format(name), None, 144000, 2,
            ('table_partition', '"{}"'.format(self.leader), '"0-7"', 'true'),
            ('table_partition', '"{}"'.format(self.slave1), '"0-7"', 'false'),
            ('table_partition', '"{}"'.format(self.slave2), '"0-7"', 'false'),
            ('column_desc', '"k1"', '"string"', 'true'),
            ('column_desc', '"k2"', '"string"', 'false'),
            ('column_desc', '"k3"', '"string"', 'true'),
        )
        utils.gen_table_metadata_file(m, metadata_path)
        rs0 = self.ns_create(self.ns_leader, metadata_path)
        self.assertIn('Create table ok', rs0)

        rs1 = self.showtable(self.ns_leader, name)
        tid = rs1.keys()[0][1]
        rs3 = self.get_table_status(self.leader, tid, 0)
        infoLogger.info(rs3)
        self.assertNotEqual(rs3, None)
        self.ns_drop(self.ns_leader, name)
        time.sleep(2)
        rs2 = self.showtable(self.ns_leader, name)
        rs3 = self.get_table_status(self.leader, tid, 0)

        self.assertEqual(len(rs1), 24)
        self.assertEqual(rs2, {})
        self.assertEqual(rs3, None)
Esempio n. 8
0
 def clear_tb_table(self, endpoint):
     table_dict = self.get_table_status(endpoint)
     if isinstance(table_dict, dict):
         for tid_pid in table_dict:
             self.drop(endpoint, tid_pid[0], tid_pid[1])
     else:
         infoLogger.info('gettablestatus empty.')
Esempio n. 9
0
 def test_ttl_latest_2_check_ttl(self, tid, ttl, value_ts_scannable):
     """
     depends on test_ttl_latest_1_ready_test
     :param tid:
     :param ttl:
     :param value_ts_scannable:
     :return:
     """
     self.multidimension_scan_vk = {'card': 'pk'}  # for multidimension
     if ttl.find("latest") == -1:
         rs1 = self.scan(self.leader, tid, 0, 'pk', self.now(), 1)
         infoLogger.info(rs1)
         for k, v in value_ts_scannable.items():
             if v is True:
                 self.assertIn('|{}|'.format(k[0]), rs1)
             else:
                 self.assertNotIn('|{}|'.format(k[0]), rs1)
     else:
         for k, v in value_ts_scannable.items():
             rs = self.get(self.leader, tid, 0, 'pk', k[1])
             infoLogger.info(rs)
             if v is True:
                 self.assertIn('|{}|'.format(k[0]), rs)
             else:
                 self.assertNotIn('|{}|'.format(k[0]), rs)
     self.drop(self.leader, tid, 0)
Esempio n. 10
0
 def test_ns_after_failover(self, *steps):
     """
     ns故障切换后,新主可以判断节点状态
     :param steps:
     :return:
     """
     self.createtable_put()
     rs1 = self.showtable(self.ns_leader, self.tname)
     steps_dict = self.get_steps_dict()
     for i in steps:
         infoLogger.info('*' * 10 +
                         ' Executing step {}: {}'.format(i, steps_dict[i]))
         eval(steps_dict[i])
     rs2 = self.showtable(self.ns_leader, self.tname)
     self.stop_client(self.leader)
     self.updatetablealive(self.ns_leader, self.tname, '*', self.leader,
                           'no')
     time.sleep(10)
     rs3 = self.showtablet(self.ns_leader)
     rs4 = self.showtable(self.ns_leader, self.tname)
     self.start_client(self.leader)
     self.stop_client(self.ns_leader)
     self.start_client(self.ns_leader, 'nameserver')
     time.sleep(10)
     self.get_new_ns_leader()
     self.assertEqual(rs1, rs2)
     self.assertEqual(rs3[self.leader][0], 'kTabletOffline')
     self.assertEqual(
         [v[-2] for k, v in rs4.items() if k[-1] == self.leader],
         ['no'] * 4)
     self.ns_drop(self.ns_leader, self.tname)
Esempio n. 11
0
 def test_create_showtable_record_cnt(self, exp_msg, *eles):
     """
     使用文件column_key创建表,put数据后showtable检查record的数量
     """
     name = 'tname{}'.format(time.time())
     metadata_path = '{}/metadata.txt'.format(self.testpath)
     table_meta = {
         "name": name,
         "ttl": 120,
         "partition_num": 3,
         "replica_num": 3,
         "column_desc": [],
         "column_key": []
     }
     for item in eles:
         table_meta[item[0]].append(item[1])
     utils.gen_table_meta_file(table_meta, metadata_path)
     rs = self.ns_create(self.ns_leader, metadata_path)
     infoLogger.info(rs)
     self.assertIn(exp_msg, rs)
     self.ns_put_multi(self.ns_leader, name, 10, ['card0', '123', '1.1'])
     self.ns_put_multi(self.ns_leader, name, 10, ['card1', '123', '2.2'])
     self.ns_put_multi(self.ns_leader, name, 10, ['card1', '233', '3.3'])
     self.ns_put_multi(self.ns_leader, name, 10, ['card0', '233', '4.4'])
     time.sleep(2)
     table_info = self.showtable_with_tablename(self.ns_leader, name)
     table_info = self.parse_tb(table_info, ' ', [1, 2, 3], [9])
     record_cnt = 0
     for k, v in table_info.items():
         record_cnt += int(v[0])
     self.assertEqual(record_cnt, 12)
     self.ns_drop(self.ns_leader, name)
    def test_auto_recover_table(self, *steps):
        """
        tablet故障恢复流程测试
        :param steps:
        :return:
        """
        self.get_new_ns_leader()
        steps_dict = self.get_steps_dict()
        for i in steps:
            infoLogger.info('*' * 10 +
                            ' Executing step {}: {}'.format(i, steps_dict[i]))
            eval(steps_dict[i])

        rs = self.showtable(self.ns_leader, self.tname)
        role_x = [v[0] for k, v in rs.items()]
        is_alive_x = [v[-2] for k, v in rs.items()]
        for repeat in range(10):
            rs = self.showtable(self.ns_leader, self.tname)
            role_x = [v[0] for k, v in rs.items()]
            is_alive_x = [v[-2] for k, v in rs.items()]
            if role_x.count('leader') == 10 and role_x.count(
                    'follower') == 18 and is_alive_x.count('yes') == 28:
                break
            time.sleep(2)
        self.assertEqual(role_x.count('leader'), 10)
        self.assertEqual(role_x.count('follower'), 18)
        self.assertEqual(is_alive_x.count('yes'), 28)
        self.assertEqual(
            self.get_table_status(self.leader, self.tid, self.pid)[0],
            self.get_table_status(self.slave1, self.tid, self.pid)[0])
        self.assertEqual(
            self.get_table_status(self.leader, self.tid, self.pid)[0],
            self.get_table_status(self.slave2, self.tid, self.pid)[0])
        self.ns_drop(self.ns_leader, self.tname)
Esempio n. 13
0
 def test_create_partition_column_order(self, exp_msg, *eles):
     """
     table_partition和column_desc的前后顺序测试,无论顺序如何,都会拼成完整的schema
     :param exp_msg:
     :param eles:
     :return:
     """
     tname = 'tname{}'.format(time.time())
     metadata_path = '{}/metadata.txt'.format(self.testpath)
     m = utils.gen_table_metadata('"' + tname + '"', '"kAbsoluteTime"',
                                  144000, 8, *eles)
     utils.gen_table_metadata_file(m, metadata_path)
     rs = self.ns_create(self.ns_leader, metadata_path)
     infoLogger.info(rs)
     self.assertIn(exp_msg, rs)
     rs1 = self.showtable(self.ns_leader, tname)
     tid = rs1.keys()[0][1]
     infoLogger.info(rs1)
     self.assertEqual(rs1[(tname, tid, '0', self.leader)],
                      ['leader', '144000min', 'yes', 'kNoCompress'])
     self.assertEqual(rs1[(tname, tid, '0', self.slave1)],
                      ['follower', '144000min', 'yes', 'kNoCompress'])
     self.assertEqual(rs1[(tname, tid, '2', self.slave2)],
                      ['follower', '144000min', 'yes', 'kNoCompress'])
     (schema, column_key) = self.showschema(self.slave1, tid, 0)
     self.assertEqual(len(schema), 3)
     self.assertEqual(len(column_key), 0)
     self.assertEqual(schema[0], ['0', 'k1', 'string', 'yes'])
     self.assertEqual(schema[1], ['1', 'k2', 'double', 'no'])
     self.assertEqual(schema[2], ['2', 'k3', 'int32', 'yes'])
     self.ns_drop(self.ns_leader, tname)
Esempio n. 14
0
 def test_ttl_abnormal_create_md(self, ttl, exp_msg):
     """
     ttl = latest:abnormal
     :return:
     """
     rs1 = self.create(self.leader, 't', self.tid, self.pid, ttl, 2, 'true')
     infoLogger.info(rs1)
     self.assertIn(exp_msg, rs1)
Esempio n. 15
0
    def test_auto_failover_disconnectzk(self):
        """
        auto_failover打开后,然后put数据,disconnectzk的所有tablet。最后一个节点状态应该不变
        :return:
        """
        self.confset(self.ns_leader, 'auto_failover', 'true')
        name = 't{}'.format(time.time())
        infoLogger.info(name)
        rs1 = self.ns_create_cmd(self.ns_leader, name, 144000, 1, 3, '')
        self.assertIn('Create table ok', rs1)

        number = 3
        for i in range(number):
            rs_put = self.ns_put_kv(self.ns_leader, name, 'key{}'.format(i),
                                    self.now() - 1, 'value{}'.format(i))
            self.assertIn('Put ok', rs_put)
        time.sleep(1)

        rs = self.disconnectzk(self.slave1)
        self.assertIn('disconnect zk ok', rs)
        time.sleep(1)
        rs = self.disconnectzk(self.slave2)
        self.assertIn('disconnect zk ok', rs)
        time.sleep(1)
        rs = self.disconnectzk(self.leader)
        self.assertIn('disconnect zk ok', rs)
        time.sleep(1)
        flag_yes = 0
        flag_no = 0
        for repeat in range(10):
            time.sleep(2)
            result = ['']
            rs_show = self.showtable(self.ns_leader)
            row = 0
            for i in rs_show:
                result.append(rs_show.values()[row][2])
                row = row + 1
            flag_yes = 0
            flag_no = 0
            for i in result:
                if i == 'yes':
                    flag_yes = flag_yes + 1
                if i == 'no':
                    flag_no = flag_no + 1
            if flag_no == 2 and flag_yes == 1:
                break
        self.assertEqual(flag_no, 2)
        self.assertEqual(flag_yes, 1)

        self.confset(self.ns_leader, 'auto_failover', 'false')

        self.connectzk(self.leader)
        self.connectzk(self.slave1)
        self.connectzk(self.slave2)
        self.get_new_ns_leader()
        time.sleep(3)
        self.ns_drop(self.ns_leader, name)
Esempio n. 16
0
 def clear_ns_table(self, endpoint):
     table_dict = self.showtable(endpoint)
     if isinstance(table_dict, dict):
         tname_tids = table_dict.keys()
         tnames = set([i[0] for i in tname_tids])
         for tname in tnames:
             self.ns_drop(endpoint, tname)
     else:
         infoLogger.info('showtable empty.')
Esempio n. 17
0
 def test_showtablet_healthy(self):
     """
     健康的节点,状态为kTabletHealthy
     :return:
     """
     rs1 = self.showtablet(self.ns_leader)
     infoLogger.info(rs1)
     self.assertEqual(rs1[self.leader][0], 'kTabletHealthy')
     self.assertEqual(rs1[self.slave1][0], 'kTabletHealthy')
     self.assertEqual(rs1[self.slave2][0], 'kTabletHealthy')
Esempio n. 18
0
 def check_op_done(self, tname):
     rs = self.run_client(self.ns_leader, 'showopstatus {} '.format(tname),
                          'ns_client')
     infoLogger.info(rs)
     opstatus = self.parse_tb(rs, ' ', [0], [1, 4, 8])
     infoLogger.info(opstatus)
     for op_id in opstatus.keys():
         if opstatus[op_id][1] == "kDoing" or opstatus[op_id][
                 1] == "kInited":
             return False
     return True
Esempio n. 19
0
 def test_sendsnapshot_normal(self, *steps):
     """
     各种情况下sendsnapshot功能检查
     :param steps:
     :return:
     """
     self.tname = str(self.now())
     steps_dict = self.get_steps_dict()
     for i in steps:
         infoLogger.info('*' * 10 + ' Executing step {}: {}'.format(i, steps_dict[i]))
         eval(steps_dict[i])
Esempio n. 20
0
 def tearDownClass(cls):
     for edp in conf.tb_endpoints:
         utils.exe_shell('rm -rf {}/recycle/*'.format(
             cls.node_path_dict[edp]))
         utils.exe_shell('rm -rf {}/db/*'.format(cls.node_path_dict[edp]))
     for edp in conf.tb_endpoints_r:
         utils.exe_shell('rm -rf {}/recycle/*'.format(
             cls.node_path_dict_r[edp]))
         utils.exe_shell('rm -rf {}/db/*'.format(cls.node_path_dict_r[edp]))
     infoLogger.info('\n' + '=' * 50 + ' TEST {} FINISHED '.format(cls) +
                     '=' * 50 + '\n' * 5)
Esempio n. 21
0
 def setUp(self):
     infoLogger.info('\n' * 5 + 'TEST CASE NAME: ' + self._testMethodName +
                     self._testMethodDoc)
     self.ns_leader = utils.exe_shell('head -n 1 {}/ns_leader'.format(
         self.testpath))
     self.ns_leader_path = utils.exe_shell('tail -n 1 {}/ns_leader'.format(
         self.testpath))
     self.tid = random.randint(1, 1000)
     self.pid = random.randint(1, 1000)
     self.clear_ns_table(self.ns_leader)
     infoLogger.info('\n\n' + '|' * 50 + ' SETUP FINISHED ' + '|' * 50 +
                     '\n')
Esempio n. 22
0
 def find_new_tb_leader(self, tname, tid, pid):
     rs = self.showtable(self.ns_leader, tname)
     infoLogger.info(rs)
     for (key, value) in rs.items():
         if key[1] == str(tid) and key[2] == str(pid):
             infoLogger.info(value)
             if value[0] == "leader" and value[2] == "yes":
                 new_leader = key[3]
                 infoLogger.debug('------new leader:' + new_leader +
                                  '-----------')
     self.new_tb_leader = new_leader
     return new_leader
Esempio n. 23
0
    def check_manifest(self, db_path, tid, pid, offset, name, count):
        try:
            mf = self.get_manifest(db_path, tid, pid)
            infoLogger.info(mf)
            self.assertEqual(mf['offset'], offset)
            self.assertEqual(mf['name'], name)
            self.assertEqual(mf['count'], count)
            return True
        except Exception as e:
            infoLogger.info(e)

            return False
Esempio n. 24
0
 def check_tasks(self, op_id, exp_task_list):
     self.get_task_dict_by_opid(self.tname, op_id)
     tasks = [
         k[1] for k, v in self.task_dict.items()
         if k[0] == int(op_id) and v == 'kDone'
     ]
     infoLogger.info(self.task_dict)
     infoLogger.info(op_id)
     infoLogger.info([k[1] for k, v in self.task_dict.items()])
     infoLogger.info(tasks)
     infoLogger.info(exp_task_list)
     self.assertEqual(exp_task_list, tasks)
Esempio n. 25
0
 def test_create_cmd_index_float_or_double(self, exp_msg, ttl,
                                           partition_num, replica_num,
                                           schema):
     """
     不用文件, 直接在命令行指定建表信息
     :return:
     """
     tname = 'tname{}'.format(time.time())
     rs = self.ns_create_cmd(self.ns_leader, tname, ttl, partition_num,
                             replica_num, schema)
     infoLogger.info(rs)
     self.assertIn(exp_msg, rs)
Esempio n. 26
0
 def fn(arg_self):
     for data in data_list:
         if isinstance(data, list):
             try:
                 f(arg_self, *data)
             except Exception, e:
                 infoLogger.error('{}({}) failed: {}'.format(
                     f.__name__, data, e))
                 print '{}({}) failed: {}'.format(f.__name__, data, e)
                 infoLogger.info(dir(f))
         else:
             infoLogger.error('data_list type must be a list')
Esempio n. 27
0
 def test_scan_preview(self):
     """
     预览
     :return:
     """
     rs1 = self.create(self.leader, 't', self.tid, self.pid, 0, 8)
     self.assertIn('Create table ok', rs1)
     if self.multidimension:
         self.put(self.leader, self.tid, self.pid, '', 11, 'mcc0', '1.5',
                  'card0')
         self.put(self.leader, self.tid, self.pid, '', 22, 'mcc1', '2.5',
                  'card0')
         self.put(self.leader, self.tid, self.pid, '', 33, 'mcc1', '10.2',
                  'card1')
     else:
         self.put(self.leader, self.tid, self.pid, 'testkey0', 11,
                  'testvalue0')
         self.put(self.leader, self.tid, self.pid, 'testkey0', 22,
                  'testvalue1')
         self.put(self.leader, self.tid, self.pid, 'testkey1', 33,
                  'testvalue2')
     rs2 = self.preview(self.leader, self.tid, self.pid)
     rs3 = self.preview(self.leader, self.tid, self.pid, 2)
     infoLogger.info(rs2)
     if self.multidimension:
         self.assertEqual(3, len(rs2))
         self.assertEqual(2, len(rs3))
         self.assertEqual(rs2[0]['card'], 'card0')
         self.assertEqual(rs2[0]['merchant'], 'mcc0')
         self.assertEqual(rs2[1]['card'], 'card1')
         self.assertEqual(rs2[1]['merchant'], 'mcc1')
         self.assertEqual(rs2[2]['card'], 'card0')
         self.assertEqual(rs2[2]['merchant'], 'mcc1')
         self.assertEqual(2, len(rs3))
         self.assertEqual(rs3[0]['card'], 'card0')
         self.assertEqual(rs3[0]['merchant'], 'mcc0')
         self.assertEqual(rs3[1]['card'], 'card1')
         self.assertEqual(rs3[1]['merchant'], 'mcc1')
     else:
         self.assertEqual(3, len(rs2))
         self.assertEqual(rs2[0]['key'], 'testkey0')
         self.assertEqual(rs2[0]['data'], 'testvalue1')
         self.assertEqual(rs2[1]['key'], 'testkey0')
         self.assertEqual(rs2[1]['data'], 'testvalue0')
         self.assertEqual(rs2[2]['key'], 'testkey1')
         self.assertEqual(rs2[2]['data'], 'testvalue2')
         self.assertEqual(2, len(rs3))
         self.assertEqual(rs3[0]['key'], 'testkey0')
         self.assertEqual(rs3[0]['data'], 'testvalue1')
         self.assertEqual(rs3[1]['key'], 'testkey0')
         self.assertEqual(rs3[1]['data'], 'testvalue0')
Esempio n. 28
0
    def test_ttl_put_after_ttl(self, ttl, value_ts_scannable, put_value_ts,
                               value_ts_scannable2):  # RTIDB-181
        """
        ttl后put数据,再次ttl后数据正确
        :param ttl:
        :param value_ts_scannable:
        :param put_value_ts:
        :param value_ts_scannable2:
        :return:
        """
        self.create(self.leader, 't', self.tid, self.pid, ttl, 2, 'true')
        for i in value_ts_scannable.keys():
            # for multidimension test
            self.multidimension_vk = {
                'card': ('string:index', 'pk'),
                'merchant': ('string:index', '|{}|'.format(i[0])),
                'amt': ('double', 1.1)
            }
            for ts in range(100):
                self.put(self.leader, self.tid, self.pid, 'pk', i[1] - ts,
                         '|{}|'.format(i[0]))
        time.sleep(1)

        self.multidimension_scan_vk = {'card': 'pk'}  # for multidimension
        for k, v in value_ts_scannable.items():
            rs = self.get(self.leader, self.tid, self.pid, 'pk', k[1])
            infoLogger.info(rs)
            if v is True:
                self.assertIn('|{}|'.format(k[0]), rs)
            else:
                self.assertNotIn('|{}|'.format(k[0]), rs)
        # put again after the last gc
        for i in put_value_ts:
            # for multidimension test
            self.multidimension_vk = {
                'card': ('string:index', 'pk'),
                'merchant': ('string:index', '|{}|'.format(i[0])),
                'amt': ('double', 1.1)
            }
            for ts in range(100):
                self.put(self.leader, self.tid, self.pid, 'pk', i[1] - ts,
                         '|{}|'.format(i[0]))
        time.sleep(1)
        for k, v in value_ts_scannable2.items():
            rs = self.get(self.leader, self.tid, self.pid, 'pk', k[1])
            infoLogger.info(rs)
            if v is True:
                self.assertIn('|{}|'.format(k[0]), rs)
            else:
                self.assertNotIn('|{}|'.format(k[0]), rs)
Esempio n. 29
0
    def tearDown(self):
        infoLogger.info('\n\n' + '|' * 50 + ' TEARDOWN STARTED ' + '|' * 50 +
                        '\n')
        try:
            rs = self.showtablet(self.ns_leader)
            for edp in conf.tb_endpoints:
                if rs[edp][0] != 'kTabletHealthy':
                    infoLogger.info("Endpoint offline !!!! " * 10 + edp)
                    self.stop_client(edp)
                    time.sleep(1)
                    self.start_client(edp)
                    time.sleep(10)
            if conf.cluster_mode == "cluster":
                self.clear_ns_table(self.ns_leader)

            #remote env
            rs_r = self.showtablet(self.ns_leader_r)
            for edp in conf.tb_endpoints_r:
                if rs_r[edp][0] != 'kTabletHealthy':
                    infoLogger.info("Endpoint offline !!!! " * 10 + edp)
                    self.stop_client(edp)
                    time.sleep(1)
                    self.start_client(edp)
                    time.sleep(10)
            if conf.cluster_mode == "cluster":
                self.clear_ns_table(self.ns_leader_r)
        except Exception as e:
            traceback.print_exc(file=sys.stdout)
        infoLogger.info('\n\n' + '=' * 50 + ' TEARDOWN FINISHED ' + '=' * 50 +
                        '\n' * 5)
Esempio n. 30
0
 def get_task_dict_by_opid(self, tname, opid):
     time.sleep(1)
     task_dict = collections.OrderedDict()
     cmd = "cat {}/warning.log |grep -a -A 10000 '{}'|grep -a \"op_id\[{}\]\"|grep task_type".format(
         self.ns_leader_path, tname, opid) \
           + "|awk -F '\\\\[' '{print $3\"]\"$4\"]\"$5}'" \
             "|awk -F '\\\\]' '{print $1\",\"$3\",\"$5}'"
     infoLogger.info(cmd)
     rs = utils.exe_shell(cmd).split('\n')
     infoLogger.info(rs)
     for x in rs:
         x = x.split(',')
         task_dict[(int(x[1]), x[2])] = x[0]
     self.task_dict = task_dict