예제 #1
0
    def test_cache_wrap(self):
        # let's say 100 is the threshold
        input = {'disk1': nt(100, 100, 100)}
        wrap_numbers(input, 'disk_io')

        # first wrap restarts from 10
        input = {'disk1': nt(100, 100, 10)}
        wrap_numbers(input, 'disk_io')
        cache = wrap_numbers.cache_info()
        self.assertEqual(cache[0], {'disk_io': input})
        self.assertEqual(
            cache[1],
            {'disk_io': {
                ('disk1', 0): 0,
                ('disk1', 1): 0,
                ('disk1', 2): 100
            }})
        self.assertEqual(cache[2], {'disk_io': {'disk1': set([('disk1', 2)])}})

        def assert_():
            cache = wrap_numbers.cache_info()
            self.assertEqual(cache[1], {
                'disk_io': {
                    ('disk1', 0): 0,
                    ('disk1', 1): 0,
                    ('disk1', 2): 100
                }
            })
            self.assertEqual(cache[2],
                             {'disk_io': {
                                 'disk1': set([('disk1', 2)])
                             }})

        # then it remains the same
        input = {'disk1': nt(100, 100, 10)}
        wrap_numbers(input, 'disk_io')
        cache = wrap_numbers.cache_info()
        self.assertEqual(cache[0], {'disk_io': input})
        assert_()

        # then it goes up
        input = {'disk1': nt(100, 100, 90)}
        wrap_numbers(input, 'disk_io')
        cache = wrap_numbers.cache_info()
        self.assertEqual(cache[0], {'disk_io': input})
        assert_()

        # then it wraps again
        input = {'disk1': nt(100, 100, 20)}
        wrap_numbers(input, 'disk_io')
        cache = wrap_numbers.cache_info()
        self.assertEqual(cache[0], {'disk_io': input})
        self.assertEqual(
            cache[1],
            {'disk_io': {
                ('disk1', 0): 0,
                ('disk1', 1): 0,
                ('disk1', 2): 190
            }})
        self.assertEqual(cache[2], {'disk_io': {'disk1': set([('disk1', 2)])}})
예제 #2
0
 def test_cache_first_call(self):
     input = {'disk1': nt(5, 5, 5)}
     wrap_numbers(input, 'disk_io')
     cache = wrap_numbers.cache_info()
     self.assertEqual(cache[0], {'disk_io': input})
     self.assertEqual(cache[1], {'disk_io': {}})
     self.assertEqual(cache[2], {'disk_io': {}})
예제 #3
0
 def test_cache_first_call(self):
     input = {'disk1': nt(5, 5, 5)}
     wrap_numbers(input, 'disk_io')
     cache = wrap_numbers.cache_info()
     self.assertEqual(cache[0], {'disk_io': input})
     self.assertEqual(cache[1], {'disk_io': {}})
     self.assertEqual(cache[2], {'disk_io': {}})
예제 #4
0
    def test_cache_wrap(self):
        # let's say 100 is the threshold
        input = {'disk1': nt(100, 100, 100)}
        wrap_numbers(input, 'disk_io')

        # first wrap restarts from 10
        input = {'disk1': nt(100, 100, 10)}
        wrap_numbers(input, 'disk_io')
        cache = wrap_numbers.cache_info()
        self.assertEqual(cache[0], {'disk_io': input})
        self.assertEqual(
            cache[1],
            {'disk_io': {('disk1', 0): 0, ('disk1', 1): 0, ('disk1', 2): 100}})
        self.assertEqual(cache[2], {'disk_io': {'disk1': set([('disk1', 2)])}})

        def assert_():
            cache = wrap_numbers.cache_info()
            self.assertEqual(
                cache[1],
                {'disk_io': {('disk1', 0): 0, ('disk1', 1): 0,
                             ('disk1', 2): 100}})
            self.assertEqual(cache[2],
                             {'disk_io': {'disk1': set([('disk1', 2)])}})

        # then it remains the same
        input = {'disk1': nt(100, 100, 10)}
        wrap_numbers(input, 'disk_io')
        cache = wrap_numbers.cache_info()
        self.assertEqual(cache[0], {'disk_io': input})
        assert_()

        # then it goes up
        input = {'disk1': nt(100, 100, 90)}
        wrap_numbers(input, 'disk_io')
        cache = wrap_numbers.cache_info()
        self.assertEqual(cache[0], {'disk_io': input})
        assert_()

        # then it wraps again
        input = {'disk1': nt(100, 100, 20)}
        wrap_numbers(input, 'disk_io')
        cache = wrap_numbers.cache_info()
        self.assertEqual(cache[0], {'disk_io': input})
        self.assertEqual(
            cache[1],
            {'disk_io': {('disk1', 0): 0, ('disk1', 1): 0, ('disk1', 2): 190}})
        self.assertEqual(cache[2], {'disk_io': {'disk1': set([('disk1', 2)])}})
