Exemple #1
0
    def get_seconds(self, property):
        """
        Gets the value of the given property in seconds. If the value of the given property is not a number,
        throws TypeError.

        :param property: (:class:`~hazelcast.config.ClientProperty`), Property to get seconds from
        :return: (float), Value of the given property in seconds
        """
        return TimeUnit.to_seconds(self.get(property), property.time_unit)
Exemple #2
0
    def get_seconds_positive_or_default(self, property):
        """
        Gets the value of the given property in seconds. If the value of the given property is not a number,
        throws TypeError. If the value of the given property in seconds is not positive, tries to
        return the default value in seconds.

        :param property: (:class:`~hazelcast.config.ClientProperty`), Property to get seconds from
        :return: (float), Value of the given property in seconds if it is positive.
            Else, value of the default value of given property in seconds.
        """
        seconds = self.get_seconds(property)
        return seconds if seconds > 0 else TimeUnit.to_seconds(property.default_value, property.time_unit)
Exemple #3
0
 def test_unsupported_types_to_second(self):
     types = ["str", True, None, list(), set(), dict()]
     for type in types:
         with self.assertRaises((TypeError, ValueError)):
             TimeUnit.to_seconds(type, TimeUnit.SECOND)
Exemple #4
0
 def test_numeric_string_to_second(self):
     self.assertEqual(1, TimeUnit.to_seconds("1000", TimeUnit.MILLISECOND))
Exemple #5
0
 def test_hour_to_second(self):
     self.assertEqual(1800, TimeUnit.to_seconds(0.5, TimeUnit.HOUR))
Exemple #6
0
 def test_minute_to_second(self):
     self.assertEqual(60, TimeUnit.to_seconds(1, TimeUnit.MINUTE))
Exemple #7
0
 def test_second_to_second(self):
     self.assertEqual(5.5, TimeUnit.to_seconds(5.5, TimeUnit.SECOND))
Exemple #8
0
 def test_milli_to_second(self):
     self.assertEqual(3, TimeUnit.to_seconds(3e3, TimeUnit.MILLISECOND))
Exemple #9
0
 def test_micro_to_second(self):
     self.assertEqual(2, TimeUnit.to_seconds(2e6, TimeUnit.MICROSECOND))
Exemple #10
0
 def test_nano_to_second(self):
     self.assertEqual(0.1, TimeUnit.to_seconds(0.1e9, TimeUnit.NANOSECOND))