def test_readwrite(self): sessRec = DepiMcastSessionRecord() sessRec.updateDepiMcastSessionKey(IpAddrType=1, GroupIpAddr="10.79.31.1", SrcIpAddr="10.79.31.1", SessionId=1) self.assertEquals(sessRec.index.IpAddrType, 1) self.assertEquals(sessRec.index.SrcIpAddr, "10.79.31.1") self.assertEquals(sessRec.index.SessionId, 1) sessRec.write() # get_all ret = [] for ses in sessRec.get_all(): ret.append(ses) self.assertEquals(len(ret), 1) sessRec = None sessRec = DepiMcastSessionRecord() sessRec.updateDepiMcastSessionKey(IpAddrType=1, GroupIpAddr="10.79.31.1", SrcIpAddr="10.79.31.1", SessionId=1) sessRec.read() self.assertEquals(sessRec.index.IpAddrType, 1) self.assertEquals(sessRec.index.GroupIpAddr, "10.79.31.1") self.assertEquals(sessRec.index.SrcIpAddr, "10.79.31.1") self.assertEquals(sessRec.index.SessionId, 1) self.assertEquals(sessRec.JoinTime, "") self.assertEquals(sessRec.LocalLcceIpAddr, "") self.assertEquals(sessRec.RemoteLcceIpAddr, "") # modify the property currtime = Convert.pack_timestamp_to_string(time.time()) sessRec.JoinTime = currtime sessRec.write() sessRec.read() self.assertEquals(sessRec.index.IpAddrType, 1) self.assertEquals(sessRec.index.GroupIpAddr, "10.79.31.1") self.assertEquals(sessRec.index.SrcIpAddr, "10.79.31.1") self.assertEquals(sessRec.index.SessionId, 1) self.assertEquals(sessRec.JoinTime, currtime) self.assertEquals(sessRec.LocalLcceIpAddr, "") self.assertEquals(sessRec.RemoteLcceIpAddr, "") # get_all ret = [] for ses in sessRec.get_all(): ret.append(ses) self.assertEquals(len(ret), 1)
def test_get_all_ipv6(self): sessRec = DepiMcastSessionRecord() sessRec.updateDepiMcastSessionKey(IpAddrType=1, GroupIpAddr="2001::1", SrcIpAddr="2001::1", SessionId=1) sessRec.write() ret = [] for ses in sessRec.get_all(): ret.append(ses) self.assertEquals(len(ret), 1)
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_no_dup_record(self): sessRec = DepiMcastSessionRecord() sessRec.updateDepiMcastSessionKey(IpAddrType=1, GroupIpAddr="10.79.31.1", SrcIpAddr="10.79.31.1", SessionId=1) sessRec.write() sessRec = None sessRec = DepiMcastSessionRecord() sessRec.updateDepiMcastSessionKey(IpAddrType=1, GroupIpAddr="10.79.31.1", SrcIpAddr="10.79.31.1", SessionId=1) sessRec.write() ret = [] for ses in sessRec.get_all(): ret.append(ses) self.assertEquals(len(ret), 1)