예제 #5
0
    def test_cache_clear_public_apis(self):
        psutil.disk_io_counters()
        psutil.net_io_counters()
        caches = wrap_numbers.cache_info()
        for cache in caches:
            self.assertIn('psutil.disk_io_counters', cache)
            self.assertIn('psutil.net_io_counters', cache)

        psutil.disk_io_counters.cache_clear()
        caches = wrap_numbers.cache_info()
        for cache in caches:
            self.assertIn('psutil.net_io_counters', cache)
            self.assertNotIn('psutil.disk_io_counters', cache)

        psutil.net_io_counters.cache_clear()
        caches = wrap_numbers.cache_info()
        self.assertEqual(caches, ({}, {}, {}))
예제 #6
0
 def test_cache_clear(self):
     input = {'disk1': nt(5, 5, 5)}
     wrap_numbers(input, 'disk_io')
     wrap_numbers(input, 'disk_io')
     wrap_numbers.cache_clear('disk_io')
     self.assertEqual(wrap_numbers.cache_info(), ({}, {}, {}))
     wrap_numbers.cache_clear('disk_io')
     wrap_numbers.cache_clear('?!?')
예제 #7
0
 def assert_():
     cache = wrap_numbers.cache_info()
     self.assertEqual(
         cache[1],
         {'disk_io': {('disk1', 0): 0, ('disk1', 1): 0,
                      ('disk1', 2): 100}})
     self.assertEqual(cache[2],
                      {'disk_io': {'disk1': set([('disk1', 2)])}})
예제 #8
0
    def test_cache_clear_public_apis(self):
        psutil.disk_io_counters()
        psutil.net_io_counters()
        caches = wrap_numbers.cache_info()
        for cache in caches:
            self.assertIn('psutil.disk_io_counters', cache)
            self.assertIn('psutil.net_io_counters', cache)

        psutil.disk_io_counters.cache_clear()
        caches = wrap_numbers.cache_info()
        for cache in caches:
            self.assertIn('psutil.net_io_counters', cache)
            self.assertNotIn('psutil.disk_io_counters', cache)

        psutil.net_io_counters.cache_clear()
        caches = wrap_numbers.cache_info()
        self.assertEqual(caches, ({}, {}, {}))
예제 #9
0
 def test_cache_clear(self):
     input = {'disk1': nt(5, 5, 5)}
     wrap_numbers(input, 'disk_io')
     wrap_numbers(input, 'disk_io')
     wrap_numbers.cache_clear('disk_io')
     self.assertEqual(wrap_numbers.cache_info(), ({}, {}, {}))
     wrap_numbers.cache_clear('disk_io')
     wrap_numbers.cache_clear('?!?')
예제 #10
0
 def assert_():
     cache = wrap_numbers.cache_info()
     self.assertEqual(
         cache[1],
         {'disk_io': {('disk1', 0): 0, ('disk1', 1): 0,
                      ('disk1', 2): 100}})
     self.assertEqual(cache[2],
                      {'disk_io': {'disk1': set([('disk1', 2)])}})
