Skip to content

Commit b29d8b8

Browse files
committed
Track connections left open in tests
(cherry picked from commit 3291568) Conflicts: src/test/java/com/rabbitmq/client/test/ChannelAsyncCompletableFutureTest.java src/test/java/com/rabbitmq/client/test/ConnectionFactoryTest.java src/test/java/com/rabbitmq/client/test/TestUtils.java src/test/java/com/rabbitmq/client/test/functional/ConnectionOpen.java
1 parent 4611623 commit b29d8b8

15 files changed

+82
-48
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/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

2422
import java.io.IOException;
@@ -52,8 +50,9 @@ protected ConnectionFactory newConnectionFactory() {
5250
return connectionFactory;
5351
}
5452

55-
@Before
56-
public void init() {
53+
@Override
54+
protected void createResources() throws IOException, TimeoutException {
55+
super.createResources();
5756
queue = UUID.randomUUID().toString();
5857
exchange = UUID.randomUUID().toString();
5958
routingKey = UUID.randomUUID().toString();
@@ -62,8 +61,9 @@ public void init() {
6261
routingKey2 = "e2e-" + UUID.randomUUID().toString();
6362
}
6463

65-
@After
66-
public void tearDown() throws IOException {
64+
@Override
65+
protected void releaseResources() throws IOException {
66+
super.releaseResources();
6767
channel.exchangeDelete(exchange);
6868
channel.exchangeDelete(exchange2);
6969
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ public static void close(Channel channel) {
7777
}
7878
}
7979

80+
public static void abort(Connection connection) {
81+
if (connection != null) {
82+
connection.abort();
83+
}
84+
}
85+
8086
public static SSLContext getSSLContext() throws NoSuchAlgorithmException {
8187
SSLContext c = null;
8288

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class ConnectionOpen {
4747
AMQCommand command = new AMQCommand();
4848
while (!command.handleFrame(fh.readFrame())) { }
4949
Method m = command.getMethod();
50-
// System.out.println(m.getClass());
50+
5151
assertTrue("First command must be Connection.start",
5252
m instanceof AMQP.Connection.Start);
5353
AMQP.Connection.Start start = (AMQP.Connection.Start) m;

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.rabbitmq.client.test.functional;
1818

19+
import com.rabbitmq.client.ConnectionFactory;
1920
import com.rabbitmq.client.impl.recovery.AutorecoveringConnection;
2021
import com.rabbitmq.client.test.BrokerTestCase;
2122
import org.junit.Test;
@@ -26,19 +27,19 @@
2627

2728
public class Heartbeat extends BrokerTestCase {
2829

29-
public Heartbeat()
30-
{
31-
super();
32-
connectionFactory.setRequestedHeartbeat(1);
30+
@Override
31+
protected ConnectionFactory newConnectionFactory() {
32+
ConnectionFactory cf = super.newConnectionFactory();
33+
cf.setRequestedHeartbeat(1);
34+
return cf;
3335
}
3436

35-
@Test public void heartbeat()
36-
throws IOException, InterruptedException
37-
{
37+
@Test
38+
public void heartbeat() throws InterruptedException {
3839
assertEquals(1, connection.getHeartbeat());
3940
Thread.sleep(3100);
4041
assertTrue(connection.isOpen());
41-
((AutorecoveringConnection)connection).getDelegate().setHeartbeat(0);
42+
((AutorecoveringConnection) connection).getDelegate().setHeartbeat(0);
4243
assertEquals(0, connection.getHeartbeat());
4344
Thread.sleep(3100);
4445
assertFalse(connection.isOpen());

0 commit comments

Comments
 (0)