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);
}
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);
}
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());
}
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();
}
Aggregations