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