Skip to content

Commit b508437

Browse files
author
Matthias Radestock
committed
merbe bug19672 into default
2 parents a456b7d + 61f969e commit b508437

File tree

8 files changed

+117
-133
lines changed

8 files changed

+117
-133
lines changed

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,6 @@ public class Bug19219Test extends BrokerTestCase {
6363
private static final Semaphore init = new Semaphore(0);
6464
private static final CountDownLatch resume = new CountDownLatch(1);
6565

66-
@Override protected void setUp() throws Exception {
67-
super.setUp();
68-
openConnection();
69-
openChannel();
70-
}
71-
72-
@Override protected void tearDown() throws Exception {
73-
closeChannel();
74-
closeConnection();
75-
super.tearDown();
76-
}
77-
7866
public static TestSuite suite() {
7967
TestSuite suite = new TestSuite("Bug19219");
8068
suite.addTestSuite(Bug19219Test.class);

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

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import junit.framework.TestCase;
3131

32+
import com.rabbitmq.client.AlreadyClosedException;
3233
import com.rabbitmq.client.Channel;
3334
import com.rabbitmq.client.Connection;
3435
import com.rabbitmq.client.ConnectionFactory;
@@ -41,6 +42,48 @@ public class BrokerTestCase extends TestCase
4142
public Channel channel;
4243
public int ticket;
4344

45+
protected void setUp()
46+
throws IOException
47+
{
48+
openConnection();
49+
openChannel();
50+
51+
createResources();
52+
}
53+
54+
protected void tearDown()
55+
throws IOException
56+
{
57+
closeChannel();
58+
closeConnection();
59+
60+
openConnection();
61+
openChannel();
62+
releaseResources();
63+
closeChannel();
64+
closeConnection();
65+
}
66+
67+
/**
68+
* Should create any AMQP resources needed by the test. Will be
69+
* called by BrokerTestCase's implementation of setUp, after the
70+
* connection and channel have been opened.
71+
*/
72+
protected void createResources()
73+
throws IOException
74+
{}
75+
76+
/**
77+
* Should destroy any AMQP resources that were created by the
78+
* test. Will be called by BrokerTestCase's implementation of
79+
* tearDown, after the connection and channel have been closed and
80+
* reopened specifically for this method. After this method
81+
* completes, the connection and channel will be closed again.
82+
*/
83+
protected void releaseResources()
84+
throws IOException
85+
{}
86+
4487
public void openConnection()
4588
throws IOException
4689
{
@@ -53,7 +96,7 @@ public void closeConnection()
5396
throws IOException
5497
{
5598
if (connection != null) {
56-
connection.close();
99+
connection.abort();
57100
connection = null;
58101
}
59102
}
@@ -69,7 +112,12 @@ public void closeChannel()
69112
throws IOException
70113
{
71114
if (channel != null) {
72-
channel.close();
115+
try {
116+
channel.close();
117+
} catch (AlreadyClosedException ace) {
118+
// The API is broken so we have to catch this here.
119+
// See bug 19676.
120+
}
73121
channel = null;
74122
}
75123
}

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

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,9 @@
3232

3333
public class DurableOnTransient extends BrokerTestCase
3434
{
35-
3635
protected static final String Q = "DurableQueue";
3736
protected static final String X = "TransientExchange";
3837

39-
protected void setUp()
40-
throws IOException
41-
{
42-
openConnection();
43-
openChannel();
44-
}
45-
46-
protected void tearDown()
47-
throws IOException
48-
{
49-
closeChannel();
50-
closeConnection();
51-
}
52-
5338
private GetResponse basicGet()
5439
throws IOException
5540
{
@@ -64,30 +49,26 @@ private void basicPublish()
6449
"persistent message".getBytes());
6550
}
6651

67-
public void testBind()
68-
throws IOException, Exception
69-
{
70-
boolean B = false;
52+
protected void createResources() throws IOException {
7153
// Transient exchange
7254
channel.exchangeDeclare(ticket, X, "direct", false);
7355
// durable queue
7456
channel.queueDeclare(ticket, Q, true);
75-
// The following should raise an exception
57+
}
58+
59+
protected void releaseResources() throws IOException {
60+
channel.queueDelete(ticket, Q);
61+
channel.exchangeDelete(ticket, X);
62+
}
63+
64+
public void testBind()
65+
throws IOException
66+
{
7667
try {
7768
channel.queueBind(ticket, Q, X, "");
69+
fail("Expected exception from queueBind");
7870
} catch (IOException ee) {
79-
// Channel and connection have been closed. We need to
80-
// delete the queue below and therefore need to reconnect.
81-
super.connection=null;
82-
setUp();
83-
// Say that the expected behaviour is Ok
84-
B = true;
71+
// Pass!
8572
}
86-
channel.queueDelete(ticket, Q);
87-
channel.exchangeDelete(ticket, X);
88-
89-
assertTrue(B);
90-
9173
}
92-
9374
}

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,12 @@ public class NoRequeueOnCancel extends BrokerTestCase
3333
{
3434
protected final String Q = "NoRequeueOnCancel";
3535

36-
protected void setUp()
37-
throws IOException
38-
{
39-
openConnection();
40-
openChannel();
36+
protected void createResources() throws IOException {
4137
channel.queueDeclare(ticket, Q);
4238
}
4339

44-
protected void tearDown()
45-
throws IOException
46-
{
40+
protected void releaseResources() throws IOException {
4741
channel.queueDelete(ticket, Q);
48-
closeChannel();
49-
closeConnection();
5042
}
5143

5244
public void testNoRequeueOnCancel()

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,6 @@ public class PersisterRestartBase extends BrokerTestCase
4848
// rabbit_persister.erl
4949
protected final int PERSISTER_SNAPSHOT_THRESHOLD = 500;
5050

51-
protected void setUp()
52-
throws IOException
53-
{
54-
openConnection();
55-
openChannel();
56-
}
57-
58-
protected void tearDown()
59-
throws IOException
60-
{
61-
closeChannel();
62-
closeConnection();
63-
}
64-
6551
protected void restart()
6652
throws IOException
6753
{

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ public abstract class RequeueOnClose
4242

4343
protected abstract void close() throws IOException;
4444

45+
protected void setUp()
46+
throws IOException
47+
{
48+
// Override to disable the default behaviour from BrokerTestCase.
49+
}
50+
51+
protected void tearDown()
52+
throws IOException
53+
{
54+
// Override to disable the default behaviour from BrokerTestCase.
55+
}
56+
4557
public void injectMessage()
4658
throws IOException
4759
{

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,16 @@ public class Routing extends BrokerTestCase
3737
protected final String Q1 = "foo";
3838
protected final String Q2 = "bar";
3939

40-
protected void setUp()
41-
throws IOException
42-
{
43-
openConnection();
44-
openChannel();
40+
protected void createResources() throws IOException {
4541
channel.exchangeDeclare(ticket, E, "direct");
4642
channel.queueDeclare(ticket, Q1);
4743
channel.queueDeclare(ticket, Q2);
4844
}
4945

50-
protected void tearDown()
51-
throws IOException
52-
{
46+
protected void releaseResources() throws IOException {
5347
channel.queueDelete(ticket, Q1);
5448
channel.queueDelete(ticket, Q2);
5549
channel.exchangeDelete(ticket, E);
56-
closeChannel();
57-
closeConnection();
5850
}
5951

6052
private void bind(String queue, String routingKey)

0 commit comments

Comments
 (0)