Search in sources :

Example 6 with DiscoveryServiceSettings

use of com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings in project hazelcast by hazelcast.

the class ClientDiscoverySpiTest method test_CustomDiscoveryService_whenDiscoveredNodes_isEmpty.

@Test
public void test_CustomDiscoveryService_whenDiscoveredNodes_isEmpty() {
    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) {
            when(discoveryService.discoverNodes()).thenReturn(Collections.<DiscoveryNode>emptyList());
            return discoveryService;
        }
    };
    ClientNetworkConfig networkConfig = config.getNetworkConfig();
    networkConfig.setConnectionAttemptLimit(1);
    networkConfig.setConnectionAttemptPeriod(1);
    networkConfig.getDiscoveryConfig().setDiscoveryServiceProvider(discoveryServiceProvider);
    try {
        HazelcastClient.newHazelcastClient(config);
    } catch (IllegalStateException expected) {
    // no server available
    }
    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)

Example 7 with DiscoveryServiceSettings

use of com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings in project hazelcast by hazelcast.

the class HazelcastClientInstanceImpl method initDiscoveryService.

private DiscoveryService initDiscoveryService(ClientConfig config) {
    // and strategies are resolved but the AddressProvider is never registered
    if (!properties.getBoolean(ClientProperty.DISCOVERY_SPI_ENABLED)) {
        return null;
    }
    ILogger logger = loggingService.getLogger(DiscoveryService.class);
    ClientNetworkConfig networkConfig = config.getNetworkConfig();
    DiscoveryConfig discoveryConfig = networkConfig.getDiscoveryConfig().getAsReadOnly();
    DiscoveryServiceProvider factory = discoveryConfig.getDiscoveryServiceProvider();
    if (factory == null) {
        factory = new DefaultDiscoveryServiceProvider();
    }
    DiscoveryServiceSettings settings = new DiscoveryServiceSettings().setConfigClassLoader(config.getClassLoader()).setLogger(logger).setDiscoveryMode(DiscoveryMode.Client).setDiscoveryConfig(discoveryConfig);
    DiscoveryService discoveryService = factory.newDiscoveryService(settings);
    discoveryService.start();
    return discoveryService;
}
Also used : DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) ILogger(com.hazelcast.logging.ILogger) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) DiscoveryService(com.hazelcast.spi.discovery.integration.DiscoveryService) DiscoveryServiceSettings(com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig)

Aggregations

DefaultDiscoveryServiceProvider (com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider)7 DiscoveryServiceProvider (com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider)7 DiscoveryServiceSettings (com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings)7 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)5 DiscoveryService (com.hazelcast.spi.discovery.integration.DiscoveryService)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 JoinConfig (com.hazelcast.config.JoinConfig)4 DefaultDiscoveryService (com.hazelcast.spi.discovery.impl.DefaultDiscoveryService)4 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)3 AwsConfig (com.hazelcast.config.AwsConfig)3 Config (com.hazelcast.config.Config)3 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)3 InterfacesConfig (com.hazelcast.config.InterfacesConfig)3 MulticastConfig (com.hazelcast.config.MulticastConfig)3 TcpIpConfig (com.hazelcast.config.TcpIpConfig)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 ILogger (com.hazelcast.logging.ILogger)2 XmlConfigBuilder (com.hazelcast.config.XmlConfigBuilder)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1