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