@Test public void successfulConnectionIsNotDestroyed() throws IOException { ConnectionConnector spyConnector = spy(new ConnectionConnector(endpointManager, ds, 0, 0, 0, cancelCriterion, false, null, socketCreator, handshake)); doReturn(connection).when(spyConnector).getConnection(ds, cancelCriterion); doReturn(handshake).when(spyConnector).getClientSideHandshake(handshake); try { spyConnector.connectClientToServer(mock(ServerLocation.class), false); } finally { verify(spyConnector, times(0)).destroyConnection(any()); } } }
@Override public ClientUpdater createServerToClientConnection(Endpoint endpoint, QueueManager qManager, boolean isPrimary, ClientUpdater failedUpdater) { String clientUpdateName = CacheClientUpdater.CLIENT_UPDATER_THREAD_NAME + " on " + endpoint.getMemberId() + " port " + endpoint.getLocation().getPort(); if (logger.isDebugEnabled()) { logger.debug("Establishing: {}", clientUpdateName); } // Launch the thread CacheClientUpdater updater = connectionConnector.connectServerToClient(endpoint, qManager, isPrimary, failedUpdater, clientUpdateName); return updater; } }
public ConnectionImpl connectClientToServer(ServerLocation location, boolean forQueue) throws IOException { ConnectionImpl connection = null; boolean initialized = false; try { connection = getConnection(this.ds, this.cancelCriterion); ClientSideHandshake connHandShake = getClientSideHandshake(handshake); connection.connect(endpointManager, location, connHandShake, socketBufferSize, handshakeTimeout, readTimeout, getCommMode(forQueue), this.gatewaySender, this.socketCreator); connection.setHandshake(connHandShake); initialized = true; return connection; } finally { if (!initialized && connection != null) { if (logger.isDebugEnabled()) { logger.debug("Destroying failed connection to {}", location); } destroyConnection(connection); } } }
Connection connection = null; try { connection = connectionConnector.connectClientToServer(location, forQueue); initialized = true; failureTracker.reset();
public ConnectionFactoryImpl(ConnectionSource source, EndpointManager endpointManager, InternalDistributedSystem sys, int socketBufferSize, int handshakeTimeout, int readTimeout, ClientProxyMembershipID proxyId, CancelCriterion cancelCriterion, boolean usedByGateway, GatewaySender sender, long pingInterval, boolean multiuserSecureMode, PoolImpl pool) { this( new ConnectionConnector(endpointManager, sys, socketBufferSize, handshakeTimeout, readTimeout, cancelCriterion, usedByGateway, sender, (usedByGateway || sender != null) ? SocketCreatorFactory .getSocketCreatorForComponent(SecurableCommunicationChannel.GATEWAY) : SocketCreatorFactory .getSocketCreatorForComponent(SecurableCommunicationChannel.SERVER), new ClientSideHandshakeImpl(proxyId, sys, sys.getSecurityService(), multiuserSecureMode)), source, pingInterval, pool, cancelCriterion); }
doReturn(mock(ConnectionImpl.class)).when(connector).connectClientToServer(serverLocation, false);
@Test(expected = GemFireSecurityException.class) public void failedConnectionIsDestroyed() throws IOException { ConnectionConnector spyConnector = spy(new ConnectionConnector(endpointManager, ds, 0, 0, 0, cancelCriterion, false, null, socketCreator, handshake)); doReturn(connection).when(spyConnector).getConnection(ds, cancelCriterion); doReturn(handshake).when(spyConnector).getClientSideHandshake(handshake); when(connection.connect(any(), any(), any(), anyInt(), anyInt(), anyInt(), any(), any(), any())) .thenThrow(new GemFireSecurityException("Expected exception")); try { spyConnector.connectClientToServer(mock(ServerLocation.class), false); } finally { verify(spyConnector).destroyConnection(any()); } }