Parcourir la source

[2225_statistics] rename the class to the plural form (`Counters`) as it manages multiple counters

Due to the review comment.
Naoki Kambe il y a 12 ans
Parent
commit
2b861742dc

+ 10 - 10
src/lib/python/isc/statistics/counter.py

@@ -13,17 +13,17 @@
 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
-"""BIND 10 Statistics counter module
+"""BIND 10 Statistics counters module
 
 This module handles the statistics counters for BIND 10 modules.  For
 using the module `counter.py`, firstly the init() method should be
 invoked in each module like b10-xfrin or b10-xfrout after importing
 this module.
 
-  from isc.statistics import Counter
-  self.counter = Counter(/path/to/foo.spec)
+  from isc.statistics import Counters
+  self.counters = Counters(/path/to/foo.spec)
 
-The first argument of Counter() can be specified, which is the
+The first argument of Counters() can be specified, which is the
 location of the specification file like src/bin/xfrout/xfrout.spec. If
 this initial preparation is done, statistics counters can be accessed
 from each module. For example, in case that the item `xfrreqdone` is
@@ -31,13 +31,13 @@ defined in statistics_spec in xfrout.spec, the following methods is
 callable. Since these methods requires the string of the zone name in
 the first argument, in the b10-xfrout,
 
-  self.counter.inc('zones', zone_name, 'xfrreqdone')
+  self.counters.inc('zones', zone_name, 'xfrreqdone')
 
 then the counter for xfrreqdone corresponding to zone_name was
 incremented. For getting the current number of this counter, we can do
 this,
 
-  number = self.counter.get('zones', zone_name, 'xfrreqdone')
+  number = self.counters.get('zones', zone_name, 'xfrreqdone')
 
 then the current number was obtained and set in the above variable
 `number`. Such a getter method would be mainly used for unittesting.
@@ -46,7 +46,7 @@ method is also callable.  This method is used for decrementing the
 counter number.  Regarding the item `axfr_running`, an argument like
 zone name is not required.
 
-  self.counter.dec('axfr_running')
+  self.counters.dec('axfr_running')
 
 These methods are effective in other module. For example, in case
 that this module `counter.py` is once imported in such a main module
@@ -54,7 +54,7 @@ as b10-xfrout, Regarding the item `notifyoutv4`, the incrementer
 as the following can be invoked via other module like notify_out.py,
 which is firstly imported in the main module.
 
-  self.counter.inc('zones', zone_name, 'notifyoutv4')
+  self.counters.inc('zones', zone_name, 'notifyoutv4')
 
 In this example this is for incrementing the counter of the item
 notifyoutv4. Thus, such statement can be also written in the other
@@ -139,7 +139,7 @@ class _Statistics():
     # default statistics data
     _data = {}
     # default statistics spec used in case of the specfile omitted in
-    # Counter()
+    # Counters()
     _spec = [
       {
         "item_name": "zones",
@@ -182,7 +182,7 @@ class _Statistics():
       }
     ]
 
-class Counter():
+class Counters():
     """A module for holding all statistics counters of modules. The
     counter numbers can be accessed by the accesseers defined
     according to a spec file. In this class, the structure of per-zone

+ 83 - 83
src/lib/python/isc/statistics/tests/counter_test.py

@@ -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()