@Test(expected = RuntimeException.class, timeout = 120000) public void testFailingSocketInterceptor() { Config config = new Config(); config.setProperty(GroupProperties.PROP_MAX_JOIN_SECONDS, "3"); SocketInterceptorConfig sic = new SocketInterceptorConfig(); MySocketInterceptor mySocketInterceptor = new MySocketInterceptor(false); sic.setImplementation(mySocketInterceptor); config.getNetworkConfig().setSocketInterceptorConfig(sic); HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config); HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config); }
@Test(expected = RuntimeException.class, timeout = 120000) public void testFailingClientSocketInterceptor() { Config config = new Config(); SocketInterceptorConfig sic = new SocketInterceptorConfig(); MySocketInterceptor mySocketInterceptor = new MySocketInterceptor(true); sic.setImplementation(mySocketInterceptor); config.getNetworkConfig().setSocketInterceptorConfig(sic); HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config); HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config); int count = 1000; for (int i = 0; i < count; i++) { h1.getMap("default").put(i, "value" + i); h2.getMap("default").put(i, "value" + i); } assertEquals(2, h2.getCluster().getMembers().size()); assertTrue(mySocketInterceptor.getAcceptCallCount() >= 1); assertTrue(mySocketInterceptor.getConnectCallCount() >= 1); assertEquals(2, mySocketInterceptor.getInitCallCount()); assertEquals(0, mySocketInterceptor.getAcceptFailureCount()); assertEquals(0, mySocketInterceptor.getConnectFailureCount()); ClientConfig clientConfig = new ClientConfig(); clientConfig.setGroupConfig(new GroupConfig("dev", "dev-pass")).addAddress("localhost"); MySocketInterceptor myClientSocketInterceptor = new MySocketInterceptor(false); clientConfig.setSocketInterceptor(myClientSocketInterceptor); HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); for (int i = 0; i < count; i++) { client.getMap("default").put(i, "value" + i); } assertTrue(mySocketInterceptor.getAcceptCallCount() >= 2); assertTrue(mySocketInterceptor.getConnectCallCount() >= 1); assertEquals(1, myClientSocketInterceptor.getConnectCallCount()); assertEquals(0, myClientSocketInterceptor.getAcceptCallCount()); assertEquals(1, mySocketInterceptor.getAcceptFailureCount()); assertEquals(0, myClientSocketInterceptor.getAcceptFailureCount()); assertEquals(1, myClientSocketInterceptor.getConnectFailureCount()); }
@Test(expected = RuntimeException.class, timeout = 120000) public void testFailingSocketInterceptor() { Config config = new Config(); config.setProperty(GroupProperties.PROP_MAX_JOIN_SECONDS, "3"); SocketInterceptorConfig sic = new SocketInterceptorConfig(); MySocketInterceptor mySocketInterceptor = new MySocketInterceptor(false); sic.setImplementation(mySocketInterceptor).setEnabled(true); config.getNetworkConfig().setSocketInterceptorConfig(sic); HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config); HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config); }
@Test(expected = RuntimeException.class, timeout = 120000) public void testFailingClientSocketInterceptor() { Config config = new Config(); SocketInterceptorConfig sic = new SocketInterceptorConfig(); MySocketInterceptor mySocketInterceptor = new MySocketInterceptor(true); sic.setImplementation(mySocketInterceptor).setEnabled(true); config.getNetworkConfig().setSocketInterceptorConfig(sic); HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config); HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config); int count = 1000; for (int i = 0; i < count; i++) { h1.getMap("default").put(i, "value" + i); h2.getMap("default").put(i, "value" + i); } assertEquals(2, h2.getCluster().getMembers().size()); assertTrue(mySocketInterceptor.getAcceptCallCount() >= 1); assertTrue(mySocketInterceptor.getConnectCallCount() >= 1); assertEquals(2, mySocketInterceptor.getInitCallCount()); assertEquals(0, mySocketInterceptor.getAcceptFailureCount()); assertEquals(0, mySocketInterceptor.getConnectFailureCount()); ClientConfig clientConfig = new ClientConfig(); clientConfig.setGroupConfig(new GroupConfig("dev", "dev-pass")).addAddress("localhost"); MySocketInterceptor myClientSocketInterceptor = new MySocketInterceptor(false); clientConfig.setSocketInterceptor(myClientSocketInterceptor); HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); for (int i = 0; i < count; i++) { client.getMap("default").put(i, "value" + i); } assertTrue(mySocketInterceptor.getAcceptCallCount() >= 2); assertTrue(mySocketInterceptor.getConnectCallCount() >= 1); assertEquals(1, myClientSocketInterceptor.getConnectCallCount()); assertEquals(0, myClientSocketInterceptor.getAcceptCallCount()); assertEquals(1, mySocketInterceptor.getAcceptFailureCount()); assertEquals(0, myClientSocketInterceptor.getAcceptFailureCount()); assertEquals(1, myClientSocketInterceptor.getConnectFailureCount()); }
public void init(final SocketInterceptorConfig socketInterceptorConfig) { }
public SocketInterceptorConfig getSocketInterceptorConfig() { return node.getConfig().getNetworkConfig().getSocketInterceptorConfig(); }
public ConnectionManager(IOService ioService, ServerSocketChannel serverSocketChannel) { this.ioService = ioService; this.ipV6ScopeId = ioService.getThisAddress().getScopeId(); this.serverSocketChannel = serverSocketChannel; this.logger = ioService.getLogger(ConnectionManager.class.getName()); this.SOCKET_RECEIVE_BUFFER_SIZE = ioService.getSocketReceiveBufferSize() * KILO_BYTE; this.SOCKET_SEND_BUFFER_SIZE = ioService.getSocketSendBufferSize() * KILO_BYTE; this.SOCKET_LINGER_SECONDS = ioService.getSocketLingerSeconds(); this.SOCKET_KEEP_ALIVE = ioService.getSocketKeepAlive(); this.SOCKET_NO_DELAY = ioService.getSocketNoDelay(); int selectorCount = ioService.getSelectorThreadCount(); selectors = new InOutSelector[selectorCount]; SSLConfig sslConfig = ioService.getSSLConfig(); if (sslConfig != null && sslConfig.isEnabled()) { socketChannelWrapperFactory = new SSLSocketChannelWrapperFactory(sslConfig); logger.log(Level.INFO, "SSL is enabled"); } else { socketChannelWrapperFactory = new DefaultSocketChannelWrapperFactory(); } SocketInterceptorConfig sic = ioService.getSocketInterceptorConfig(); if (sic != null && sic.isEnabled()) { SocketInterceptor implementation = (SocketInterceptor) sic.getImplementation(); if (implementation == null && sic.getClassName() != null) { try { implementation = (SocketInterceptor) Class.forName(sic.getClassName()).newInstance(); } catch (Throwable e) { logger.log(Level.SEVERE, "SocketInterceptor class cannot be instantiated!" + sic.getClassName(), e); } } if (implementation != null) { if (!(implementation instanceof MemberSocketInterceptor)) { logger.log(Level.SEVERE, "SocketInterceptor must be instance of " + MemberSocketInterceptor.class.getName()); implementation = null; } else { logger.log(Level.INFO, "SocketInterceptor is enabled"); } } if (implementation != null) { memberSocketInterceptor = (MemberSocketInterceptor) implementation; memberSocketInterceptor.init(sic); } else { memberSocketInterceptor = null; } } else { memberSocketInterceptor = null; } }
@Test(timeout = 120000) public void testSuccessfulSocketInterceptor() { Config config = new Config(); SocketInterceptorConfig sic = new SocketInterceptorConfig(); MySocketInterceptor mySocketInterceptor = new MySocketInterceptor(true); sic.setImplementation(mySocketInterceptor); config.getNetworkConfig().setSocketInterceptorConfig(sic); HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config); HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config); HazelcastInstance h3 = Hazelcast.newHazelcastInstance(config); HazelcastInstance h4 = Hazelcast.newHazelcastInstance(config); int count = 1000; for (int i = 0; i < count; i++) { h1.getMap("default").put(i, "value" + i); h2.getMap("default").put(i, "value" + i); h3.getMap("default").put(i, "value" + i); h4.getMap("default").put(i, "value" + i); } assertEquals(4, h4.getCluster().getMembers().size()); assertTrue(mySocketInterceptor.getAcceptCallCount() >= 6); assertTrue(mySocketInterceptor.getConnectCallCount() >= 6); assertEquals(4, mySocketInterceptor.getInitCallCount()); assertEquals(0, mySocketInterceptor.getAcceptFailureCount()); assertEquals(0, mySocketInterceptor.getConnectFailureCount()); ClientConfig clientConfig = new ClientConfig(); clientConfig.setGroupConfig(new GroupConfig("dev", "dev-pass")).addAddress("localhost"); MySocketInterceptor myClientSocketInterceptor = new MySocketInterceptor(true); clientConfig.setSocketInterceptor(myClientSocketInterceptor); HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); for (int i = 0; i < count; i++) { client.getMap("default").put(i, "value" + i); } assertTrue(mySocketInterceptor.getAcceptCallCount() >= 7); assertTrue(mySocketInterceptor.getConnectCallCount() >= 6); assertEquals(1, myClientSocketInterceptor.getConnectCallCount()); assertEquals(0, myClientSocketInterceptor.getAcceptCallCount()); assertEquals(0, mySocketInterceptor.getAcceptFailureCount()); assertEquals(0, mySocketInterceptor.getConnectFailureCount()); assertEquals(0, myClientSocketInterceptor.getAcceptFailureCount()); assertEquals(0, myClientSocketInterceptor.getConnectFailureCount()); }
public void init(SocketInterceptorConfig socketInterceptorConfig) { initCallCount.incrementAndGet(); }
@Override public SocketInterceptorConfig getSocketInterceptorConfig() { return null; }
public ConnectionManager(IOService ioService, ServerSocketChannel serverSocketChannel) { this.ioService = ioService; this.serverSocketChannel = serverSocketChannel; this.logger = ioService.getLogger(ConnectionManager.class.getName()); this.SOCKET_RECEIVE_BUFFER_SIZE = ioService.getSocketReceiveBufferSize() * KILO_BYTE; this.SOCKET_SEND_BUFFER_SIZE = ioService.getSocketSendBufferSize() * KILO_BYTE; this.SOCKET_LINGER_SECONDS = ioService.getSocketLingerSeconds(); this.SOCKET_KEEP_ALIVE = ioService.getSocketKeepAlive(); this.SOCKET_NO_DELAY = ioService.getSocketNoDelay(); int selectorCount = ioService.getSelectorThreadCount(); selectors = new InOutSelector[selectorCount]; final Collection<Integer> ports = ioService.getOutboundPorts(); outboundPortCount = ports == null ? 0 : ports.size(); if (ports != null) { outboundPorts.addAll(ports); } SSLConfig sslConfig = ioService.getSSLConfig(); if (sslConfig != null && sslConfig.isEnabled()) { socketChannelWrapperFactory = new SSLSocketChannelWrapperFactory(sslConfig); logger.log(Level.INFO, "SSL is enabled"); } else { socketChannelWrapperFactory = new DefaultSocketChannelWrapperFactory(); } SocketInterceptorConfig sic = ioService.getSocketInterceptorConfig(); if (sic != null && sic.isEnabled()) { SocketInterceptor implementation = (SocketInterceptor) sic.getImplementation(); if (implementation == null && sic.getClassName() != null) { try { implementation = (SocketInterceptor) Class.forName(sic.getClassName()).newInstance(); } catch (Throwable e) { logger.log(Level.SEVERE, "SocketInterceptor class cannot be instantiated!" + sic.getClassName(), e); } } if (implementation != null) { if (!(implementation instanceof MemberSocketInterceptor)) { logger.log(Level.SEVERE, "SocketInterceptor must be instance of " + MemberSocketInterceptor.class.getName()); implementation = null; } else { logger.log(Level.INFO, "SocketInterceptor is enabled"); } } if (implementation != null) { memberSocketInterceptor = (MemberSocketInterceptor) implementation; memberSocketInterceptor.init(sic); } else { memberSocketInterceptor = null; } } else { memberSocketInterceptor = null; } }
@Test(timeout = 120000) public void testSuccessfulSocketInterceptor() { Config config = new Config(); SocketInterceptorConfig sic = new SocketInterceptorConfig(); MySocketInterceptor mySocketInterceptor = new MySocketInterceptor(true); sic.setImplementation(mySocketInterceptor).setEnabled(true); config.getNetworkConfig().setSocketInterceptorConfig(sic); HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config); HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config); HazelcastInstance h3 = Hazelcast.newHazelcastInstance(config); HazelcastInstance h4 = Hazelcast.newHazelcastInstance(config); int count = 1000; for (int i = 0; i < count; i++) { h1.getMap("default").put(i, "value" + i); h2.getMap("default").put(i, "value" + i); h3.getMap("default").put(i, "value" + i); h4.getMap("default").put(i, "value" + i); } assertEquals(4, h4.getCluster().getMembers().size()); assertTrue(mySocketInterceptor.getAcceptCallCount() >= 6); assertTrue(mySocketInterceptor.getConnectCallCount() >= 6); assertEquals(4, mySocketInterceptor.getInitCallCount()); assertEquals(0, mySocketInterceptor.getAcceptFailureCount()); assertEquals(0, mySocketInterceptor.getConnectFailureCount()); ClientConfig clientConfig = new ClientConfig(); clientConfig.setGroupConfig(new GroupConfig("dev", "dev-pass")).addAddress("localhost"); MySocketInterceptor myClientSocketInterceptor = new MySocketInterceptor(true); clientConfig.setSocketInterceptor(myClientSocketInterceptor); HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); for (int i = 0; i < count; i++) { client.getMap("default").put(i, "value" + i); } assertTrue(mySocketInterceptor.getAcceptCallCount() >= 7); assertTrue(mySocketInterceptor.getConnectCallCount() >= 6); assertEquals(1, myClientSocketInterceptor.getConnectCallCount()); assertEquals(0, myClientSocketInterceptor.getAcceptCallCount()); assertEquals(0, mySocketInterceptor.getAcceptFailureCount()); assertEquals(0, mySocketInterceptor.getConnectFailureCount()); assertEquals(0, myClientSocketInterceptor.getAcceptFailureCount()); assertEquals(0, myClientSocketInterceptor.getConnectFailureCount()); }
SocketInterceptorConfig getSocketInterceptorConfig();
void init(SocketInterceptorConfig socketInterceptorConfig);