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 ClientDiscoverySpiTest method test_discovery_address_translator_with_public_ip.
@Test
public void test_discovery_address_translator_with_public_ip() 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));
AddressTranslator translator = new DiscoveryAddressTranslator(discoveryService, true);
Address publicAddress = new Address("127.0.0.1", 50001);
Address privateAddress = new Address("127.0.0.1", 1);
// Enforce refresh of the internal mapping
assertEquals(publicAddress, translator.translate(privateAddress));
}
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(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.DiscoveryService 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.DiscoveryService in project hazelcast by hazelcast.
the class DiscoverySpiTest method testCustomDiscoveryService_whenDiscoveredNodes_isNull.
@Test
public void testCustomDiscoveryService_whenDiscoveredNodes_isNull() {
Config config = new Config();
config.setProperty(ClusterProperty.DISCOVERY_SPI_ENABLED.getName(), "true");
DiscoveryServiceProvider discoveryServiceProvider = new DiscoveryServiceProvider() {
public DiscoveryService newDiscoveryService(DiscoveryServiceSettings arg0) {
DiscoveryService mocked = mock(DiscoveryService.class);
when(mocked.discoverNodes()).thenReturn(null);
return mocked;
}
};
config.getNetworkConfig().getJoin().getDiscoveryConfig().setDiscoveryServiceProvider(discoveryServiceProvider);
try {
Hazelcast.newHazelcastInstance(config);
fail("Instance should not be started!");
} catch (IllegalStateException expected) {
}
}
Aggregations