use of com.hazelcast.config.SocketInterceptorConfig in project hazelcast by hazelcast.
the class ConnectionTest method testDanglingSocketsOnTerminate.
private void testDanglingSocketsOnTerminate(boolean withSocketInterceptor) throws Exception {
final int port = 5701;
Config config = new Config();
config.getNetworkConfig().setPort(port).setPortAutoIncrement(false);
if (withSocketInterceptor) {
config.getNetworkConfig().setSocketInterceptorConfig(new SocketInterceptorConfig().setEnabled(true).setImplementation(new MemberSocketInterceptor() {
public void init(Properties properties) {
}
public void onAccept(Socket acceptedSocket) throws IOException {
}
public void onConnect(Socket connectedSocket) throws IOException {
}
}));
}
final HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
final int count = 100;
final CountDownLatch latch = new CountDownLatch(count);
final CountDownLatch ll = new CountDownLatch(1);
final AtomicInteger cc = new AtomicInteger();
new Thread() {
public void run() {
try {
ll.await(1, TimeUnit.MINUTES);
hz.getLifecycleService().terminate();
} catch (InterruptedException ignored) {
}
}
}.start();
final Collection<Socket> sockets = Collections.newSetFromMap(new ConcurrentHashMap<Socket, Boolean>());
final AtomicInteger k0 = new AtomicInteger();
final AtomicInteger k1 = new AtomicInteger();
for (int i = 0; i < count; i++) {
Runnable task = new Runnable() {
public void run() {
try {
if (cc.incrementAndGet() == count / 10) {
ll.countDown();
}
Socket socket = new Socket();
sockets.add(socket);
try {
socket.connect(new InetSocketAddress(port));
k0.incrementAndGet();
} catch (IOException e) {
k1.incrementAndGet();
}
OutputStream out = socket.getOutputStream();
out.write(Protocols.CLUSTER.getBytes());
out.flush();
socket.getInputStream().read();
} catch (IOException ignored) {
} finally {
latch.countDown();
}
}
};
Thread t = new Thread(task, "socket-thread-" + i);
t.setDaemon(true);
t.start();
}
try {
assertTrue(latch.await(1, TimeUnit.MINUTES));
} catch (AssertionError e) {
System.err.println(ThreadDumpGenerator.dumpAllThreads());
throw e;
} finally {
for (Socket socket : sockets) {
try {
socket.close();
} catch (Exception e) {
ignore(e);
}
}
}
}
use of com.hazelcast.config.SocketInterceptorConfig in project hazelcast by hazelcast.
the class TestClientNetworkConfig method smokeSocketInterceptor.
@Test
public void smokeSocketInterceptor() {
ClientConfig config = client.getClientConfig();
SocketInterceptorConfig socketInterceptorConfig = config.getNetworkConfig().getSocketInterceptorConfig();
assertEquals(false, socketInterceptorConfig.isEnabled());
assertEquals(DummySocketInterceptor.class.getName(), socketInterceptorConfig.getClassName());
}
use of com.hazelcast.config.SocketInterceptorConfig in project hazelcast by hazelcast.
the class TestFullApplicationContext method testSocketInterceptorConfig.
@Test
public void testSocketInterceptorConfig() {
SocketInterceptorConfig socketInterceptorConfig = config.getNetworkConfig().getSocketInterceptorConfig();
assertNotNull(socketInterceptorConfig);
assertFalse(socketInterceptorConfig.isEnabled());
assertEquals(DummySocketInterceptor.class.getName(), socketInterceptorConfig.getClassName());
assertEquals(socketInterceptor, socketInterceptorConfig.getImplementation());
}
use of com.hazelcast.config.SocketInterceptorConfig in project hazelcast by hazelcast.
the class XmlClientConfigBuilder method handleSocketInterceptorConfig.
private void handleSocketInterceptorConfig(Node node, ClientNetworkConfig clientNetworkConfig) {
SocketInterceptorConfig socketInterceptorConfig = parseSocketInterceptorConfig(node);
clientNetworkConfig.setSocketInterceptorConfig(socketInterceptorConfig);
}
use of com.hazelcast.config.SocketInterceptorConfig in project hazelcast by hazelcast.
the class XmlClientConfigBuilderTest method testNetworkConfig.
@Test
public void testNetworkConfig() {
final ClientNetworkConfig networkConfig = clientConfig.getNetworkConfig();
assertEquals(2, networkConfig.getConnectionAttemptLimit());
assertEquals(2, networkConfig.getAddresses().size());
assertContains(networkConfig.getAddresses(), "127.0.0.1");
assertContains(networkConfig.getAddresses(), "127.0.0.2");
assertTrue(networkConfig.isSmartRouting());
assertTrue(networkConfig.isRedoOperation());
final SocketInterceptorConfig socketInterceptorConfig = networkConfig.getSocketInterceptorConfig();
assertTrue(socketInterceptorConfig.isEnabled());
assertEquals("com.hazelcast.examples.MySocketInterceptor", socketInterceptorConfig.getClassName());
assertEquals("bar", socketInterceptorConfig.getProperty("foo"));
final ClientAwsConfig awsConfig = networkConfig.getAwsConfig();
assertTrue(awsConfig.isEnabled());
assertTrue(awsConfig.isInsideAws());
assertEquals("TEST_ACCESS_KEY", awsConfig.getAccessKey());
assertEquals("TEST_ACCESS_KEY", awsConfig.getAccessKey());
assertEquals("TEST_SECRET_KEY", awsConfig.getSecretKey());
assertEquals("us-east-1", awsConfig.getRegion());
assertEquals("ec2.amazonaws.com", awsConfig.getHostHeader());
assertEquals("type", awsConfig.getTagKey());
assertEquals("hz-nodes", awsConfig.getTagValue());
assertEquals(11, awsConfig.getConnectionTimeoutSeconds());
}
Aggregations