use of com.hazelcast.spi.discovery.integration.DiscoveryService in project hazelcast by hazelcast.
the class ClientDiscoverySpiTest method test_CustomDiscoveryService_whenDiscoveredNodes_isEmpty.
@Test
public void test_CustomDiscoveryService_whenDiscoveredNodes_isEmpty() {
ClientConfig config = new ClientConfig();
config.setProperty(ClusterProperty.DISCOVERY_SPI_ENABLED.getName(), "true");
final DiscoveryService discoveryService = mock(DiscoveryService.class);
when(discoveryService.discoverNodes()).thenReturn(Collections.emptyList());
DiscoveryServiceProvider discoveryServiceProvider = arg0 -> discoveryService;
ClientNetworkConfig networkConfig = config.getNetworkConfig();
config.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(0);
networkConfig.getDiscoveryConfig().addDiscoveryStrategyConfig(new DiscoveryStrategyConfig());
networkConfig.getDiscoveryConfig().setDiscoveryServiceProvider(discoveryServiceProvider);
try {
HazelcastClient.newHazelcastClient(config);
} catch (IllegalStateException expected) {
// no server available
}
verify(discoveryService, new AtLeast(1)).discoverNodes();
}
use of com.hazelcast.spi.discovery.integration.DiscoveryService 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(ClusterProperty.DISCOVERY_SPI_ENABLED.getName(), "true");
final DiscoveryService discoveryService = mock(DiscoveryService.class);
when(discoveryService.discoverNodes()).thenReturn(null);
DiscoveryServiceProvider discoveryServiceProvider = arg0 -> discoveryService;
ClientNetworkConfig networkConfig = config.getNetworkConfig();
config.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(2000);
networkConfig.getDiscoveryConfig().addDiscoveryStrategyConfig(new DiscoveryStrategyConfig());
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.DiscoveryService in project hazelcast by hazelcast.
the class ClientDiscoverySpiTest method testNodeFilter_from_xml.
@Test
public void testNodeFilter_from_xml() throws Exception {
String xmlFileName = "hazelcast-client-discovery-spi-test.xml";
InputStream xmlResource = ClientDiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
ClientConfig clientConfig = new XmlClientConfigBuilder(xmlResource).build();
ClientNetworkConfig networkConfig = clientConfig.getNetworkConfig();
DiscoveryConfig discoveryConfig = networkConfig.getDiscoveryConfig();
DiscoveryServiceProvider provider = new DefaultDiscoveryServiceProvider();
DiscoveryService discoveryService = provider.newDiscoveryService(buildDiscoveryServiceSettings(discoveryConfig));
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.DiscoveryService in project hazelcast by hazelcast.
the class DiscoverySpiTest method testCustomDiscoveryService_whenDiscoveredNodes_isEmpty.
@Test
public void testCustomDiscoveryService_whenDiscoveredNodes_isEmpty() {
Config config = new Config();
config.setProperty(ClusterProperty.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, atLeastOnce()).discoverNodes();
} finally {
instance.getLifecycleService().terminate();
}
}
Aggregations