Search in sources :

Example 6 with Addresses

use of com.hazelcast.client.impl.connection.Addresses in project hazelcast by hazelcast.

the class DefaultAddressProviderTest method whenExplicitNoPortAddress.

@Test
public void whenExplicitNoPortAddress() throws UnknownHostException {
    ClientNetworkConfig config = new ClientNetworkConfig();
    config.addAddress("10.0.0.1");
    DefaultAddressProvider provider = new DefaultAddressProvider(config);
    Addresses addresses = provider.loadAddresses();
    assertPrimary(addresses, new Address("10.0.0.1", 5701));
    assertSecondary(addresses, new Address("10.0.0.1", 5702), new Address("10.0.0.1", 5703));
}
Also used : Addresses(com.hazelcast.client.impl.connection.Addresses) Address(com.hazelcast.cluster.Address) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with Addresses

use of com.hazelcast.client.impl.connection.Addresses in project hazelcast by hazelcast.

the class DefaultAddressProviderTest method whenNoAddresses.

@Test
public void whenNoAddresses() throws UnknownHostException {
    ClientNetworkConfig config = new ClientNetworkConfig();
    DefaultAddressProvider provider = new DefaultAddressProvider(config);
    Addresses addresses = provider.loadAddresses();
    assertPrimary(addresses, new Address("127.0.0.1", 5701));
    assertSecondary(addresses, new Address("127.0.0.1", 5702), new Address("127.0.0.1", 5703));
}
Also used : Addresses(com.hazelcast.client.impl.connection.Addresses) Address(com.hazelcast.cluster.Address) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with Addresses

use of com.hazelcast.client.impl.connection.Addresses in project hazelcast by hazelcast.

the class DefaultAddressProviderTest method whenBogusAddress.

@Test
public void whenBogusAddress() {
    ClientNetworkConfig config = new ClientNetworkConfig();
    config.addAddress(UUID.randomUUID().toString());
    DefaultAddressProvider provider = new DefaultAddressProvider(config);
    Addresses addresses = provider.loadAddresses();
    assertPrimaryEmpty(addresses);
    assertSecondaryEmpty(addresses);
}
Also used : Addresses(com.hazelcast.client.impl.connection.Addresses) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with Addresses

use of com.hazelcast.client.impl.connection.Addresses in project hazelcast by hazelcast.

the class TestHazelcastFactory method createAddressProvider.

private AddressProvider createAddressProvider(ClientConfig config) {
    boolean discoveryEnabled = new HazelcastProperties(config.getProperties()).getBoolean(ClientProperty.DISCOVERY_SPI_ENABLED);
    List<DiscoveryStrategyConfig> aliasedDiscoveryConfigs = ClientAliasedDiscoveryConfigUtils.createDiscoveryStrategyConfigs(config);
    List<String> userConfiguredAddresses = config.getNetworkConfig().getAddresses();
    boolean isAtLeastAProviderConfigured = discoveryEnabled || !aliasedDiscoveryConfigs.isEmpty() || !userConfiguredAddresses.isEmpty();
    if (isAtLeastAProviderConfigured) {
        // address providers or addresses are configured explicitly, don't add more addresses
        return null;
    }
    return new AddressProvider() {

        @Override
        public Addresses loadAddresses() {
            Addresses possibleAddresses = new Addresses();
            for (Address address : getKnownAddresses()) {
                Addresses addresses = AddressHelper.getPossibleSocketAddresses(address.getPort(), address.getHost(), 1);
                possibleAddresses.addAll(addresses);
            }
            return possibleAddresses;
        }

        @Override
        public Address translate(Address address) {
            return address;
        }
    };
}
Also used : Addresses(com.hazelcast.client.impl.connection.Addresses) HazelcastProperties(com.hazelcast.spi.properties.HazelcastProperties) AddressProvider(com.hazelcast.client.impl.connection.AddressProvider) Address(com.hazelcast.cluster.Address) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig)

Aggregations

Addresses (com.hazelcast.client.impl.connection.Addresses)9 Address (com.hazelcast.cluster.Address)6 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 AuthenticationException (com.hazelcast.client.AuthenticationException)1 ClientNotAllowedInClusterException (com.hazelcast.client.ClientNotAllowedInClusterException)1 HazelcastClientNotActiveException (com.hazelcast.client.HazelcastClientNotActiveException)1 HazelcastClientOfflineException (com.hazelcast.client.HazelcastClientOfflineException)1 AddressProvider (com.hazelcast.client.impl.connection.AddressProvider)1 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)1 InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)1 HazelcastException (com.hazelcast.core.HazelcastException)1 TargetDisconnectedException (com.hazelcast.spi.exception.TargetDisconnectedException)1 HazelcastProperties (com.hazelcast.spi.properties.HazelcastProperties)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1