Search in sources :

Example 1 with DiscoveryServiceSettings

use of com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings 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)

Example 2 with DiscoveryServiceSettings

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

the class Node method createDiscoveryService.

private DiscoveryService createDiscoveryService(Config config) {
    JoinConfig joinConfig = config.getNetworkConfig().getJoin();
    DiscoveryConfig discoveryConfig = joinConfig.getDiscoveryConfig().getAsReadOnly();
    DiscoveryServiceProvider factory = discoveryConfig.getDiscoveryServiceProvider();
    if (factory == null) {
        factory = new DefaultDiscoveryServiceProvider();
    }
    ILogger logger = getLogger(DiscoveryService.class);
    DiscoveryServiceSettings settings = new DiscoveryServiceSettings().setConfigClassLoader(configClassLoader).setLogger(logger).setDiscoveryMode(DiscoveryMode.Member).setDiscoveryConfig(discoveryConfig).setDiscoveryNode(new SimpleDiscoveryNode(localMember.getAddress(), localMember.getAttributes()));
    return factory.newDiscoveryService(settings);
}
Also used : DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) JoinConfig(com.hazelcast.config.JoinConfig) SimpleDiscoveryNode(com.hazelcast.spi.discovery.SimpleDiscoveryNode) ILogger(com.hazelcast.logging.ILogger) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) DiscoveryServiceSettings(com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings)

Example 3 with DiscoveryServiceSettings

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

the class DiscoverySpiTest method testCustomDiscoveryService_whenDiscoveredNodes_isNull.

@Test
public void testCustomDiscoveryService_whenDiscoveredNodes_isNull() {
    Config config = new Config();
    config.setProperty(GroupProperty.DISCOVERY_SPI_ENABLED.getName(), "true");
    DiscoveryServiceProvider discoveryServiceProvider = new DiscoveryServiceProvider() {

        public DiscoveryService newDiscoveryService(DiscoveryServiceSettings arg0) {
            return mock(DiscoveryService.class);
        }
    };
    config.getNetworkConfig().getJoin().getDiscoveryConfig().setDiscoveryServiceProvider(discoveryServiceProvider);
    try {
        Hazelcast.newHazelcastInstance(config);
        fail("Instance should not be started!");
    } catch (IllegalStateException expected) {
    }
}
Also used : DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) AwsConfig(com.hazelcast.config.AwsConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) DiscoveryServiceSettings(com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with DiscoveryServiceSettings

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

the class DiscoverySpiTest method testNodeFilter_from_xml.

@Test
public void testNodeFilter_from_xml() throws Exception {
    String xmlFileName = "test-hazelcast-discovery-spi.xml";
    InputStream xmlResource = DiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
    Config config = new XmlConfigBuilder(xmlResource).build();
    JoinConfig joinConfig = config.getNetworkConfig().getJoin();
    DiscoveryConfig discoveryConfig = joinConfig.getDiscoveryConfig();
    Address address = new Address("localhost", 5701);
    DiscoveryServiceSettings settings = buildDiscoveryServiceSettings(address, discoveryConfig, DiscoveryMode.Client);
    DiscoveryServiceProvider provider = new DefaultDiscoveryServiceProvider();
    DiscoveryService discoveryService = provider.newDiscoveryService(settings);
    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 : XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) InputStream(java.io.InputStream) AwsConfig(com.hazelcast.config.AwsConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) DiscoveryServiceSettings(com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings) 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) JoinConfig(com.hazelcast.config.JoinConfig) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) DiscoveryService(com.hazelcast.spi.discovery.integration.DiscoveryService) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with DiscoveryServiceSettings

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

the class DiscoverySpiTest method testCustomDiscoveryService_whenDiscoveredNodes_isEmpty.

@Test
public void testCustomDiscoveryService_whenDiscoveredNodes_isEmpty() {
    Config config = new Config();
    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;
        }
    };
    config.getNetworkConfig().getJoin().getDiscoveryConfig().setDiscoveryServiceProvider(discoveryServiceProvider);
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
    try {
        verify(discoveryService).discoverNodes();
    } finally {
        instance.getLifecycleService().terminate();
    }
}
Also used : DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AwsConfig(com.hazelcast.config.AwsConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) DiscoveryService(com.hazelcast.spi.discovery.integration.DiscoveryService) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) DiscoveryServiceSettings(com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

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