Search in sources :

Example 1 with DiscoveryStrategyFactory

use of com.hazelcast.spi.discovery.DiscoveryStrategyFactory in project hazelcast by hazelcast.

the class ClientDiscoverySpiTest method testNodeStartup.

@Test
public void testNodeStartup() {
    Config config = new Config();
    config.setProperty("hazelcast.discovery.enabled", "true");
    config.getNetworkConfig().setPort(50001);
    InterfacesConfig interfaces = config.getNetworkConfig().getInterfaces();
    interfaces.clear();
    interfaces.setEnabled(true);
    interfaces.addInterface("127.0.0.1");
    List<DiscoveryNode> discoveryNodes = new CopyOnWriteArrayList<DiscoveryNode>();
    DiscoveryStrategyFactory factory = new CollectingDiscoveryStrategyFactory(discoveryNodes);
    JoinConfig join = config.getNetworkConfig().getJoin();
    join.getTcpIpConfig().setEnabled(false);
    join.getMulticastConfig().setEnabled(false);
    DiscoveryConfig discoveryConfig = join.getDiscoveryConfig();
    discoveryConfig.getDiscoveryStrategyConfigs().clear();
    DiscoveryStrategyConfig strategyConfig = new DiscoveryStrategyConfig(factory, Collections.<String, Comparable>emptyMap());
    discoveryConfig.addDiscoveryStrategyConfig(strategyConfig);
    final HazelcastInstance hazelcastInstance1 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance hazelcastInstance2 = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance hazelcastInstance3 = Hazelcast.newHazelcastInstance(config);
    try {
        ClientConfig clientConfig = new ClientConfig();
        clientConfig.setProperty("hazelcast.discovery.enabled", "true");
        discoveryConfig = clientConfig.getNetworkConfig().getDiscoveryConfig();
        discoveryConfig.getDiscoveryStrategyConfigs().clear();
        strategyConfig = new DiscoveryStrategyConfig(factory, Collections.<String, Comparable>emptyMap());
        discoveryConfig.addDiscoveryStrategyConfig(strategyConfig);
        final HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
        assertNotNull(hazelcastInstance1);
        assertNotNull(hazelcastInstance2);
        assertNotNull(hazelcastInstance3);
        assertNotNull(client);
        assertTrueEventually(new AssertTask() {

            @Override
            public void run() throws Exception {
                assertEquals(3, hazelcastInstance1.getCluster().getMembers().size());
                assertEquals(3, hazelcastInstance2.getCluster().getMembers().size());
                assertEquals(3, hazelcastInstance3.getCluster().getMembers().size());
                assertEquals(3, client.getCluster().getMembers().size());
            }
        });
    } finally {
        HazelcastClient.shutdownAll();
        Hazelcast.shutdownAll();
    }
}
Also used : InterfacesConfig(com.hazelcast.config.InterfacesConfig) DiscoveryNode(com.hazelcast.spi.discovery.DiscoveryNode) SimpleDiscoveryNode(com.hazelcast.spi.discovery.SimpleDiscoveryNode) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) AwsConfig(com.hazelcast.config.AwsConfig) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) JoinConfig(com.hazelcast.config.JoinConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) DiscoveryStrategyFactory(com.hazelcast.spi.discovery.DiscoveryStrategyFactory) HazelcastInstance(com.hazelcast.core.HazelcastInstance) JoinConfig(com.hazelcast.config.JoinConfig) AssertTask(com.hazelcast.test.AssertTask) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with DiscoveryStrategyFactory

use of com.hazelcast.spi.discovery.DiscoveryStrategyFactory in project hazelcast by hazelcast.

the class ClientDiscoverySpiTest method testDiscoveryServiceLifecycleMethodsCalledWhenClientAndServerStartAndShutdown.

@Test
public void testDiscoveryServiceLifecycleMethodsCalledWhenClientAndServerStartAndShutdown() {
    //Given
    Config config = new Config();
    config.setProperty("hazelcast.discovery.enabled", "true");
    config.getNetworkConfig().setPort(50001);
    InterfacesConfig interfaces = config.getNetworkConfig().getInterfaces();
    interfaces.clear();
    interfaces.setEnabled(true);
    interfaces.addInterface("127.0.0.1");
    //Both server and client are using the same LifecycleDiscoveryStrategyFactory so latch count is set to 2.
    CountDownLatch startLatch = new CountDownLatch(2);
    CountDownLatch stopLatch = new CountDownLatch(2);
    List<DiscoveryNode> discoveryNodes = new CopyOnWriteArrayList<DiscoveryNode>();
    DiscoveryStrategyFactory factory = new LifecycleDiscoveryStrategyFactory(startLatch, stopLatch, discoveryNodes);
    JoinConfig join = config.getNetworkConfig().getJoin();
    join.getTcpIpConfig().setEnabled(false);
    join.getMulticastConfig().setEnabled(false);
    DiscoveryConfig discoveryConfig = join.getDiscoveryConfig();
    discoveryConfig.getDiscoveryStrategyConfigs().clear();
    DiscoveryStrategyConfig strategyConfig = new DiscoveryStrategyConfig(factory, Collections.<String, Comparable>emptyMap());
    discoveryConfig.addDiscoveryStrategyConfig(strategyConfig);
    final HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setProperty("hazelcast.discovery.enabled", "true");
    discoveryConfig = clientConfig.getNetworkConfig().getDiscoveryConfig();
    discoveryConfig.getDiscoveryStrategyConfigs().clear();
    strategyConfig = new DiscoveryStrategyConfig(factory, Collections.<String, Comparable>emptyMap());
    discoveryConfig.addDiscoveryStrategyConfig(strategyConfig);
    final HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
    assertNotNull(hazelcastInstance);
    assertNotNull(client);
    //When
    HazelcastClient.shutdownAll();
    Hazelcast.shutdownAll();
    //Then
    assertOpenEventually(startLatch);
    assertOpenEventually(stopLatch);
}
Also used : InterfacesConfig(com.hazelcast.config.InterfacesConfig) DiscoveryNode(com.hazelcast.spi.discovery.DiscoveryNode) SimpleDiscoveryNode(com.hazelcast.spi.discovery.SimpleDiscoveryNode) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) AwsConfig(com.hazelcast.config.AwsConfig) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) JoinConfig(com.hazelcast.config.JoinConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) CountDownLatch(java.util.concurrent.CountDownLatch) DiscoveryStrategyFactory(com.hazelcast.spi.discovery.DiscoveryStrategyFactory) HazelcastInstance(com.hazelcast.core.HazelcastInstance) JoinConfig(com.hazelcast.config.JoinConfig) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with DiscoveryStrategyFactory

