Пример #1
0
    def test_get_human_readable(self):
        # Bytes
        for i, raw_bytes in enumerate(self.as_bytes):
            exp_hr = self.bytes_to_hr[i]
            exp_hr2 = self.bytes_to_hr2[i]
            min_suffix = self.min_bytes_suffixes[i]
            hr_value = ConversionUtil.get_human_readable(
                raw_bytes, system=ConversionUtil.DEFAULT_BYTES_SYSTEM)
            hr_value2 = ConversionUtil.get_human_readable2(
                raw_bytes,
                system=ConversionUtil.DEFAULT_BYTES_SYSTEM,
                min_suffix=min_suffix)
            self.assertEqual(hr_value, exp_hr)
            self.assertEqual(hr_value2, exp_hr2)

        # Time
        for i, raw_time in enumerate(self.as_ms):
            exp_hr = self.ms_to_hr[i]
            exp_hr2 = self.ms_to_hr2[i]
            min_suffix = self.min_time_suffixes[i]
            hr_value = ConversionUtil.get_human_readable(
                raw_time, system=ConversionUtil.DEFAULT_TIME_SYSTEM)
            hr_value2 = ConversionUtil.get_human_readable2(
                raw_time,
                system=ConversionUtil.DEFAULT_TIME_SYSTEM,
                min_suffix=min_suffix)
            self.assertEqual(hr_value, exp_hr)
            self.assertEqual(hr_value2, exp_hr2)
Пример #2
0
    def test_get_human_readable_simple(self):
        # Bytes
        for raw_value, exp_value in zip(self.as_bytes_simple,
                                        self.bytes_to_hr_simple):
            value = ConversionUtil.get_human_readable(
                raw_value, system=ConversionUtil.DEFAULT_BYTES_SYSTEM)
            self.assertEqual(value, exp_value)
            value2 = ConversionUtil.get_human_readable2(
                raw_value,
                system=ConversionUtil.DEFAULT_BYTES_SYSTEM,
                min_suffix='B')
            self.assertEqual(value2, exp_value)

        value = ConversionUtil.get_human_readable2(
            44, system=ConversionUtil.DEFAULT_BYTES_SYSTEM, min_suffix='kB')
        self.assertEqual(value, '44B')

        # Time
        for raw_value, exp_value in zip(self.as_ms_simple,
                                        self.ms_to_hr_simple):
            value = ConversionUtil.get_human_readable(
                raw_value, system=ConversionUtil.DEFAULT_TIME_SYSTEM)
            self.assertEqual(value, exp_value)
            value2 = ConversionUtil.get_human_readable2(
                raw_value,
                system=ConversionUtil.DEFAULT_TIME_SYSTEM,
                min_suffix='ms')
            self.assertEqual(value2, exp_value)

        value = ConversionUtil.get_human_readable2(
            44, system=ConversionUtil.DEFAULT_TIME_SYSTEM, min_suffix='s')
        self.assertEqual(value, '44ms')
Пример #3
0
 def format_integer(self, int_value, metadata):
     if metadata.unit != KnobUnitType.OTHER and int_value > 0:
         if metadata.unit == KnobUnitType.BYTES:
             int_value = ConversionUtil.get_human_readable(
                 int_value, ConversionUtil.DEFAULT_BYTES_SYSTEM)
         elif metadata.unit == KnobUnitType.MILLISECONDS:
             int_value = ConversionUtil.get_human_readable(
                 int_value, ConversionUtil.DEFAULT_TIME_SYSTEM)
         else:
             raise Exception('Invalid unit type for {}: {}'.format(
                 metadata.name, metadata.unit))
     else:
         int_value = super().format_integer(int_value, metadata)
     return int_value
Пример #4
0
 def format_integer(self, int_value, metadata):
     if metadata.unit != KnobUnitType.OTHER and int_value > 0:
         if metadata.unit == KnobUnitType.BYTES:
             int_value = ConversionUtil.get_human_readable(
                 int_value, MyRocksParser.MYROCKS_BYTES_SYSTEM)
         elif metadata.unit == KnobUnitType.MILLISECONDS:
             int_value = ConversionUtil.get_human_readable(
                 int_value, MyRocksParser.MYROCKS_TIME_SYSTEM)
         else:
             raise Exception('Invalid unit type for {}: {}'.format(
                 metadata.name, metadata.unit))
     else:
         int_value = super(MyRocksParser, self).format_integer(
             int_value, metadata)
     return int_value
Пример #5
0
    def test_get_human_readable(self):
        # Bytes
        byte_test_convert = [1024**5, 2 * 1024**4, 3 * 1024**3,
                             4 * 1024**2, 5 * 1024**1, 6]
        byte_ans = ['1PB', '2TB', '3GB', '4MB', '5kB', '6B']
        for i, byte_test in enumerate(byte_test_convert):
            byte_readable = ConversionUtil.get_human_readable(
                byte_test, system=PostgresParser.POSTGRES_BYTES_SYSTEM)
            self.assertEqual(byte_readable, byte_ans[i])

        # Time
        day_test_convert = [500, 1000, 55000, 600000, 72000000, 86400000]
        day_ans = ['500ms', '1s', '55s', '10min', '20h', '1d']
        for i, day_test in enumerate(day_test_convert):
            day_readable = ConversionUtil.get_human_readable(
                day_test, system=PostgresParser.POSTGRES_TIME_SYSTEM)
            self.assertEqual(day_readable, day_ans[i])
Пример #6
0
    def test_get_human_readable(self):
        # Bytes
        byte_test_convert = [1024**5, 2 * 1024**4, 3 * 1024**3,
                             4 * 1024**2, 5 * 1024**1, 6]
        byte_ans = ['1PB', '2TB', '3GB', '4MB', '5kB', '6B']
        for i, byte_test in enumerate(byte_test_convert):
            byte_readable = ConversionUtil.get_human_readable(
                byte_test, system=PostgresParser.POSTGRES_BYTES_SYSTEM)
            self.assertEqual(byte_readable, byte_ans[i])

        # Time
        day_test_convert = [500, 1000, 55000, 600000, 72000000, 86400000]
        day_ans = ['500ms', '1s', '55s', '10min', '20h', '1d']
        for i, day_test in enumerate(day_test_convert):
            day_readable = ConversionUtil.get_human_readable(
                day_test, system=PostgresParser.POSTGRES_TIME_SYSTEM)
            self.assertEqual(day_readable, day_ans[i])
Пример #7
0
 def format_integer(self, int_value, metadata):
     int_value = int(round(int_value))
     if metadata.unit != KnobUnitType.OTHER and int_value > 0:
         if metadata.unit == KnobUnitType.BYTES:
             int_value = ConversionUtil.get_human_readable(
                 int_value, PostgresParser.POSTGRES_BYTES_SYSTEM)
         elif metadata.unit == KnobUnitType.MILLISECONDS:
             int_value = ConversionUtil.get_human_readable(
                 int_value, PostgresParser.POSTGRES_TIME_SYSTEM)
         else:
             raise Exception(
                 'Invalid unit type for {}: {}'.format(
                     metadata.name, metadata.unit))
     else:
         int_value = super(PostgresParser, self).format_integer(
             int_value, metadata)
     return int_value