def test_load_addresses_with_duplicate_addresses(self): self.network_config.addresses.append("192.168.0.1:5701") self.network_config.addresses.append("192.168.0.1:5701") provider = DefaultAddressProvider(self.network_config) addresses = provider.load_addresses() six.assertCountEqual(self, addresses, [Address("192.168.0.1", 5701), Address("192.168.0.1", 5701)])
def test_load_addresses_without_port(self): initial_list = ["192.168.0.1"] provider = DefaultAddressProvider(initial_list) primaries, secondaries = provider.load_addresses() self.assertCountEqual(primaries, [Address("192.168.0.1", 5701)]) self.assertCountEqual( secondaries, [Address("192.168.0.1", 5702), Address("192.168.0.1", 5703)])
def test_load_addresses_with_empty_addresses(self): initial_list = [] provider = DefaultAddressProvider(initial_list) primaries, secondaries = provider.load_addresses() self.assertCountEqual(primaries, [Address("127.0.0.1", 5701)]) self.assertCountEqual( secondaries, [Address("127.0.0.1", 5702), Address("127.0.0.1", 5703)])
def test_load_addresses_with_duplicate_addresses(self): initial_list = ["192.168.0.1:5701", "192.168.0.1:5701"] provider = DefaultAddressProvider(initial_list) primaries, secondaries = provider.load_addresses() self.assertCountEqual( primaries, [Address("192.168.0.1", 5701), Address("192.168.0.1", 5701)]) self.assertCountEqual(secondaries, [])
def test_multiple_providers_with_empty_network_config_addresses(self): default_address_provider = DefaultAddressProvider(self.network_config) providers = [default_address_provider, self.cloud_address_provider] provider_addresses = get_provider_addresses(providers) six.assertCountEqual(self, provider_addresses, [Address("10.0.0.1", 5701)]) addresses = get_possible_addresses(provider_addresses) six.assertCountEqual(self, addresses, [Address("10.0.0.1", 5701)])
def _create_address_providers(self): network_config = self.config.network_config address_providers = [] cloud_config = network_config.cloud_config cloud_address_provider = self._init_cloud_address_provider(cloud_config) if cloud_address_provider: address_providers.append(cloud_address_provider) address_providers.append(DefaultAddressProvider(network_config)) return address_providers
def test_load_addresses_with_multiple_addresses(self): initial_list = [ "192.168.0.1:5701", "192.168.0.1:5702", "192.168.0.2:5701" ] provider = DefaultAddressProvider(initial_list) primaries, secondaries = provider.load_addresses() six.assertCountEqual(self, primaries, [ Address("192.168.0.1", 5701), Address("192.168.0.1", 5702), Address("192.168.0.2", 5701) ]) six.assertCountEqual(self, secondaries, [])
def test_multiple_providers_with_empty_load_addresses(self): default_address_provider = DefaultAddressProvider(self.network_config) self.cloud_address_provider.load_addresses = lambda: [] providers = [default_address_provider, self.cloud_address_provider] provider_addresses = get_provider_addresses(providers) six.assertCountEqual(self, provider_addresses, []) addresses = get_possible_addresses(provider_addresses) six.assertCountEqual(self, addresses, [ Address("127.0.0.1", 5701), Address("127.0.0.1", 5702), Address("127.0.0.1", 5703) ])
def _create_address_provider(self): network_config = self.config.network address_list_provided = len(network_config.addresses) != 0 cloud_config = network_config.cloud cloud_enabled = cloud_config.enabled or cloud_config.discovery_token != "" if address_list_provided and cloud_enabled: raise IllegalStateError( "Only one discovery method can be enabled at a time. " "Cluster members given explicitly: %s, Hazelcast Cloud enabled: %s" % (address_list_provided, cloud_enabled)) cloud_address_provider = self._init_cloud_address_provider( cloud_config) if cloud_address_provider: return cloud_address_provider return DefaultAddressProvider(network_config.addresses)
def _create_address_provider(self): config = self._config cluster_members = config.cluster_members address_list_provided = len(cluster_members) > 0 cloud_discovery_token = config.cloud_discovery_token cloud_enabled = cloud_discovery_token is not None if address_list_provided and cloud_enabled: raise IllegalStateError( "Only one discovery method can be enabled at a time. " "Cluster members given explicitly: %s, Hazelcast Cloud enabled: %s" % (address_list_provided, cloud_enabled)) if cloud_enabled: connection_timeout = self._get_connection_timeout(config) return HazelcastCloudAddressProvider(cloud_discovery_token, connection_timeout) return DefaultAddressProvider(cluster_members)
def test_multiple_providers_with_duplicate_network_config_addresses(self): self.network_config.addresses.append("127.0.0.1:5701") self.network_config.addresses.append("127.0.0.1:5701") default_address_provider = DefaultAddressProvider(self.network_config) providers = [default_address_provider, self.cloud_address_provider] provider_addresses = get_provider_addresses(providers) six.assertCountEqual(self, provider_addresses, [ Address("10.0.0.1", 5701), Address("127.0.0.1", 5701), Address("127.0.0.1", 5701) ]) addresses = get_possible_addresses(provider_addresses) six.assertCountEqual( self, addresses, [Address("10.0.0.1", 5701), Address("127.0.0.1", 5701)])
def setUp(self): self.network_config = ClientNetworkConfig() self.address_provider = DefaultAddressProvider(self.network_config)
def test_translate_none(self): provider = DefaultAddressProvider([]) actual = provider.translate(None) self.assertIsNone(actual)
def test_translate(self): provider = DefaultAddressProvider([]) address = Address("192.168.0.1", 5701) actual = provider.translate(address) self.assertEqual(address, actual)
def test_load_addresses_with_empty_addresses(self): provider = DefaultAddressProvider(self.network_config) addresses = provider.load_addresses() six.assertCountEqual(self, addresses, [])