Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 4
0
 def test_numeric_string_to_second(self):
     self.assertEqual(1, TimeUnit.to_seconds("1000", TimeUnit.MILLISECOND))
Esempio n. 5
0
 def test_hour_to_second(self):
     self.assertEqual(1800, TimeUnit.to_seconds(0.5, TimeUnit.HOUR))
Esempio n. 6
0
 def test_minute_to_second(self):
     self.assertEqual(60, TimeUnit.to_seconds(1, TimeUnit.MINUTE))
Esempio n. 7
0
 def test_second_to_second(self):
     self.assertEqual(5.5, TimeUnit.to_seconds(5.5, TimeUnit.SECOND))
Esempio n. 8
0
 def test_milli_to_second(self):
     self.assertEqual(3, TimeUnit.to_seconds(3e3, TimeUnit.MILLISECOND))
Esempio n. 9
0
 def test_micro_to_second(self):
     self.assertEqual(2, TimeUnit.to_seconds(2e6, TimeUnit.MICROSECOND))
Esempio n. 10
0
 def test_nano_to_second(self):
     self.assertEqual(0.1, TimeUnit.to_seconds(0.1e9, TimeUnit.NANOSECOND))