MT#56753 dlgcnt: use xavp(lua_dlgcnt_vals[0]=>%) to store counter values

Change-Id: I6251c094fab3b2dd86c923adc8e4fc3bf15c3137
mr11.3
Victor Seva 3 years ago
parent 99f73edc7c
commit 576c724ed3

@ -23,6 +23,9 @@ local NGCPDlgCounters = {
local NGCPRedis = require 'ngcp.redis';
local utils = require 'ngcp.utils';
local utable = utils.table;
local xavp_name = 'lua_dlgcnt_vals';
local xavp_fmt_init = '$xavp('..xavp_name..'=>%s)'
local xavp_fmt = '$xavp('..xavp_name..'[0]=>%s)'
_ENV = NGCPDlgCounters
@ -69,13 +72,16 @@ end
if res == 0 then
self.central.client:del(key);
KSR.dbg(string.format("central:del[%s] counter is 0\n", key));
KSR.pv.unset(string.format(xavp_fmt, key))
elseif res < 0 and not self.config.allow_negative then
self.central.client:del(key);
KSR.warn(string.format("central:del[%s] counter was %s\n",
key, tostring(res)));
KSR.pv.unset(string.format(xavp_fmt, key))
else
KSR.dbg(string.format("central:decr[%s]=>[%s]\n",
key, tostring(res)));
KSR.pv.seti(string.format(xavp_fmt, key), res)
end
return res;
end
@ -114,6 +120,11 @@ end
end
local res = self.central.client:incr(key);
KSR.dbg(string.format("central:incr[%s]=>%s\n", key, tostring(res)));
if KSR.pvx.xavp_is_null(xavp_name) > 0 then
KSR.pv.seti(string.format(xavp_fmt_init, key), res)
else
KSR.pv.seti(string.format(xavp_fmt, key), res)
end
if not self.pair:test_connection() then
self.pair:connect()
end

@ -22,7 +22,7 @@ local lu = require('luaunit')
local ksrMock = require 'mocks.ksr'
KSR = ksrMock:new()
local xavp_fmt = '$xavp(lua_dlgcnt_vals[0]=>%s)'
local mc
-- luacheck: ignore TestNGCPDlgCnt
TestNGCPDlgCnt = {} --class
@ -43,6 +43,10 @@ TestNGCPDlgCnt = {} --class
self.dlg.pair.client = self.pair
end
function TestNGCPDlgCnt:tearDown()
KSR.pv.vars = {}
end
function TestNGCPDlgCnt:test_set_1()
self.central:ping() ;mc :returns(true)
self.central:incr("total") ;mc :returns(1)
@ -53,6 +57,8 @@ TestNGCPDlgCnt = {} --class
mc:replay()
self.dlg:set("callid0", "total")
mc:verify()
lu.assertEquals(KSR.pv.get(string.format(xavp_fmt, "total")), 1)
end
function TestNGCPDlgCnt:test_set_2()
@ -71,6 +77,8 @@ TestNGCPDlgCnt = {} --class
self.dlg:set("callid0", "total")
self.dlg:set("callid1", "total")
mc:verify()
lu.assertEquals(KSR.pv.get(string.format(xavp_fmt, "total")), 2)
end
function TestNGCPDlgCnt:test_del()
@ -87,6 +95,7 @@ TestNGCPDlgCnt = {} --class
lu.assertIs(self.dlg.central.client, self.central)
lu.assertIs(self.dlg.pair.client, self.pair)
lu.assertEquals(KSR.pv.get(string.format(xavp_fmt, "total")), 1)
end
function TestNGCPDlgCnt:test_del_zero()
@ -104,6 +113,7 @@ TestNGCPDlgCnt = {} --class
lu.assertIs(self.dlg.central.client, self.central)
lu.assertIs(self.dlg.pair.client, self.pair)
lu.assertIsNil(KSR.pv.get(string.format(xavp_fmt, "total")))
end
function TestNGCPDlgCnt:test_del_negative()
@ -123,6 +133,7 @@ TestNGCPDlgCnt = {} --class
lu.assertIs(self.dlg.central.client, self.central)
lu.assertIs(self.dlg.pair.client, self.pair)
lu.assertIsNil(KSR.pv.get(string.format(xavp_fmt, "total")))
end
function TestNGCPDlgCnt:test_del_negative_ok()
@ -141,6 +152,7 @@ TestNGCPDlgCnt = {} --class
lu.assertIs(self.dlg.central.client, self.central)
lu.assertIs(self.dlg.pair.client, self.pair)
lu.assertEquals(KSR.pv.get(string.format(xavp_fmt, "total")), -1)
end
function TestNGCPDlgCnt:test_del_multy()
@ -167,6 +179,7 @@ TestNGCPDlgCnt = {} --class
lu.assertIs(self.dlg.central.client, self.central)
lu.assertIs(self.dlg.pair.client, self.pair)
lu.assertIsNil(KSR.pv.get(string.format(xavp_fmt, "total")))
end
function TestNGCPDlgCnt:test_is_in_set_fail()

Loading…
Cancel
Save