use of com.hazelcast.spi.discovery.DiscoveryStrategyFactory in project hazelcast by hazelcast.

the class DiscoveryTest method test_DiscoveryConfigReadOnly_addDiscoveryStrategyConfig.

@Test
public void test_DiscoveryConfigReadOnly_addDiscoveryStrategyConfig() {
    DiscoveryConfig discoveryConfig = new DiscoveryConfig();
    DiscoveryStrategyFactory discoveryStrategyFactory = new TestDiscoveryStrategyFactory();
    DiscoveryStrategyConfig discoveryStrategyConfig = new DiscoveryStrategyConfig(discoveryStrategyFactory);
    discoveryConfig.addDiscoveryStrategyConfig(discoveryStrategyConfig);
    assertSame(discoveryStrategyConfig, discoveryConfig.getDiscoveryStrategyConfigs().iterator().next());
}
Also used : DiscoveryStrategyFactory(com.hazelcast.spi.discovery.DiscoveryStrategyFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with DiscoveryStrategyFactory

use of com.hazelcast.spi.discovery.DiscoveryStrategyFactory in project hazelcast by hazelcast.

the class DiscoveryTest method test_DiscoveryConfigReadOnly_addDiscoveryStrategyConfig_thenUnsupportedOperationException.

@Test(expected = UnsupportedOperationException.class)
public void test_DiscoveryConfigReadOnly_addDiscoveryStrategyConfig_thenUnsupportedOperationException() {
    DiscoveryConfig discoveryConfig = new DiscoveryConfig();
    DiscoveryConfig readOnly = new DiscoveryConfigReadOnly(discoveryConfig);
    DiscoveryStrategyFactory discoveryStrategyFactory = new TestDiscoveryStrategyFactory();
    DiscoveryStrategyConfig discoveryStrategyConfig = new DiscoveryStrategyConfig(discoveryStrategyFactory);
    readOnly.addDiscoveryStrategyConfig(discoveryStrategyConfig);
}
Also used : DiscoveryStrategyFactory(com.hazelcast.spi.discovery.DiscoveryStrategyFactory) DiscoveryConfigReadOnly(com.hazelcast.internal.config.DiscoveryConfigReadOnly) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with DiscoveryStrategyFactory

use of com.hazelcast.spi.discovery.DiscoveryStrategyFactory in project hazelcast by hazelcast.

the class DiscoveryStrategyConfigTest method test_DiscoveryStrategyFactory_constructor_factory_properties.

@Test
public void test_DiscoveryStrategyFactory_constructor_factory_properties() {
    DiscoveryStrategyFactory discoveryStrategyFactory = new TestDiscoveryStrategyFactory();
    Map<String, Comparable> properties = new HashMap<String, Comparable>();
    properties.put("test", "value");
    DiscoveryStrategyConfig discoveryStrategyConfig = new DiscoveryStrategyConfig(discoveryStrategyFactory, properties);
    assertSame(discoveryStrategyFactory, discoveryStrategyConfig.getDiscoveryStrategyFactory());
    assertNull(discoveryStrategyConfig.getClassName());
    assertEquals(1, discoveryStrategyConfig.getProperties().size());
    assertEquals(properties, discoveryStrategyConfig.getProperties());
}
Also used : DiscoveryStrategyFactory(com.hazelcast.spi.discovery.DiscoveryStrategyFactory) HashMap(java.util.HashMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

DiscoveryStrategyFactory (com.hazelcast.spi.discovery.DiscoveryStrategyFactory)14 QuickTest (com.hazelcast.test.annotation.QuickTest)11 Test (org.junit.Test)11 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)8 Config (com.hazelcast.config.Config)6 ClientConfig (com.hazelcast.client.config.ClientConfig)5 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)5 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)5 InterfacesConfig (com.hazelcast.config.InterfacesConfig)5 JoinConfig (com.hazelcast.config.JoinConfig)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)5 DiscoveryNode (com.hazelcast.spi.discovery.DiscoveryNode)4 SimpleDiscoveryNode (com.hazelcast.spi.discovery.SimpleDiscoveryNode)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 ClientClasspathXmlConfig (com.hazelcast.client.config.ClientClasspathXmlConfig)3 SlowTest (com.hazelcast.test.annotation.SlowTest)3 AwsConfig (com.hazelcast.config.AwsConfig)2 ValidationException (com.hazelcast.config.properties.ValidationException)2 ArrayList (java.util.ArrayList)2