Search in sources :

Example 11 with DiscoveryService

use of com.hazelcast.spi.discovery.integration.DiscoveryService 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(ClusterProperty.DISCOVERY_SPI_ENABLED.getName(), "true");
    final DiscoveryService discoveryService = mock(DiscoveryService.class);
    when(discoveryService.discoverNodes()).thenReturn(Collections.emptyList());
    DiscoveryServiceProvider discoveryServiceProvider = arg0 -> discoveryService;
    ClientNetworkConfig networkConfig = config.getNetworkConfig();
    config.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(0);
    networkConfig.getDiscoveryConfig().addDiscoveryStrategyConfig(new DiscoveryStrategyConfig());
    networkConfig.getDiscoveryConfig().setDiscoveryServiceProvider(discoveryServiceProvider);
    try {
        HazelcastClient.newHazelcastClient(config);
    } catch (IllegalStateException expected) {
    // no server available
    }
    verify(discoveryService, new AtLeast(1)).discoverNodes();
}
Also used : DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) Address(com.hazelcast.cluster.Address) QuickTest(com.hazelcast.test.annotation.QuickTest) URL(java.net.URL) DiscoveryStrategy(com.hazelcast.spi.discovery.DiscoveryStrategy) AtLeast(org.mockito.internal.verification.AtLeast) SimplePropertyDefinition(com.hazelcast.config.properties.SimplePropertyDefinition) After(org.junit.After) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) Logger(com.hazelcast.logging.Logger) DiscoveryStrategyFactory(com.hazelcast.spi.discovery.DiscoveryStrategyFactory) DiscoveryService(com.hazelcast.spi.discovery.integration.DiscoveryService) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) Collection(java.util.Collection) Category(org.junit.experimental.categories.Category) ClusterProperty(com.hazelcast.spi.properties.ClusterProperty) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Hazelcast(com.hazelcast.core.Hazelcast) NodeFilter(com.hazelcast.spi.discovery.NodeFilter) DiscoveryMode(com.hazelcast.spi.discovery.integration.DiscoveryMode) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Mockito.mock(org.mockito.Mockito.mock) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) HazelcastClient(com.hazelcast.client.HazelcastClient) PartitionGroupStrategy(com.hazelcast.spi.partitiongroup.PartitionGroupStrategy) StreamSource(javax.xml.transform.stream.StreamSource) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Source(javax.xml.transform.Source) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) Schema(javax.xml.validation.Schema) ArrayList(java.util.ArrayList) JoinConfig(com.hazelcast.config.JoinConfig) PropertyDefinition(com.hazelcast.config.properties.PropertyDefinition) ILogger(com.hazelcast.logging.ILogger) DiscoveryNode(com.hazelcast.spi.discovery.DiscoveryNode) ClientClasspathXmlConfig(com.hazelcast.client.config.ClientClasspathXmlConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) XMLConstants(javax.xml.XMLConstants) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SchemaFactory(javax.xml.validation.SchemaFactory) PropertyTypeConverter(com.hazelcast.config.properties.PropertyTypeConverter) DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) Test(org.junit.Test) Validator(javax.xml.validation.Validator) SimpleDiscoveryNode(com.hazelcast.spi.discovery.SimpleDiscoveryNode) SlowTest(com.hazelcast.test.annotation.SlowTest) Mockito.when(org.mockito.Mockito.when) Field(java.lang.reflect.Field) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) Mockito.verify(org.mockito.Mockito.verify) AbstractDiscoveryStrategy(com.hazelcast.spi.discovery.AbstractDiscoveryStrategy) DiscoveryServiceSettings(com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings) InterfacesConfig(com.hazelcast.config.InterfacesConfig) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) AtLeast(org.mockito.internal.verification.AtLeast) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) 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) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 12 with DiscoveryService

