use of com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings in project hazelcast by hazelcast.
the class ClientDiscoverySpiTest method test_CustomDiscoveryService_whenDiscoveredNodes_isNull.
@Test
public void test_CustomDiscoveryService_whenDiscoveredNodes_isNull() {
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) {
return discoveryService;
}
};
ClientNetworkConfig networkConfig = config.getNetworkConfig();
networkConfig.setConnectionAttemptLimit(1);
networkConfig.setConnectionAttemptPeriod(1);
networkConfig.getDiscoveryConfig().setDiscoveryServiceProvider(discoveryServiceProvider);
try {
HazelcastClient.newHazelcastClient(config);
fail("Client cannot start, discovery nodes is null!");
} catch (NullPointerException expected) {
// discovered nodes is null
}
verify(discoveryService).discoverNodes();
}
use of com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings in project hazelcast by hazelcast.
the class Node method createDiscoveryService.
private DiscoveryService createDiscoveryService(Config config) {
JoinConfig joinConfig = config.getNetworkConfig().getJoin();
DiscoveryConfig discoveryConfig = joinConfig.getDiscoveryConfig().getAsReadOnly();
DiscoveryServiceProvider factory = discoveryConfig.getDiscoveryServiceProvider();
if (factory == null) {
factory = new DefaultDiscoveryServiceProvider();
}
ILogger logger = getLogger(DiscoveryService.class);
DiscoveryServiceSettings settings = new DiscoveryServiceSettings().setConfigClassLoader(configClassLoader).setLogger(logger).setDiscoveryMode(DiscoveryMode.Member).setDiscoveryConfig(discoveryConfig).setDiscoveryNode(new SimpleDiscoveryNode(localMember.getAddress(), localMember.getAttributes()));
return factory.newDiscoveryService(settings);
}
use of com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings 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) {
}
}
use of com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings 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());
}
use of com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings in project hazelcast by hazelcast.
the class DiscoverySpiTest method testCustomDiscoveryService_whenDiscoveredNodes_isEmpty.
@Test
public void testCustomDiscoveryService_whenDiscoveredNodes_isEmpty() {
Config config = new Config();
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;
}
};
config.getNetworkConfig().getJoin().getDiscoveryConfig().setDiscoveryServiceProvider(discoveryServiceProvider);
HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
try {
verify(discoveryService).discoverNodes();
} finally {
instance.getLifecycleService().terminate();
}
}
Aggregations