예제 #1
0
def create_report_block(first_evict, last_evict, events, log_duration, name):
    """creates the report block for the node"""
    report_block = NodeReportBlock(first_evict, last_evict, name)
    report_block.log_duration = log_duration
    stats = [
        stat for event in events for stat in event.values()
        if stat.duration > 0
    ]
    byte_evictions = [stat for stat in stats if stat.name == "byte"]
    byte_limit = len(byte_evictions)
    item_evicitions = [stat for stat in stats if stat.name == "item"]
    item_limit = len(item_evicitions)
    total_evictions = byte_limit + item_limit
    duration = sum([x.duration for x in stats])
    report_block.avg_evict_freq = (float(report_block.evict_range) /
                                   float(total_evictions)
                                   if report_block.evict_range
                                   and total_evictions else 0.0)
    report_block.avg_evict_duration = (float(duration) /
                                       float(total_evictions) if duration
                                       and total_evictions else 0.0)
    report_block.item_limit = item_limit
    report_block.byte_limit = byte_limit
    report_block.last_item_limit = item_evicitions[
        -1].maximum if item_evicitions else 0
    report_block.last_byte_limit = (humanize.to_bytes(
        byte_evictions[-1].maximum, byte_evictions[-1].maximum_unit)
                                    if byte_evictions else 0)
    return report_block
예제 #2
0
 def test_to_bytes(self):
     """happy path test of all units"""
     self.assertEqual(humanize.to_bytes(2, "bytes"), 2)
     self.assertEqual(humanize.to_bytes(2, "kb"), 2048)
     self.assertEqual(humanize.to_bytes(2, "mb"), 2097152)
     self.assertEqual(humanize.to_bytes(2, "gb"), 2147483648)
     self.assertEqual(humanize.to_bytes(2, "tb"), 2199023255552)
     self.assertEqual(humanize.to_bytes(2, "pb"), 2251799813685248)
     self.assertEqual(humanize.to_bytes(2, "ByTes"), 2)
     self.assertEqual(humanize.to_bytes(2, "KB"), 2048)
     self.assertEqual(humanize.to_bytes(2, "mB"), 2097152)
     self.assertEqual(humanize.to_bytes(2, "GB"), 2147483648)
     self.assertEqual(humanize.to_bytes(2, "tB"), 2199023255552)
     self.assertEqual(humanize.to_bytes(2, "Pb"), 2251799813685248)
예제 #3
0
def test_to_bytes():
    """happy path test of all units"""
    assert humanize.to_bytes(2, "bytes") == 2
    assert humanize.to_bytes(2, "kb") == 2048
    assert humanize.to_bytes(2, "mb") == 2097152
    assert humanize.to_bytes(2, "gb") == 2147483648
    assert humanize.to_bytes(2, "tb") == 2199023255552
    assert humanize.to_bytes(2, "pb") == 2251799813685248
    assert humanize.to_bytes(2, "ByTes") == 2
    assert humanize.to_bytes(2, "KB") == 2048
    assert humanize.to_bytes(2, "mB") == 2097152
    assert humanize.to_bytes(2, "GB") == 2147483648
    assert humanize.to_bytes(2, "tB") == 2199023255552
    assert humanize.to_bytes(2, "Pb") == 2251799813685248