use of com.hazelcast.spi.discovery.integration.DiscoveryService 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(ClusterProperty.DISCOVERY_SPI_ENABLED.getName(), "true");
    final DiscoveryService discoveryService = mock(DiscoveryService.class);
    when(discoveryService.discoverNodes()).thenReturn(null);
    DiscoveryServiceProvider discoveryServiceProvider = arg0 -> discoveryService;
    ClientNetworkConfig networkConfig = config.getNetworkConfig();
    config.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(2000);
    networkConfig.getDiscoveryConfig().addDiscoveryStrategyConfig(new DiscoveryStrategyConfig());
    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) Address(com.hazelcast.cluster.Address) QuickTest(com.hazelcast.test.annotation.QuickTest) URL(java.net.URL) DiscoveryStrategy(com.hazelcast.spi.discovery.DiscoveryStrategy) AtLeast(org.mockito.internal.verification.AtLeast) SimplePropertyDefinition(com.hazelcast.config.properties.SimplePropertyDefinition) After(org.junit.After) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) Logger(com.hazelcast.logging.Logger) DiscoveryStrategyFactory(com.hazelcast.spi.discovery.DiscoveryStrategyFactory) DiscoveryService(com.hazelcast.spi.discovery.integration.DiscoveryService) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) Collection(java.util.Collection) Category(org.junit.experimental.categories.Category) ClusterProperty(com.hazelcast.spi.properties.ClusterProperty) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Hazelcast(com.hazelcast.core.Hazelcast) NodeFilter(com.hazelcast.spi.discovery.NodeFilter) DiscoveryMode(com.hazelcast.spi.discovery.integration.DiscoveryMode) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Mockito.mock(org.mockito.Mockito.mock) DefaultDiscoveryService(com.hazelcast.spi.discovery.impl.DefaultDiscoveryService) HazelcastClient(com.hazelcast.client.HazelcastClient) PartitionGroupStrategy(com.hazelcast.spi.partitiongroup.PartitionGroupStrategy) StreamSource(javax.xml.transform.stream.StreamSource) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Source(javax.xml.transform.Source) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) Schema(javax.xml.validation.Schema) ArrayList(java.util.ArrayList) JoinConfig(com.hazelcast.config.JoinConfig) PropertyDefinition(com.hazelcast.config.properties.PropertyDefinition) ILogger(com.hazelcast.logging.ILogger) DiscoveryNode(com.hazelcast.spi.discovery.DiscoveryNode) ClientClasspathXmlConfig(com.hazelcast.client.config.ClientClasspathXmlConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) XMLConstants(javax.xml.XMLConstants) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SchemaFactory(javax.xml.validation.SchemaFactory) PropertyTypeConverter(com.hazelcast.config.properties.PropertyTypeConverter) DiscoveryServiceProvider(com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) Test(org.junit.Test) Validator(javax.xml.validation.Validator) SimpleDiscoveryNode(com.hazelcast.spi.discovery.SimpleDiscoveryNode) SlowTest(com.hazelcast.test.annotation.SlowTest) Mockito.when(org.mockito.Mockito.when) Field(java.lang.reflect.Field) DefaultDiscoveryServiceProvider(com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider) Mockito.verify(org.mockito.Mockito.verify) AbstractDiscoveryStrategy(com.hazelcast.spi.discovery.AbstractDiscoveryStrategy) DiscoveryServiceSettings(com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings) InterfacesConfig(com.hazelcast.config.InterfacesConfig) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) 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) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 13 with DiscoveryService

use of com.hazelcast.spi.discovery.integration.DiscoveryService 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) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 14 with DiscoveryService

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

the class DiscoverySpiTest method testCustomDiscoveryService_whenDiscoveredNodes_isEmpty.

@Test
public void testCustomDiscoveryService_whenDiscoveredNodes_isEmpty() {
    Config config = new Config();
    config.setProperty(ClusterProperty.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, atLeastOnce()).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

DiscoveryService (com.hazelcast.spi.discovery.integration.DiscoveryService)14 DefaultDiscoveryService (com.hazelcast.spi.discovery.impl.DefaultDiscoveryService)13 DefaultDiscoveryServiceProvider (com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider)13 DiscoveryServiceProvider (com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider)13 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)11 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)11 QuickTest (com.hazelcast.test.annotation.QuickTest)11 Test (org.junit.Test)11 ClientConfig (com.hazelcast.client.config.ClientConfig)9 DiscoveryServiceSettings (com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings)9 InputStream (java.io.InputStream)7 XmlClientConfigBuilder (com.hazelcast.client.config.XmlClientConfigBuilder)6 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)6 Config (com.hazelcast.config.Config)5 InterfacesConfig (com.hazelcast.config.InterfacesConfig)5 JoinConfig (com.hazelcast.config.JoinConfig)5 Field (java.lang.reflect.Field)5 ILogger (com.hazelcast.logging.ILogger)4 Address (com.hazelcast.cluster.Address)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3