Search in sources :

Example 1 with ClientNetworkConfig

use of com.hazelcast.client.config.ClientNetworkConfig in project hazelcast by hazelcast.

the class DummyClientReplicatedMapTest method getClientConfig.

private ClientConfig getClientConfig(HazelcastInstance instance) {
    Address address = instance.getCluster().getLocalMember().getAddress();
    String addressString = address.getHost() + ":" + address.getPort();
    ClientConfig dummyClientConfig = new ClientConfig();
    ClientNetworkConfig networkConfig = new ClientNetworkConfig();
    networkConfig.setSmartRouting(false);
    networkConfig.addAddress(addressString);
    dummyClientConfig.setNetworkConfig(networkConfig);
    return dummyClientConfig;
}
Also used : Address(com.hazelcast.nio.Address) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig)

Example 2 with ClientNetworkConfig

use of com.hazelcast.client.config.ClientNetworkConfig in project hazelcast by hazelcast.

the class ClientDiscoverySpiTest method test_enabled_whenDiscoveryConfigIsEmpty.

@Test
public void test_enabled_whenDiscoveryConfigIsEmpty() {
    ClientConfig config = new ClientConfig();
    config.setProperty(GroupProperty.DISCOVERY_SPI_ENABLED.getName(), "true");
    ClientNetworkConfig networkConfig = config.getNetworkConfig();
    networkConfig.setConnectionAttemptLimit(1);
    networkConfig.setConnectionAttemptPeriod(1);
    try {
        HazelcastClient.newHazelcastClient(config);
    } catch (IllegalStateException expected) {
    // no server available
    }
}
Also used : ClientConfig(com.hazelcast.client.config.ClientConfig) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with ClientNetworkConfig

use of com.hazelcast.client.config.ClientNetworkConfig in project hazelcast by hazelcast.

the class ClientDiscoverySpiTest method testNodeFilter_from_xml.

@Test
public void testNodeFilter_from_xml() throws Exception {
    String xmlFileName = "hazelcast-client-discovery-spi-test.xml";
    InputStream xmlResource = ClientDiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
    ClientConfig clientConfig = new XmlClientConfigBuilder(xmlResource).build();
    ClientNetworkConfig networkConfig = clientConfig.getNetworkConfig();
    DiscoveryConfig discoveryConfig = networkConfig.getDiscoveryConfig();
    DiscoveryServiceProvider provider = new DefaultDiscoveryServiceProvider();
    DiscoveryService discoveryService = provider.newDiscoveryService(buildDiscoveryServiceSettings(discoveryConfig));
    discoveryService.start();
    discoveryService.discoverNodes();
    discoveryService.destroy();
    Field nodeFilterField = DefaultDiscoveryService.class.getDeclaredField("nodeFilter");
    nodeFilterField.setAccessible(true);
    TestNodeFilter nodeFilter = (TestNodeFilter) nodeFilterField.get(discoveryService);
    assertEquals(4, nodeFilter.getNodes().size());
}
Also used : DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) Field(java.lang.reflect.Field) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) InputStream(java.io.InputStream) ClientConfig(com.hazelcast.client.config.ClientConfig) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) DiscoveryService(com.hazelcast.spi.discovery.integration.DiscoveryService) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with ClientNetworkConfig

use of com.hazelcast.client.config.ClientNetworkConfig in project hazelcast by hazelcast.

the class ClientDiscoverySpiTest method test_discovery_address_translator_with_public_ip.

@Test
public void test_discovery_address_translator_with_public_ip() throws Exception {
    String xmlFileName = "hazelcast-client-discovery-spi-test.xml";
    InputStream xmlResource = ClientDiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
    ClientConfig clientConfig = new XmlClientConfigBuilder(xmlResource).build();
    ClientNetworkConfig networkConfig = clientConfig.getNetworkConfig();
    DiscoveryConfig discoveryConfig = networkConfig.getDiscoveryConfig();
    DiscoveryServiceProvider provider = new DefaultDiscoveryServiceProvider();
    DiscoveryService discoveryService = provider.newDiscoveryService(buildDiscoveryServiceSettings(discoveryConfig));
    AddressTranslator translator = new DiscoveryAddressTranslator(discoveryService, true);
    Address publicAddress = new Address("127.0.0.1", 50001);
    Address privateAddress = new Address("127.0.0.1", 1);
    // Enforce refresh of the internal mapping
    assertEquals(publicAddress, translator.translate(privateAddress));
}
Also used : Address(com.hazelcast.nio.Address) InputStream(java.io.InputStream) DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) AddressTranslator(com.hazelcast.client.connection.AddressTranslator) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) ClientConfig(com.hazelcast.client.config.ClientConfig) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) DiscoveryService(com.hazelcast.spi.discovery.integration.DiscoveryService) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with ClientNetworkConfig

use of com.hazelcast.client.config.ClientNetworkConfig in project hazelcast by hazelcast.

the class ClientDiscoverySpiTest method test_CustomDiscoveryService_whenDiscoveredNodes_isNull.

@Test
public void test_CustomDiscoveryService_whenDiscoveredNodes_isNull() {
    ClientConfig config = new ClientConfig();
    config.setProperty(GroupProperty.DISCOVERY_SPI_ENABLED.getName(), "true");
    final DiscoveryService discoveryService = mock(DiscoveryService.class);
    DiscoveryServiceProvider discoveryServiceProvider = new DiscoveryServiceProvider() {

        public DiscoveryService newDiscoveryService(DiscoveryServiceSettings arg0) {
            return discoveryService;
        }
    };
    ClientNetworkConfig networkConfig = config.getNetworkConfig();
    networkConfig.setConnectionAttemptLimit(1);
    networkConfig.setConnectionAttemptPeriod(1);
    networkConfig.getDiscoveryConfig().setDiscoveryServiceProvider(discoveryServiceProvider);
    try {
        HazelcastClient.newHazelcastClient(config);
        fail("Client cannot start, discovery nodes is null!");
    } catch (NullPointerException expected) {
    // discovered nodes is null
    }
    verify(discoveryService).discoverNodes();
}
Also used : DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) ClientConfig(com.hazelcast.client.config.ClientConfig) DiscoveryService(com.hazelcast.spi.discovery.integration.DiscoveryService) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) DiscoveryServiceSettings(com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)18 ClientConfig (com.hazelcast.client.config.ClientConfig)13 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Test (org.junit.Test)9 DefaultDiscoveryServiceProvider (com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider)6 DiscoveryService (com.hazelcast.spi.discovery.integration.DiscoveryService)6 DiscoveryServiceProvider (com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider)6 XmlClientConfigBuilder (com.hazelcast.client.config.XmlClientConfigBuilder)5 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)5 Address (com.hazelcast.nio.Address)5 DefaultDiscoveryService (com.hazelcast.spi.discovery.impl.DefaultDiscoveryService)5 InputStream (java.io.InputStream)4 DiscoveryServiceSettings (com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings)3 ClientAwsConfig (com.hazelcast.client.config.ClientAwsConfig)2 AddressTranslator (com.hazelcast.client.connection.AddressTranslator)2 ILogger (com.hazelcast.logging.ILogger)2 InetSocketAddress (java.net.InetSocketAddress)2 HazelcastClient (com.hazelcast.client.HazelcastClient)1 AddressProvider (com.hazelcast.client.connection.AddressProvider)1 AwsAddressProvider (com.hazelcast.client.spi.impl.AwsAddressProvider)1