Пример #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 convert_integer(self, int_value, metadata):
        if len(str(int_value)) == 0:
            # The value collected from the database is empty
            return 0
        try:
            try:
                converted = int(int_value)
            except ValueError:
                converted = int(float(int_value))

        except ValueError:
            if metadata.unit == KnobUnitType.BYTES:
                converted = ConversionUtil.get_raw_size(
                    int_value, system=self.bytes_system)
            elif metadata.unit == KnobUnitType.MILLISECONDS:
                converted = ConversionUtil.get_raw_size(
                    int_value, system=self.time_system)
            else:
                # If vartype is OTHER, try to decode it with bytes and time systems
                converted = ConversionUtil.get_raw_size(
                    int_value, system=self.bytes_system)
                if converted is None:
                    converted = ConversionUtil.get_raw_size(
                        int_value, system=self.time_system)
        if converted is None:
            raise Exception('Invalid integer format for {}: {}'.format(
                metadata.name, int_value))
        return converted
Пример #3
0
    def test_get_raw_size(self):
        # Bytes
        for hr_value, exp_value in zip(self.from_hr_bytes, self.as_bytes):
            byte_conversion = ConversionUtil.get_raw_size(
                hr_value, system=ConversionUtil.DEFAULT_BYTES_SYSTEM)
            self.assertEqual(byte_conversion, exp_value)

        # Time
        for hr_value, exp_value in zip(self.from_hr_times, self.as_ms):
            time_conversion = ConversionUtil.get_raw_size(
                hr_value, system=ConversionUtil.DEFAULT_TIME_SYSTEM)
            self.assertEqual(time_conversion, exp_value)
Пример #4
0
    def test_get_raw_size_simple(self):
        # Bytes
        for hr_value, exp_value in zip(self.from_hr_bytes_simple, self.as_bytes_simple):
            value = ConversionUtil.get_raw_size(
                hr_value, system=ConversionUtil.DEFAULT_BYTES_SYSTEM)
            self.assertEqual(value, exp_value)

        # Time
        for hr_value, exp_value in zip(self.from_hr_times_simple, self.as_ms_simple):
            value = ConversionUtil.get_raw_size(
                hr_value, system=ConversionUtil.DEFAULT_TIME_SYSTEM)
            self.assertEqual(value, exp_value)
Пример #5
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
Пример #6
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_readable2(
                    int_value, self.bytes_system, 'kB')
            elif metadata.unit == KnobUnitType.MILLISECONDS:
                int_value = ConversionUtil.get_human_readable2(
                    int_value, self.time_system, 'ms')
            else:
                raise Exception('Invalid unit type for {}: {}'.format(
                    metadata.name, metadata.unit))

        return int_value
Пример #7
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
Пример #8
0
    def test_get_raw_size(self):
        # Bytes - In Bytes
        byte_test_convert = ['1PB', '2TB', '3GB', '4MB', '5kB', '6B']
        byte_ans = [1024**5, 2 * 1024**4, 3 * 1024**3, 4 * 1024**2, 5 * 1024**1, 6]
        for i, byte_test in enumerate(byte_test_convert):
            byte_conversion = ConversionUtil.get_raw_size(
                byte_test, system=PostgresParser.POSTGRES_BYTES_SYSTEM)
            self.assertEqual(byte_conversion, byte_ans[i])

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

        # Time - In Milliseconds
        day_test_convert = ['1000ms', '1s', '10min', '20h', '1d']
        day_ans = [1000, 1000, 600000, 72000000, 86400000]
        for i, day_test in enumerate(day_test_convert):
            day_conversion = ConversionUtil.get_raw_size(
                day_test, system=PostgresParser.POSTGRES_TIME_SYSTEM)
            self.assertEqual(day_conversion, day_ans[i])
Пример #10
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])
Пример #11
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
Пример #12
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])
Пример #13
0
 def convert_integer(self, int_value, metadata):
     converted = None
     try:
         converted = super().convert_integer(int_value, metadata)
     except ValueError:
         if metadata.unit == KnobUnitType.BYTES:
             converted = ConversionUtil.get_raw_size(
                 int_value, system=ConversionUtil.DEFAULT_BYTES_SYSTEM)
         elif metadata.unit == KnobUnitType.MILLISECONDS:
             converted = ConversionUtil.get_raw_size(
                 int_value, system=ConversionUtil.DEFAULT_TIME_SYSTEM)
         else:
             raise Exception('Unknown unit type: {}'.format(metadata.unit))
     if converted is None:
         raise Exception('Invalid integer format for {}: {}'.format(
             metadata.name, int_value))
     return converted
Пример #14
0
 def convert_integer(self, int_value, metadata):
     converted = None
     try:
         converted = super(MyRocksParser, self).convert_integer(
             int_value, metadata)
     except ValueError:
         if metadata.unit == KnobUnitType.BYTES:
             converted = ConversionUtil.get_raw_size(
                 int_value, system=self.MYROCKS_BYTES_SYSTEM)
         elif metadata.unit == KnobUnitType.MILLISECONDS:
             converted = ConversionUtil.get_raw_size(
                 int_value, system=self.MYROCKS_TIME_SYSTEM)
         else:
             raise Exception('Unknown unit type: {}'.format(metadata.unit))
     if converted is None:
         raise Exception('Invalid integer format for {}: {}'.format(
             metadata.name, int_value))
     return converted
Пример #15
0
    def convert_integer(self, int_value, metadata):
        try:
            try:
                converted = int(int_value)
            except ValueError:
                converted = int(float(int_value))

        except ValueError:
            if metadata.unit == KnobUnitType.BYTES:
                converted = ConversionUtil.get_raw_size(
                    int_value, system=self.bytes_system)
            elif metadata.unit == KnobUnitType.MILLISECONDS:
                converted = ConversionUtil.get_raw_size(
                    int_value, system=self.time_system)
            else:
                raise Exception('Unknown unit type: {}'.format(metadata.unit))
        if converted is None:
            raise Exception('Invalid integer format for {}: {}'.format(
                metadata.name, int_value))
        return converted
Пример #16
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')
Пример #17
0
 def format_integer(self, int_value, metadata):
     int_value = int(round(int_value))
     if int_value > 0 and metadata.unit == KnobUnitType.BYTES:
         int_value = ConversionUtil.get_human_readable2(
             int_value, self.bytes_system, self.min_bytes_unit)
     return int_value