Esempio n. 1
0
    def test_with_free_up(self):
        key1 = ("1-ff00:0:300", 1)
        key2 = ("1-ff00:0:301", 1)
        now = int(time.time())
        rev_info1 = self._create_rev_info(key1[0], key1[1], timestamp=now)
        rev_info2 = self._create_rev_info(key2[0], key2[1], timestamp=now + 1)

        def check_active_side_effect(srev_info):
            del rev_cache._cache[(srev_info.rev_info().isd_as(),
                                  srev_info.rev_info().p.ifID)]
            return False

        rev_cache = RevCache(capacity=1)
        rev_cache._cache[key1] = rev_info1
        rev_cache._check_active = create_mock()
        rev_cache._check_active.side_effect = check_active_side_effect
        rev_cache.get = create_mock()
        rev_cache.get.return_value = None
        # Call
        ntools.assert_true(rev_cache.add(rev_info2))
        # Tests
        ntools.eq_(rev_cache._cache[key2], rev_info2)
        ntools.assert_true(key1 not in rev_cache._cache)
        assert_these_calls(rev_info2.rev_info().active, [call()])
        assert_these_calls(rev_cache.get, [call(key2)])
Esempio n. 2
0
 def test_expired_entry(self):
     key = ("1-ff00:0:300", 1)
     default = "default"
     rev_info = "rev_info"
     srev_info = create_mock_full({"rev_info()": rev_info})
     rev_cache = RevCache()
     rev_cache._cache[key] = srev_info
     rev_cache._check_active = create_mock_full(return_value=False)
     # Call
     ntools.eq_(rev_cache.get(key, default=default), default)
     # Tests
     assert_these_calls(rev_cache._check_active, [call(srev_info)])
Esempio n. 3
0
 def test_with_no_free_up(self):
     key1 = ("1-ff00:0:300", 1)
     key2 = ("1-ff00:0:301", 1)
     now = int(time.time())
     rev_info1 = self._create_rev_info(key1[0], key1[1], timestamp=now)
     rev_info2 = self._create_rev_info(key2[0], key2[1], timestamp=now + 1)
     rev_cache = RevCache(capacity=1)
     rev_cache._cache[key1] = rev_info1
     rev_cache._check_active = create_mock_full(return_value=True)
     rev_cache.get = create_mock()
     rev_cache.get.return_value = None
     # Call
     ntools.assert_false(rev_cache.add(rev_info2))
     # Tests
     ntools.assert_true(key1 in rev_cache._cache)
     assert_these_calls(rev_info2.rev_info().active, [call()])
     assert_these_calls(rev_cache.get, [call(key2)])