Skip to content

Commit b0a599c

Browse files
committed
Track connections left open in tests
(cherry picked from commit 3291568) Conflicts: src/test/java/com/rabbitmq/client/test/ConnectionFactoryTest.java
1 parent 69f3d3c commit b0a599c

16 files changed

+89
-55
lines changed

src/test/java/com/rabbitmq/client/test/AMQConnectionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ public class AMQConnectionTest {
5151
private ConnectionFactory factory;
5252
private MyExceptionHandler exceptionHandler;
5353

54-
@Before public void setUp() throws Exception {
54+
@Before public void setUp() {
5555
_mockFrameHandler = new MockFrameHandler();
5656
factory = TestUtils.connectionFactory();
5757
exceptionHandler = new MyExceptionHandler();
5858
factory.setExceptionHandler(exceptionHandler);
5959
}
6060

61-
@After public void tearDown() throws Exception {
61+
@After public void tearDown() {
6262
factory = null;
6363
_mockFrameHandler = null;
6464
}

src/test/java/com/rabbitmq/client/test/BrokenFramesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public class BrokenFramesTest {
4242
private MyFrameHandler myFrameHandler;
4343
private ConnectionFactory factory;
4444

45-
@Before public void setUp() throws Exception {
45+
@Before public void setUp() {
4646
myFrameHandler = new MyFrameHandler();
4747
factory = TestUtils.connectionFactory();
4848
}
4949

50-
@After public void tearDown() throws Exception {
50+
@After public void tearDown() {
5151
factory = null;
5252
myFrameHandler = null;
5353
}

src/test/java/com/rabbitmq/client/test/BrokerTestCase.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.rabbitmq.client.impl.nio.NioParams;
2121
import com.rabbitmq.tools.Host;
2222
import org.junit.After;
23-
import org.junit.Assume;
2423
import org.junit.Before;
2524
import org.junit.Rule;
2625
import org.junit.rules.TestRule;
@@ -32,7 +31,6 @@
3231
import javax.net.ssl.SSLContext;
3332
import java.io.IOException;
3433
import java.security.NoSuchAlgorithmException;
35-
import java.util.Arrays;
3634
import java.util.Map;
3735
import java.util.UUID;
3836
import java.util.concurrent.TimeoutException;
@@ -184,7 +182,6 @@ public void checkShutdownSignal(int expectedCode, ShutdownSignalException sse) {
184182
Method method = sse.getReason();
185183
channel = null;
186184
if (sse.isHardError()) {
187-
connection = null;
188185
AMQP.Connection.Close closeMethod = (AMQP.Connection.Close) method;
189186
assertEquals(expectedCode, closeMethod.getReplyCode());
190187
} else {

src/test/java/com/rabbitmq/client/test/ChannelAsyncCompletableFutureTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525

2626
import java.io.IOException;
2727
import java.util.UUID;
28-
import java.util.concurrent.CountDownLatch;
29-
import java.util.concurrent.ExecutorService;
30-
import java.util.concurrent.Executors;
31-
import java.util.concurrent.TimeUnit;
28+
import java.util.concurrent.*;
3229

3330
import static org.junit.Assert.assertTrue;
3431

@@ -39,13 +36,17 @@ public class ChannelAsyncCompletableFutureTest extends BrokerTestCase {
3936
String queue;
4037
String exchange;
4138

42-
@Before public void init() {
39+
@Override
40+
protected void createResources() throws IOException, TimeoutException {
41+
super.createResources();
4342
executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
4443
queue = UUID.randomUUID().toString();
4544
exchange = UUID.randomUUID().toString();
4645
}
4746

48-
@After public void tearDown() throws IOException {
47+
@Override
48+
protected void releaseResources() throws IOException {
49+
super.releaseResources();
4950
executor.shutdownNow();
5051
channel.queueDelete(queue);
5152
channel.exchangeDelete(exchange);

src/test/java/com/rabbitmq/client/test/ChannelRpcTimeoutIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ public class ChannelRpcTimeoutIntegrationTest {
3737
ConnectionFactory factory;
3838

3939
@Before
40-
public void setUp() throws Exception {
40+
public void setUp() {
4141
factory = TestUtils.connectionFactory();
4242
}
4343

4444
@After
45-
public void tearDown() throws Exception {
45+
public void tearDown() {
4646
factory = null;
4747
}
4848

src/test/java/com/rabbitmq/client/test/ConnectionFactoryTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import com.rabbitmq.client.impl.CredentialsProvider;
2828
import com.rabbitmq.client.impl.FrameHandler;
2929
import com.rabbitmq.client.impl.FrameHandlerFactory;
30-
import org.hamcrest.Matchers;
31-
import org.junit.Assert;
3230
import org.junit.Test;
3331

3432
import java.io.IOException;

src/test/java/com/rabbitmq/client/test/RecoveryAwareAMQConnectionFactoryTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
import java.io.IOException;
3030
import java.util.Arrays;
31-
import java.util.List;
3231
import java.util.Queue;
3332
import java.util.concurrent.ArrayBlockingQueue;
3433
import java.util.concurrent.TimeoutException;

src/test/java/com/rabbitmq/client/test/RpcTopologyRecordingTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
import com.rabbitmq.client.*;
1919
import com.rabbitmq.client.impl.AMQImpl;
20-
import org.junit.After;
21-
import org.junit.Before;
2220
import org.junit.Test;
2321
import org.junit.runner.RunWith;
2422
import org.junit.runners.Parameterized;
@@ -57,8 +55,9 @@ protected ConnectionFactory newConnectionFactory() {
5755
return connectionFactory;
5856
}
5957

60-
@Before
61-
public void init() {
58+
@Override
59+
protected void createResources() throws IOException, TimeoutException {
60+
super.createResources();
6261
queue = UUID.randomUUID().toString();
6362
exchange = UUID.randomUUID().toString();
6463
routingKey = UUID.randomUUID().toString();
@@ -67,8 +66,9 @@ public void init() {
6766
routingKey2 = "e2e-" + UUID.randomUUID().toString();
6867
}
6968

70-
@After
71-
public void tearDown() throws IOException {
69+
@Override
70+
protected void releaseResources() throws IOException {
71+
super.releaseResources();
7272
channel.exchangeDelete(exchange);
7373
channel.exchangeDelete(exchange2);
7474
}

src/test/java/com/rabbitmq/client/test/TestUtils.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ public static void close(Connection connection) {
6767
}
6868
}
6969

70+
public static void abort(Connection connection) {
71+
if (connection != null) {
72+
connection.abort();
73+
}
74+
}
75+
7076
public static SSLContext getSSLContext() throws NoSuchAlgorithmException {
7177
SSLContext c = null;
7278

src/test/java/com/rabbitmq/client/test/functional/ConnectionOpen.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@
4343
*/
4444
public class ConnectionOpen {
4545
@Test public void correctProtocolHeader() throws IOException {
46-
ConnectionFactory factory = TestUtils.connectionFactory();
4746
SocketFrameHandler fh = new SocketFrameHandler(SocketFactory.getDefault().createSocket("localhost", AMQP.PROTOCOL.PORT));
4847
fh.sendHeader();
4948
AMQCommand command = new AMQCommand();
5049
while (!command.handleFrame(fh.readFrame())) { }
5150
Method m = command.getMethod();
52-
// System.out.println(m.getClass());
51+
5352
assertTrue("First command must be Connection.start",
5453
m instanceof AMQP.Connection.Start);
5554
AMQP.Connection.Start start = (AMQP.Connection.Start) m;

0 commit comments

Comments
 (0)