예제 #11
0
    def test_cache_clear_public_apis(self):
        if not psutil.disk_io_counters() or not psutil.net_io_counters():
            return self.skipTest("no disks or NICs available")
        psutil.disk_io_counters()
        psutil.net_io_counters()
        caches = wrap_numbers.cache_info()
        for cache in caches:
            self.assertIn('psutil.disk_io_counters', cache)
            self.assertIn('psutil.net_io_counters', cache)

        psutil.disk_io_counters.cache_clear()
        caches = wrap_numbers.cache_info()
        for cache in caches:
            self.assertIn('psutil.net_io_counters', cache)
            self.assertNotIn('psutil.disk_io_counters', cache)

        psutil.net_io_counters.cache_clear()
        caches = wrap_numbers.cache_info()
        self.assertEqual(caches, ({}, {}, {}))
예제 #12
0
    def test_cache_clear_public_apis(self):
        if not psutil.disk_io_counters() or not psutil.net_io_counters():
            return self.skipTest("no disks or NICs available")
        psutil.disk_io_counters()
        psutil.net_io_counters()
        caches = wrap_numbers.cache_info()
        for cache in caches:
            self.assertIn('psutil.disk_io_counters', cache)
            self.assertIn('psutil.net_io_counters', cache)

        psutil.disk_io_counters.cache_clear()
        caches = wrap_numbers.cache_info()
        for cache in caches:
            self.assertIn('psutil.net_io_counters', cache)
            self.assertNotIn('psutil.disk_io_counters', cache)

        psutil.net_io_counters.cache_clear()
        caches = wrap_numbers.cache_info()
        self.assertEqual(caches, ({}, {}, {}))
예제 #13
0
 def test_cache_call_twice(self):
     input = {'disk1': nt(5, 5, 5)}
     wrap_numbers(input, 'disk_io')
     input = {'disk1': nt(10, 10, 10)}
     wrap_numbers(input, 'disk_io')
     cache = wrap_numbers.cache_info()
     self.assertEqual(cache[0], {'disk_io': input})
     self.assertEqual(
         cache[1],
         {'disk_io': {('disk1', 0): 0, ('disk1', 1): 0, ('disk1', 2): 0}})
     self.assertEqual(cache[2], {'disk_io': {}})
예제 #14
0
 def test_cache_call_twice(self):
     input = {'disk1': nt(5, 5, 5)}
     wrap_numbers(input, 'disk_io')
     input = {'disk1': nt(10, 10, 10)}
     wrap_numbers(input, 'disk_io')
     cache = wrap_numbers.cache_info()
     self.assertEqual(cache[0], {'disk_io': input})
     self.assertEqual(
         cache[1],
         {'disk_io': {('disk1', 0): 0, ('disk1', 1): 0, ('disk1', 2): 0}})
     self.assertEqual(cache[2], {'disk_io': {}})
예제 #15
0
 def test_cache_changing_keys(self):
     input = {'disk1': nt(5, 5, 5)}
     wrap_numbers(input, 'disk_io')
     input = {'disk1': nt(5, 5, 5),
              'disk2': nt(7, 7, 7)}
     wrap_numbers(input, 'disk_io')
     cache = wrap_numbers.cache_info()
     self.assertEqual(cache[0], {'disk_io': input})
     self.assertEqual(
         cache[1],
         {'disk_io': {('disk1', 0): 0, ('disk1', 1): 0, ('disk1', 2): 0}})
     self.assertEqual(cache[2], {'disk_io': {}})
예제 #16
0
 def test_cache_changing_keys(self):
     input = {'disk1': nt(5, 5, 5)}
     wrap_numbers(input, 'disk_io')
     input = {'disk1': nt(5, 5, 5),
              'disk2': nt(7, 7, 7)}
     wrap_numbers(input, 'disk_io')
     cache = wrap_numbers.cache_info()
     self.assertEqual(cache[0], {'disk_io': input})
     self.assertEqual(
         cache[1],
         {'disk_io': {('disk1', 0): 0, ('disk1', 1): 0, ('disk1', 2): 0}})
     self.assertEqual(cache[2], {'disk_io': {}})