def test_per_content(self): view = type('MockNetworkView', (), {})() c = collectors.CacheHitRatioCollector(view, content_hits=True) c.start_session(3.0, 'RECV', 1) c.cache_hit(1) c.end_session() c.start_session(4.0, 'RECV', 1) c.server_hit(2) c.end_session() c.start_session(5.0, 'RECV', 2) c.cache_hit(3) c.end_session() c.start_session(6.0, 'RECV', 2) c.server_hit(4) c.end_session() c.start_session(7.0, 'RECV', 2) c.server_hit(5) c.end_session() c.start_session(8.0, 'RECV', 2) c.server_hit(5) c.end_session() res = c.results() self.assertEqual({1: 0.5, 2: 0.25}, res['PER_CONTENT'])
def test_per_node(self): view = type('MockNetworkView', (), {})() c = collectors.CacheHitRatioCollector(view, per_node=True) c.start_session(3.0, 1, 'CONTENT') c.cache_hit(1) c.end_session() c.start_session(4.0, 1, 'CONTENT') c.cache_hit(1) c.end_session() c.start_session(5.0, 1, 'CONTENT') c.cache_hit(2) c.end_session() c.start_session(6.0, 1, 'CONTENT') c.cache_hit(3) c.end_session() c.start_session(7.0, 1, 'CONTENT') c.server_hit(4) c.end_session() res = c.results() self.assertEqual({ 1: 0.4, 2: 0.2, 3: 0.2 }, res['PER_NODE_CACHE_HIT_RATIO']) self.assertEqual({4: 0.2}, res['PER_NODE_SERVER_HIT_RATIO'])
def test_per_content(self): view = type("MockNetworkView", (), {})() c = collectors.CacheHitRatioCollector(view, content_hits=True) c.start_session(3.0, "RECV", 1) c.cache_hit(1) c.end_session() c.start_session(4.0, "RECV", 1) c.server_hit(2) c.end_session() c.start_session(5.0, "RECV", 2) c.cache_hit(3) c.end_session() c.start_session(6.0, "RECV", 2) c.server_hit(4) c.end_session() c.start_session(7.0, "RECV", 2) c.server_hit(5) c.end_session() c.start_session(8.0, "RECV", 2) c.server_hit(5) c.end_session() res = c.results() assert {1: 0.5, 2: 0.25} == res["PER_CONTENT"]
def test_per_node(self): view = type("MockNetworkView", (), {})() c = collectors.CacheHitRatioCollector(view, per_node=True) c.start_session(3.0, 1, "CONTENT") c.cache_hit(1) c.end_session() c.start_session(4.0, 1, "CONTENT") c.cache_hit(1) c.end_session() c.start_session(5.0, 1, "CONTENT") c.cache_hit(2) c.end_session() c.start_session(6.0, 1, "CONTENT") c.cache_hit(3) c.end_session() c.start_session(7.0, 1, "CONTENT") c.server_hit(4) c.end_session() res = c.results() assert {1: 0.4, 2: 0.2, 3: 0.2} == res["PER_NODE_CACHE_HIT_RATIO"] assert {4: 0.2} == res["PER_NODE_SERVER_HIT_RATIO"]
def test_base(self): view = type('MockNetworkView', (), {})() c = collectors.CacheHitRatioCollector(view) c.start_session(3.0, 1, 'CONTENT') c.cache_hit(1) c.end_session() c.start_session(4.0, 1, 'CONTENT') c.server_hit(2) c.end_session() res = c.results() self.assertEqual(0.5, res['MEAN'])
def test_base(self): view = type("MockNetworkView", (), {})() c = collectors.CacheHitRatioCollector(view) c.start_session(3.0, 1, "CONTENT") c.cache_hit(1) c.end_session() c.start_session(4.0, 1, "CONTENT") c.server_hit(2) c.end_session() res = c.results() assert 0.5 == res["MEAN"]