Search in sources :

Example 11 with DiscoveryStrategyFactory

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

the class ClientDiscoverySpiTest method testClientCanConnect_afterDiscoveryStrategyThrowsException.

@Test
public void testClientCanConnect_afterDiscoveryStrategyThrowsException() {
    Config config = new Config();
    config.getNetworkConfig().setPort(50001);
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
    Address address = instance.getCluster().getLocalMember().getAddress();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setProperty(ClusterProperty.DISCOVERY_SPI_ENABLED.getName(), "true");
    DiscoveryConfig discoveryConfig = clientConfig.getNetworkConfig().getDiscoveryConfig();
    DiscoveryStrategyFactory factory = new ExceptionThrowingDiscoveryStrategyFactory(address);
    DiscoveryStrategyConfig strategyConfig = new DiscoveryStrategyConfig(factory, Collections.emptyMap());
    discoveryConfig.addDiscoveryStrategyConfig(strategyConfig);
    HazelcastClient.newHazelcastClient(clientConfig);
}
Also used : DiscoveryStrategyFactory(com.hazelcast.spi.discovery.DiscoveryStrategyFactory) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) JoinConfig(com.hazelcast.config.JoinConfig) ClientClasspathXmlConfig(com.hazelcast.client.config.ClientClasspathXmlConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 12 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.getAutoDetectionConfig().setEnabled(false);
    DiscoveryConfig discoveryConfig = join.getDiscoveryConfig();
    discoveryConfig.getDiscoveryStrategyConfigs().clear();
    DiscoveryStrategyConfig strategyConfig = new DiscoveryStrategyConfig(factory, Collections.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.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) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) JoinConfig(com.hazelcast.config.JoinConfig) ClientClasspathXmlConfig(com.hazelcast.client.config.ClientClasspathXmlConfig) 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) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 13 with DiscoveryStrategyFactory

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

the class DiscoveryStrategyConfigTest method test_DiscoveryStrategyFactory_constructor_factory.

@Test
public void test_DiscoveryStrategyFactory_constructor_factory() {
    DiscoveryStrategyFactory discoveryStrategyFactory = new TestDiscoveryStrategyFactory();
    DiscoveryStrategyConfig discoveryStrategyConfig = new DiscoveryStrategyConfig(discoveryStrategyFactory);
    assertSame(discoveryStrategyFactory, discoveryStrategyConfig.getDiscoveryStrategyFactory());
    assertNull(discoveryStrategyConfig.getClassName());
    assertEquals(0, discoveryStrategyConfig.getProperties().size());
}
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 14 with DiscoveryStrategyFactory

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

the class RestNodeStateTest method testStartingNodeState_regression.

/**
 * This test does a node-state REST call before the Node is switched to the {@link NodeState#ACTIVE}. A custom discovery
 * strategy is used to block the processing in a point when REST is already running, but the node is not yet active. During
 * the blocked discovery initialization the HTTP call is done.
 * <p>
 * See
 * <a href="https://github.com/hazelcast/hazelcast/issues/17773">https://github.com/hazelcast/hazelcast/issues/17773</a>.
 */
@Test
public void testStartingNodeState_regression() throws Exception {
    Config config = smallInstanceConfig().setProperty(ClusterProperty.DISCOVERY_SPI_ENABLED.getName(), "true");
    RestApiConfig restApiConfig = new RestApiConfig().setEnabled(true).enableAllGroups();
    NetworkConfig networkConfig = config.getNetworkConfig();
    int port = TestUtil.getAvailablePort(BASE_PORT);
    networkConfig.setPort(port).setPortAutoIncrement(false);
    networkConfig.getJoin().getMulticastConfig().setEnabled(false);
    networkConfig.setRestApiConfig(restApiConfig);
    StrategyFactory discoveryStrategyFactory = new StrategyFactory();
    networkConfig.getJoin().getDiscoveryConfig().addDiscoveryStrategyConfig(new DiscoveryStrategyConfig(discoveryStrategyFactory));
    HazelcastTestSupport.spawn(() -> Hazelcast.newHazelcastInstance(config));
    discoveryStrategyFactory.getNodeStartingLatch().await();
    HTTPCommunicator communicator = new HTTPCommunicator(port);
    assertEquals("\"STARTING\"", communicator.getClusterHealth("/node-state"));
    discoveryStrategyFactory.getTestDoneLatch().countDown();
}
Also used : RestApiConfig(com.hazelcast.config.RestApiConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) RestApiConfig(com.hazelcast.config.RestApiConfig) HazelcastTestSupport.smallInstanceConfig(com.hazelcast.test.HazelcastTestSupport.smallInstanceConfig) Config(com.hazelcast.config.Config) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) DiscoveryStrategyFactory(com.hazelcast.spi.discovery.DiscoveryStrategyFactory) NetworkConfig(com.hazelcast.config.NetworkConfig) 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