Connection connection = null; try { connection = connectionConnector.connectClientToServer(location, forQueue); initialized = true; failureTracker.reset();
@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()); } } }
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()); } }