Search in sources :

Example 6 with DiscoveryServiceProvider

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

use of com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider 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 8 with DiscoveryServiceProvider

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

Example 9 with DiscoveryServiceProvider

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

the class ClientDiscoverySpiTest method test_discovery_address_translator.

@Test
public void test_discovery_address_translator() 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, false);
    Address address = new Address("127.0.0.1", 50001);
    assertNull(translator.translate(null));
    assertEquals(address, translator.translate(address));
    // Enforce refresh of the internal mapping
    assertEquals(address, translator.translate(address));
}
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 10 with DiscoveryServiceProvider

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

Aggregations

DiscoveryServiceProvider (com.hazelcast.spi.discovery.integration.DiscoveryServiceProvider)11 DefaultDiscoveryServiceProvider (com.hazelcast.spi.discovery.impl.DefaultDiscoveryServiceProvider)10 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Test (org.junit.Test)9 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)8 DiscoveryService (com.hazelcast.spi.discovery.integration.DiscoveryService)8 DefaultDiscoveryService (com.hazelcast.spi.discovery.impl.DefaultDiscoveryService)7 DiscoveryServiceSettings (com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings)7 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)6 ClientConfig (com.hazelcast.client.config.ClientConfig)5 JoinConfig (com.hazelcast.config.JoinConfig)4 InputStream (java.io.InputStream)4 XmlClientConfigBuilder (com.hazelcast.client.config.XmlClientConfigBuilder)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 Address (com.hazelcast.nio.Address)3