|
@@ -50,26 +50,26 @@ class TestBasicMethods(unittest.TestCase):
|
|
|
TEST_SPECFILE_LOCATION = TESTDATA_SRCDIR + os.sep + 'test_spec1.spec'
|
|
|
|
|
|
def setUp(self):
|
|
|
- self.counter = counter.Counter(self.TEST_SPECFILE_LOCATION)
|
|
|
+ self.counters = counter.Counters(self.TEST_SPECFILE_LOCATION)
|
|
|
|
|
|
def tearDown(self):
|
|
|
- self.counter.clear_counters()
|
|
|
+ self.counters.clear_counters()
|
|
|
|
|
|
def test_clear_counters(self):
|
|
|
self.assertRaises(isc.cc.data.DataNotFoundError,
|
|
|
- self.counter.get, 'counter')
|
|
|
- self.counter.inc('counter')
|
|
|
- self.assertEqual(self.counter.get('counter'), 1)
|
|
|
- self.counter.clear_counters()
|
|
|
+ self.counters.get, 'counter')
|
|
|
+ self.counters.inc('counter')
|
|
|
+ self.assertEqual(self.counters.get('counter'), 1)
|
|
|
+ self.counters.clear_counters()
|
|
|
self.assertRaises(isc.cc.data.DataNotFoundError,
|
|
|
- self.counter.get, 'counter')
|
|
|
+ self.counters.get, 'counter')
|
|
|
|
|
|
def test_enablediable(self):
|
|
|
- self.assertFalse(self.counter._disabled)
|
|
|
- self.counter.disable()
|
|
|
- self.assertTrue(self.counter._disabled)
|
|
|
- self.counter.enable()
|
|
|
- self.assertFalse(self.counter._disabled)
|
|
|
+ self.assertFalse(self.counters._disabled)
|
|
|
+ self.counters.disable()
|
|
|
+ self.assertTrue(self.counters._disabled)
|
|
|
+ self.counters.enable()
|
|
|
+ self.assertFalse(self.counters._disabled)
|
|
|
|
|
|
def test_add_counter_normal(self):
|
|
|
element = {'counter' : 1}
|
|
@@ -128,30 +128,30 @@ class TestBasicMethods(unittest.TestCase):
|
|
|
counter_name = "counter"
|
|
|
timer_name = "seconds"
|
|
|
start_time = counter._start_timer()
|
|
|
- start_functor(concurrency, number, self.counter.inc,
|
|
|
+ start_functor(concurrency, number, self.counters.inc,
|
|
|
counter_name)
|
|
|
counter._stop_timer(start_time,
|
|
|
- self.counter._statistics._data,
|
|
|
- self.counter._statistics._spec,
|
|
|
+ self.counters._statistics._data,
|
|
|
+ self.counters._statistics._spec,
|
|
|
timer_name)
|
|
|
self.assertEqual(
|
|
|
- counter._get_counter(self.counter._statistics._data,
|
|
|
+ counter._get_counter(self.counters._statistics._data,
|
|
|
counter_name),
|
|
|
concurrency * number)
|
|
|
self.assertGreater(
|
|
|
- counter._get_counter(self.counter._statistics._data,
|
|
|
+ counter._get_counter(self.counters._statistics._data,
|
|
|
timer_name), 0)
|
|
|
|
|
|
-class BaseTestCounter():
|
|
|
+class BaseTestCounters():
|
|
|
|
|
|
def setUp(self):
|
|
|
self._statistics_data = {}
|
|
|
- self.counter = counter.Counter(self.TEST_SPECFILE_LOCATION)
|
|
|
- self._entire_server = self.counter._entire_server
|
|
|
- self._perzone_prefix = self.counter._perzone_prefix
|
|
|
+ self.counters = counter.Counters(self.TEST_SPECFILE_LOCATION)
|
|
|
+ self._entire_server = self.counters._entire_server
|
|
|
+ self._perzone_prefix = self.counters._perzone_prefix
|
|
|
|
|
|
def tearDown(self):
|
|
|
- self.counter.clear_counters()
|
|
|
+ self.counters.clear_counters()
|
|
|
|
|
|
def check_dump_statistics(self):
|
|
|
"""Checks no differences between the value returned from
|
|
@@ -159,10 +159,10 @@ class BaseTestCounter():
|
|
|
checks the result isn't changed even after the method is
|
|
|
invoked twice. Finally checks it is valid for the the
|
|
|
statistics spec."""
|
|
|
- self.assertEqual(self.counter.dump_statistics(),
|
|
|
+ self.assertEqual(self.counters.dump_statistics(),
|
|
|
self._statistics_data)
|
|
|
# Idempotency check
|
|
|
- self.assertEqual(self.counter.dump_statistics(),
|
|
|
+ self.assertEqual(self.counters.dump_statistics(),
|
|
|
self._statistics_data)
|
|
|
if self.TEST_SPECFILE_LOCATION:
|
|
|
self.assertTrue(isc.config.module_spec_from_file(
|
|
@@ -171,35 +171,35 @@ class BaseTestCounter():
|
|
|
else:
|
|
|
self.assertTrue(isc.config.ModuleSpec(
|
|
|
{'module_name': 'Foo',
|
|
|
- 'statistics': self.counter._statistics._spec}
|
|
|
+ 'statistics': self.counters._statistics._spec}
|
|
|
).validate_statistics(
|
|
|
False, self._statistics_data))
|
|
|
|
|
|
def test_perzone_counters(self):
|
|
|
# for per-zone counters
|
|
|
- for name in self.counter._zones_item_list:
|
|
|
+ for name in self.counters._zones_item_list:
|
|
|
args = (self._perzone_prefix, TEST_ZONE_NAME_STR, name)
|
|
|
if name.find('time_to_') == 0:
|
|
|
- self.counter.start(*args)
|
|
|
- self.counter.stop(*args)
|
|
|
- self.assertGreater(self.counter.get(*args), 0)
|
|
|
- sec = self.counter.get(*args)
|
|
|
+ self.counters.start(*args)
|
|
|
+ self.counters.stop(*args)
|
|
|
+ self.assertGreater(self.counters.get(*args), 0)
|
|
|
+ sec = self.counters.get(*args)
|
|
|
for zone_str in (self._entire_server, TEST_ZONE_NAME_STR):
|
|
|
isc.cc.data.set(self._statistics_data,
|
|
|
'%s/%s/%s' % (args[0], zone_str, name), sec)
|
|
|
# twice exec stopper, then second is not changed
|
|
|
- self.counter.stop(*args)
|
|
|
- self.assertEqual(self.counter.get(*args), sec)
|
|
|
+ self.counters.stop(*args)
|
|
|
+ self.assertEqual(self.counters.get(*args), sec)
|
|
|
else:
|
|
|
- self.counter.inc(*args)
|
|
|
- self.assertEqual(self.counter.get(*args), 1)
|
|
|
+ self.counters.inc(*args)
|
|
|
+ self.assertEqual(self.counters.get(*args), 1)
|
|
|
# checks disable/enable
|
|
|
- self.counter.disable()
|
|
|
- self.counter.inc(*args)
|
|
|
- self.assertEqual(self.counter.get(*args), 1)
|
|
|
- self.counter.enable()
|
|
|
- self.counter.inc(*args)
|
|
|
- self.assertEqual(self.counter.get(*args), 2)
|
|
|
+ self.counters.disable()
|
|
|
+ self.counters.inc(*args)
|
|
|
+ self.assertEqual(self.counters.get(*args), 1)
|
|
|
+ self.counters.enable()
|
|
|
+ self.counters.inc(*args)
|
|
|
+ self.assertEqual(self.counters.get(*args), 2)
|
|
|
for zone_str in (self._entire_server, TEST_ZONE_NAME_STR):
|
|
|
isc.cc.data.set(self._statistics_data,
|
|
|
'%s/%s/%s' % (args[0], zone_str, name), 2)
|
|
@@ -209,28 +209,28 @@ class BaseTestCounter():
|
|
|
# for counters of xfer running
|
|
|
_suffix = 'xfr_running'
|
|
|
_xfrrunning_names = \
|
|
|
- isc.config.spec_name_list(self.counter._statistics._spec,
|
|
|
+ isc.config.spec_name_list(self.counters._statistics._spec,
|
|
|
"", True)
|
|
|
for name in _xfrrunning_names:
|
|
|
if name.find(_suffix) != 1: continue
|
|
|
args = name.split('/')
|
|
|
- self.counter.inc(*args)
|
|
|
- self.assertEqual(self.counter.get(*args), 1)
|
|
|
- self.counter.dec(*args)
|
|
|
- self.assertEqual(self.counter.get(*args), 0)
|
|
|
+ self.counters.inc(*args)
|
|
|
+ self.assertEqual(self.counters.get(*args), 1)
|
|
|
+ self.counters.dec(*args)
|
|
|
+ self.assertEqual(self.counters.get(*args), 0)
|
|
|
# checks disable/enable
|
|
|
- self.counter.disable()
|
|
|
- self.counter.inc(*args)
|
|
|
- self.assertEqual(self.counter.get(*args), 0)
|
|
|
- self.counter.enable()
|
|
|
- self.counter.inc(*args)
|
|
|
- self.assertEqual(self.counter.get(*args), 1)
|
|
|
- self.counter.disable()
|
|
|
- self.counter.dec(*args)
|
|
|
- self.assertEqual(self.counter.get(*args), 1)
|
|
|
- self.counter.enable()
|
|
|
- self.counter.dec(*args)
|
|
|
- self.assertEqual(self.counter.get(*args), 0)
|
|
|
+ self.counters.disable()
|
|
|
+ self.counters.inc(*args)
|
|
|
+ self.assertEqual(self.counters.get(*args), 0)
|
|
|
+ self.counters.enable()
|
|
|
+ self.counters.inc(*args)
|
|
|
+ self.assertEqual(self.counters.get(*args), 1)
|
|
|
+ self.counters.disable()
|
|
|
+ self.counters.dec(*args)
|
|
|
+ self.assertEqual(self.counters.get(*args), 1)
|
|
|
+ self.counters.enable()
|
|
|
+ self.counters.dec(*args)
|
|
|
+ self.assertEqual(self.counters.get(*args), 0)
|
|
|
self._statistics_data[name] = 0
|
|
|
self.check_dump_statistics()
|
|
|
|
|
@@ -238,20 +238,20 @@ class BaseTestCounter():
|
|
|
# for ipsocket/unixsocket counters
|
|
|
_prefix = 'socket/'
|
|
|
_socket_names = \
|
|
|
- isc.config.spec_name_list(self.counter._statistics._spec,
|
|
|
+ isc.config.spec_name_list(self.counters._statistics._spec,
|
|
|
"", True)
|
|
|
for name in _socket_names:
|
|
|
if name.find(_prefix) != 0: continue
|
|
|
args = name.split('/')
|
|
|
- self.counter.inc(*args)
|
|
|
- self.assertEqual(self.counter.get(*args), 1)
|
|
|
+ self.counters.inc(*args)
|
|
|
+ self.assertEqual(self.counters.get(*args), 1)
|
|
|
# checks disable/enable
|
|
|
- self.counter.disable()
|
|
|
- self.counter.inc(*args)
|
|
|
- self.assertEqual(self.counter.get(*args), 1)
|
|
|
- self.counter.enable()
|
|
|
- self.counter.inc(*args)
|
|
|
- self.assertEqual(self.counter.get(*args), 2)
|
|
|
+ self.counters.disable()
|
|
|
+ self.counters.inc(*args)
|
|
|
+ self.assertEqual(self.counters.get(*args), 1)
|
|
|
+ self.counters.enable()
|
|
|
+ self.counters.inc(*args)
|
|
|
+ self.assertEqual(self.counters.get(*args), 2)
|
|
|
isc.cc.data.set(
|
|
|
self._statistics_data, '/'.join(args), 2)
|
|
|
self.check_dump_statistics()
|
|
@@ -260,42 +260,42 @@ class BaseTestCounter():
|
|
|
# test DataNotFoundError raising when specifying item defined
|
|
|
# in the specfile
|
|
|
self.assertRaises(isc.cc.data.DataNotFoundError,
|
|
|
- self.counter.inc, '__undefined__')
|
|
|
+ self.counters.inc, '__undefined__')
|
|
|
self.assertRaises(isc.cc.data.DataNotFoundError,
|
|
|
- self.counter.dec, '__undefined__')
|
|
|
- self.counter.start('__undefined__')
|
|
|
+ self.counters.dec, '__undefined__')
|
|
|
+ self.counters.start('__undefined__')
|
|
|
self.assertRaises(isc.cc.data.DataNotFoundError,
|
|
|
- self.counter.stop, '__undefined__')
|
|
|
+ self.counters.stop, '__undefined__')
|
|
|
self.assertRaises(isc.cc.data.DataNotFoundError,
|
|
|
- self.counter.get, '__undefined__')
|
|
|
+ self.counters.get, '__undefined__')
|
|
|
|
|
|
-class TestCounter0(unittest.TestCase, BaseTestCounter):
|
|
|
+class TestCounters0(unittest.TestCase, BaseTestCounters):
|
|
|
TEST_SPECFILE_LOCATION = None
|
|
|
def setUp(self):
|
|
|
- BaseTestCounter.setUp(self)
|
|
|
+ BaseTestCounters.setUp(self)
|
|
|
def tearDown(self):
|
|
|
- BaseTestCounter.tearDown(self)
|
|
|
+ BaseTestCounters.tearDown(self)
|
|
|
|
|
|
-class TestCounter1(unittest.TestCase, BaseTestCounter):
|
|
|
+class TestCounters1(unittest.TestCase, BaseTestCounters):
|
|
|
TEST_SPECFILE_LOCATION = TESTDATA_SRCDIR + os.sep + 'test_spec1.spec'
|
|
|
def setUp(self):
|
|
|
- BaseTestCounter.setUp(self)
|
|
|
+ BaseTestCounters.setUp(self)
|
|
|
def tearDown(self):
|
|
|
- BaseTestCounter.tearDown(self)
|
|
|
+ BaseTestCounters.tearDown(self)
|
|
|
|
|
|
-class TestCounter2(unittest.TestCase, BaseTestCounter):
|
|
|
+class TestCounters2(unittest.TestCase, BaseTestCounters):
|
|
|
TEST_SPECFILE_LOCATION = TESTDATA_SRCDIR + os.sep + 'test_spec2.spec'
|
|
|
def setUp(self):
|
|
|
- BaseTestCounter.setUp(self)
|
|
|
+ BaseTestCounters.setUp(self)
|
|
|
def tearDown(self):
|
|
|
- BaseTestCounter.tearDown(self)
|
|
|
+ BaseTestCounters.tearDown(self)
|
|
|
|
|
|
-class TestCounter3(unittest.TestCase, BaseTestCounter):
|
|
|
+class TestCounters3(unittest.TestCase, BaseTestCounters):
|
|
|
TEST_SPECFILE_LOCATION = TESTDATA_SRCDIR + os.sep + 'test_spec3.spec'
|
|
|
def setUp(self):
|
|
|
- BaseTestCounter.setUp(self)
|
|
|
+ BaseTestCounters.setUp(self)
|
|
|
def tearDown(self):
|
|
|
- BaseTestCounter.tearDown(self)
|
|
|
+ BaseTestCounters.tearDown(self)
|
|
|
|
|
|
if __name__== "__main__":
|
|
|
unittest.main()
|