use of com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings 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(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;
}
};
ClientNetworkConfig networkConfig = config.getNetworkConfig();
networkConfig.setConnectionAttemptLimit(1);
networkConfig.setConnectionAttemptPeriod(1);
networkConfig.getDiscoveryConfig().setDiscoveryServiceProvider(discoveryServiceProvider);
try {
HazelcastClient.newHazelcastClient(config);
} catch (IllegalStateException expected) {
// no server available
}
verify(discoveryService).discoverNodes();
}
use of com.hazelcast.spi.discovery.integration.DiscoveryServiceSettings in project hazelcast by hazelcast.
the class HazelcastClientInstanceImpl method initDiscoveryService.
private DiscoveryService initDiscoveryService(ClientConfig config) {
// and strategies are resolved but the AddressProvider is never registered
if (!properties.getBoolean(ClientProperty.DISCOVERY_SPI_ENABLED)) {
return null;
}
ILogger logger = loggingService.getLogger(DiscoveryService.class);
ClientNetworkConfig networkConfig = config.getNetworkConfig();
DiscoveryConfig discoveryConfig = networkConfig.getDiscoveryConfig().getAsReadOnly();
DiscoveryServiceProvider factory = discoveryConfig.getDiscoveryServiceProvider();
if (factory == null) {
factory = new DefaultDiscoveryServiceProvider();
}
DiscoveryServiceSettings settings = new DiscoveryServiceSettings().setConfigClassLoader(config.getClassLoader()).setLogger(logger).setDiscoveryMode(DiscoveryMode.Client).setDiscoveryConfig(discoveryConfig);
DiscoveryService discoveryService = factory.newDiscoveryService(settings);
discoveryService.start();
return discoveryService;
}
Aggregations