def test_get_next_n(self): sessRec = DepiMcastSessionRecord() sessRec.updateDepiMcastSessionKey(IpAddrType=1, GroupIpAddr="10.79.31.1", SrcIpAddr="10.79.31.1", SessionId=1) sessRec.write() sessRec.updateDepiMcastSessionKey(IpAddrType=1, GroupIpAddr="10.79.31.1", SrcIpAddr="10.79.31.1", SessionId=2) sessRec.write() sessRec = DepiMcastSessionRecord() sessRec.updateDepiMcastSessionKey(IpAddrType=1, GroupIpAddr="10.79.31.1", SrcIpAddr="10.78.31.1", SessionId=1) sessRec.write() sessRec = DepiMcastSessionRecord() sessRec.updateDepiMcastSessionKey(IpAddrType=1, GroupIpAddr="10.79.31.1", SrcIpAddr="10.78.31.1", SessionId=2) sessRec.write() print "#########step 1: None key query, return value from the very first record" ret = [] for record in sessRec.get_next_n(key=None, count=2): ret.append(record) self.assertEquals(len(ret), 2) print "#########step 2: key query, request count is larger than db have" record = DepiMcastSessionRecord() record.updateDepiMcastSessionKey(IpAddrType=1, GroupIpAddr="10.79.31.1", SrcIpAddr="10.79.31.1", SessionId=2) test_key = record.index ret = [] for record in sessRec.get_next_n(key=None, count=2): ret.append(record) self.assertEquals(len(ret), 2) print "#########step 3: key query, request key is larger than db have" record = DepiMcastSessionRecord() record.updateDepiMcastSessionKey(IpAddrType=1, GroupIpAddr="10.79.31.1", SrcIpAddr="10.90.31.1", SessionId=1) ret = [] for record in sessRec.get_next_n(key=None, count=2): ret.append(record) self.assertEquals(len(ret), 2)
def test_performance(self): sessRec = DepiMcastSessionRecord() test_count = 1000 print "#########: perfermance test about %s session in store" % test_count current_time = time.time() print "current time is: " + str( datetime.datetime.fromtimestamp(current_time)) for test_session in range(0, test_count): sessRec.updateDepiMcastSessionKey(IpAddrType=1, GroupIpAddr="10.79.31.1", SrcIpAddr="10.90.31.1", SessionId=test_session) test_time = Convert.pack_timestamp_to_string(time.time()) sessRec.updateDepiMcastSessionData("10.1.1.1", "1.1.1.1", test_time) sessRec.write() print "Write " + str(test_count) + " records need : " + str( time.time() - current_time) current_time = time.time() ret = [] for record in sessRec.get_next_n(count=test_count): ret.append(record) self.assertEquals(len(ret), test_count) print "get_next_n " + str(test_count) + " records need : " + str( time.time() - current_time) print "current time is: " + str( datetime.datetime.fromtimestamp(time.time())) current_time = time.time() ret = [] for record in sessRec.get_next_n(count=20): ret.append(record) self.assertEquals(len(ret), 20) end_time = time.time() print "get_next_n " + str(20) + " records need : " + str(end_time - current_time) print "End time is: " + str(datetime.datetime.fromtimestamp(end_time)) self.assertEquals(len(ret), 20) current_time = time.time() ret = [] for ses in sessRec.get_all(): ret.append(ses) print "get_next_all " + str(test_count) + " records need : " + str( time.time() - current_time) self.assertEquals(len(ret), test_count)
def test_recvRpdInfo_empty(self): # nothing in db sessRec = DepiMcastSessionRecord() ret = [] for record in sessRec.get_next_n(count=100): ret.append(record) self.assertEquals(len(ret), 0) print("######test_recvRpdInfo with empty database######") rcp_msg = t_RcpMessage() rcp_msg.RcpDataResult = t_RcpMessage.RCP_RESULT_OK rcp_msg.RcpMessageType = t_RcpMessage.RPD_CONFIGURATION print("=====test case1: payload operation read, # no read count, no key=====") data = config() data.RpdInfo.DepiMcastSession.add() rcp_msg.RpdDataMessage.RpdData.CopyFrom(data) rcp_msg.RpdDataMessage.RpdDataOperation = 2 payload = rcp_msg.SerializeToString() msg = HalMessage("HalConfig", SrcClientID="testRpdFM", SeqNum=322, CfgMsgType=MsgTypeRpdInfo, CfgMsgPayload=payload) return_str = self.hal_client.recvRpdInfo(msg.msg) config_data = t_RcpMessage() config_data.ParseFromString(msg.msg.CfgMsgPayload) recv_rcp_msg = config_data.RpdDataMessage.RpdData self.assertEqual(len(recv_rcp_msg.RpdInfo.DepiMcastSession), 1) self.assertEqual(config_data.RcpDataResult, t_RcpMessage.RCP_RESULT_OK) print("=====test case2: payload operation read, # read with keylist=====") data = config() for sessionId in range(0, 3): req = data.RpdInfo.DepiMcastSession.add() req.IpAddrType = 1 req.SessionId = sessionId + 1 rcp_msg.RpdDataMessage.RpdData.CopyFrom(data) rcp_msg.RpdDataMessage.RpdDataOperation = 2 payload = rcp_msg.SerializeToString() msg = HalMessage("HalConfig", SrcClientID="testRpdFM", SeqNum=322, CfgMsgType=MsgTypeRpdInfo, CfgMsgPayload=payload) return_str = self.hal_client.recvRpdInfo(msg.msg) config_data = t_RcpMessage() config_data.ParseFromString(msg.msg.CfgMsgPayload) recv_rcp_msg = config_data.RpdDataMessage.RpdData for item in recv_rcp_msg.RpdInfo.DepiMcastSession: print item self.assertEqual(len(recv_rcp_msg.RpdInfo.DepiMcastSession), 3) self.assertEquals(config_data.RcpDataResult, t_RcpMessage.RCP_RESULT_OK) print("=====test case3: payload operation read, # read with readcount=====") data = config() data.ReadCount = 3 req = data.RpdInfo.DepiMcastSession.add() req.IpAddrType = 1 req.SessionId = 0 rcp_msg.RpdDataMessage.RpdData.CopyFrom(data) rcp_msg.RpdDataMessage.RpdDataOperation = 2 payload = rcp_msg.SerializeToString() msg = HalMessage("HalConfig", SrcClientID="testRpdFM", SeqNum=322, CfgMsgType=MsgTypeRpdInfo, CfgMsgPayload=payload) return_str = self.hal_client.recvRpdInfo(msg.msg) config_data = t_RcpMessage() config_data.ParseFromString(msg.msg.CfgMsgPayload) recv_rcp_msg = config_data.RpdDataMessage.RpdData for item in recv_rcp_msg.RpdInfo.DepiMcastSession: print item self.assertEqual(len(recv_rcp_msg.RpdInfo.DepiMcastSession), 1) self.assertEquals(config_data.RcpDataResult, t_RcpMessage.RCP_RESULT_OK)