コード例 #1
0
    def _create_address_translator(self):
        network_config = self.config.network_config
        cloud_config = network_config.cloud_config
        cloud_discovery_token = self.properties.get(
            self.properties.HAZELCAST_CLOUD_DISCOVERY_TOKEN)

        address_list_provided = len(network_config.addresses) != 0
        if cloud_discovery_token != "" and cloud_config.enabled:
            raise HazelcastIllegalStateError(
                "Ambiguous Hazelcast.cloud configuration. "
                "Both property based and client configuration based settings are provided "
                "for Hazelcast cloud discovery together. Use only one.")

        hazelcast_cloud_enabled = cloud_discovery_token != "" or cloud_config.enabled
        self._is_discovery_configuration_consistent(address_list_provided,
                                                    hazelcast_cloud_enabled)

        if hazelcast_cloud_enabled:
            if cloud_config.enabled:
                discovery_token = cloud_config.discovery_token
            else:
                discovery_token = cloud_discovery_token
            host, url = HazelcastCloudDiscovery.get_host_and_url(
                self.config.get_properties(), discovery_token)
            return HazelcastCloudAddressTranslator(
                host, url, self._get_connection_timeout(), self._logger_extras)

        return DefaultAddressTranslator()
class DefaultAddressTranslatorTest(TestCase):
    def setUp(self):
        self.translator = DefaultAddressTranslator()
        self.address = Address("192.168.0.1", 5701)

    def test_translate(self):
        actual = self.translator.translate(self.address)

        self.assertEqual(self.address, actual)

    def test_translate_none(self):
        actual = self.translator.translate(None)

        self.assertIsNone(actual)

    def test_refresh_and_translate(self):
        self.translator.refresh()
        actual = self.translator.translate(self.address)

        self.assertEqual(self.address, actual)
 def setUp(self):
     self.translator = DefaultAddressTranslator()
     self.address = Address("192.168.0.1", 5701)