use of com.hazelcast.client.config.ClientNetworkConfig 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.client.config.ClientNetworkConfig in project hazelcast by hazelcast.
the class ClientDiscoverySpiTest method testParsing.
@Test
public void testParsing() 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();
AwsConfig awsConfig = networkConfig.getAwsConfig();
assertNull(awsConfig);
DiscoveryConfig discoveryConfig = networkConfig.getDiscoveryConfig();
assertTrue(discoveryConfig.isEnabled());
assertEquals(1, discoveryConfig.getDiscoveryStrategyConfigs().size());
DiscoveryStrategyConfig providerConfig = discoveryConfig.getDiscoveryStrategyConfigs().iterator().next();
assertEquals(3, providerConfig.getProperties().size());
assertEquals("foo", providerConfig.getProperties().get("key-string"));
assertEquals("123", providerConfig.getProperties().get("key-int"));
assertEquals("true", providerConfig.getProperties().get("key-boolean"));
}
use of com.hazelcast.client.config.ClientNetworkConfig in project hazelcast by hazelcast.
the class DummyClientMapPartitionIteratorTest method getClientConfig.
private static ClientConfig getClientConfig(HazelcastInstance instance) {
Address address = instance.getCluster().getLocalMember().getAddress();
String addressString = address.getHost() + ":" + address.getPort();
ClientConfig clientConfig = new ClientConfig();
ClientNetworkConfig networkConfig = new ClientNetworkConfig();
networkConfig.setSmartRouting(false);
networkConfig.addAddress(addressString);
clientConfig.setNetworkConfig(networkConfig);
return clientConfig;
}
use of com.hazelcast.client.config.ClientNetworkConfig in project hazelcast by hazelcast.
the class ClusterListenerSupport method connectToCluster.
public void connectToCluster() throws Exception {
ownerConnectionAddress = null;
final ClientNetworkConfig networkConfig = client.getClientConfig().getNetworkConfig();
final int connAttemptLimit = networkConfig.getConnectionAttemptLimit();
final int connectionAttemptPeriod = networkConfig.getConnectionAttemptPeriod();
final int connectionAttemptLimit = connAttemptLimit == 0 ? Integer.MAX_VALUE : connAttemptLimit;
int attempt = 0;
Set<InetSocketAddress> triedAddresses = new HashSet<InetSocketAddress>();
while (attempt < connectionAttemptLimit) {
if (!client.getLifecycleService().isRunning()) {
if (logger.isFinestEnabled()) {
logger.finest("Giving up on retrying to connect to cluster since client is shutdown");
}
break;
}
attempt++;
final long nextTry = Clock.currentTimeMillis() + connectionAttemptPeriod;
boolean isConnected = connect(triedAddresses);
if (isConnected) {
return;
}
final long remainingTime = nextTry - Clock.currentTimeMillis();
logger.warning(String.format("Unable to get alive cluster connection, try in %d ms later, attempt %d of %d.", Math.max(0, remainingTime), attempt, connectionAttemptLimit));
if (remainingTime > 0) {
try {
Thread.sleep(remainingTime);
} catch (InterruptedException e) {
break;
}
}
}
throw new IllegalStateException("Unable to connect to any address in the config!" + " The following addresses were tried: " + triedAddresses);
}
use of com.hazelcast.client.config.ClientNetworkConfig in project hazelcast by hazelcast.
the class TestClientApplicationContext method testAwsClientConfig.
@Test
public void testAwsClientConfig() {
assertNotNull(client4);
ClientConfig config = client4.getClientConfig();
ClientNetworkConfig networkConfig = config.getNetworkConfig();
ClientAwsConfig awsConfig = networkConfig.getAwsConfig();
assertFalse(awsConfig.isEnabled());
assertTrue(awsConfig.isInsideAws());
assertEquals("sample-access-key", awsConfig.getAccessKey());
assertEquals("sample-secret-key", awsConfig.getSecretKey());
assertEquals("sample-region", awsConfig.getRegion());
assertEquals("sample-group", awsConfig.getSecurityGroupName());
assertEquals("sample-tag-key", awsConfig.getTagKey());
assertEquals("sample-tag-value", awsConfig.getTagValue());
}
Aggregations