Skip to content

Commit 4e416ae

Browse files
committed
merge default into bug18776
2 parents bee8083 + b508437 commit 4e416ae

File tree

8 files changed

+130
-131
lines changed

8 files changed

+130
-131
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 IOException {
67-
super.setUp();
68-
openConnection();
69-
openChannel();
70-
}
71-
72-
@Override protected void tearDown() throws IOException {
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 & 31 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;
@@ -42,6 +43,48 @@ public class BrokerTestCase extends TestCase
4243
public Channel channel;
4344
public int ticket;
4445

46+
protected void setUp()
47+
throws IOException
48+
{
49+
openConnection();
50+
openChannel();
51+
52+
createResources();
53+
}
54+
55+
protected void tearDown()
56+
throws IOException
57+
{
58+
closeChannel();
59+
closeConnection();
60+
61+
openConnection();
62+
openChannel();
63+
releaseResources();
64+
closeChannel();
65+
closeConnection();
66+
}
67+
68+
/**
69+
* Should create any AMQP resources needed by the test. Will be
70+
* called by BrokerTestCase's implementation of setUp, after the
71+
* connection and channel have been opened.
72+
*/
73+
protected void createResources()
74+
throws IOException
75+
{}
76+
77+
/**
78+
* Should destroy any AMQP resources that were created by the
79+
* test. Will be called by BrokerTestCase's implementation of
80+
* tearDown, after the connection and channel have been closed and
81+
* reopened specifically for this method. After this method
82+
* completes, the connection and channel will be closed again.
83+
*/
84+
protected void releaseResources()
85+
throws IOException
86+
{}
87+
4588
public void openConnection()
4689
throws IOException
4790
{
@@ -54,7 +97,7 @@ public void closeConnection()
5497
throws IOException
5598
{
5699
if (connection != null) {
57-
connection.close();
100+
connection.abort();
58101
connection = null;
59102
}
60103
}
@@ -70,37 +113,13 @@ public void closeChannel()
70113
throws IOException
71114
{
72115
if (channel != null) {
73-
channel.close();
116+
try {
117+
channel.close();
118+
} catch (AlreadyClosedException ace) {
119+
// The API is broken so we have to catch this here.
120+
// See bug 19676.
121+
}
74122
channel = null;
75123
}
76124
}
77-
78-
public void restart()
79-
throws IOException
80-
{
81-
tearDown();
82-
Host.executeCommand("cd ../rabbitmq-test; make restart-on-node");
83-
setUp();
84-
}
85-
86-
public void forceSnapshot()
87-
throws IOException, InterruptedException
88-
{
89-
Host.executeCommand("cd ../rabbitmq-test; make force-snapshot");
90-
}
91-
92-
protected void setUp()
93-
throws IOException
94-
{
95-
openConnection();
96-
openChannel();
97-
}
98-
99-
protected void tearDown()
100-
throws IOException
101-
{
102-
closeChannel();
103-
closeConnection();
104-
}
105-
106125
}

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

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

@@ -50,30 +49,26 @@ private void basicPublish()
5049
"persistent message".getBytes());
5150
}
5251

53-
public void testBind()
54-
throws IOException, Exception
55-
{
56-
boolean B = false;
52+
protected void createResources() throws IOException {
5753
// Transient exchange
5854
channel.exchangeDeclare(ticket, X, "direct", false);
5955
// durable queue
6056
channel.queueDeclare(ticket, Q, true);
61-
// 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+
{
6267
try {
6368
channel.queueBind(ticket, Q, X, "");
69+
fail("Expected exception from queueBind");
6470
} catch (IOException ee) {
65-
// Channel and connection have been closed. We need to
66-
// delete the queue below and therefore need to reconnect.
67-
super.connection=null;
68-
setUp();
69-
// Say that the expected behaviour is Ok
70-
B = true;
71+
// Pass!
7172
}
72-
channel.queueDelete(ticket, Q);
73-
channel.exchangeDelete(ticket, X);
74-
75-
assertTrue(B);
76-
7773
}
78-
7974
}

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

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

36-
protected void setUp()
37-
throws IOException
38-
{
39-
super.setUp();
36+
protected void createResources() throws IOException {
4037
channel.queueDeclare(ticket, Q);
4138
}
4239

43-
protected void tearDown()
44-
throws IOException
45-
{
40+
protected void releaseResources() throws IOException {
4641
channel.queueDelete(ticket, Q);
47-
super.tearDown();
4842
}
4943

5044
public void testNoRequeueOnCancel()

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

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

51+
protected void restart()
52+
throws IOException
53+
{
54+
tearDown();
55+
Host.executeCommand("cd ../rabbitmq-test; make restart-on-node");
56+
setUp();
57+
}
58+
59+
protected void forceSnapshot()
60+
throws IOException, InterruptedException
61+
{
62+
Host.executeCommand("cd ../rabbitmq-test; make force-snapshot");
63+
}
64+
5165
protected void declareDurableTopicExchange(String x)
5266
throws IOException
5367
{

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,22 @@ public abstract class RequeueOnClose
3838
public static final int GRATUITOUS_DELAY = 100;
3939
public static final int MESSAGE_COUNT = 2000;
4040

41-
protected void setUp() throws IOException {}
42-
43-
protected void tearDown() throws IOException {}
44-
4541
protected abstract void open() throws IOException;
4642

4743
protected abstract void close() throws IOException;
4844

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+
4957
public void injectMessage()
5058
throws IOException
5159
{

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,16 @@ public class Routing extends BrokerTestCase
3939
protected final String Q1 = "foo";
4040
protected final String Q2 = "bar";
4141

42-
protected void setUp()
43-
throws IOException
44-
{
45-
super.setUp();
42+
protected void createResources() throws IOException {
4643
channel.exchangeDeclare(ticket, E, "direct");
4744
channel.queueDeclare(ticket, Q1);
4845
channel.queueDeclare(ticket, Q2);
4946
}
5047

51-
protected void tearDown()
52-
throws IOException
53-
{
48+
protected void releaseResources() throws IOException {
5449
channel.queueDelete(ticket, Q1);
5550
channel.queueDelete(ticket, Q2);
5651
channel.exchangeDelete(ticket, E);
57-
super.tearDown();
5852
}
5953

6054
private void bind(String queue, String routingKey)

0 commit comments

Comments
 (0)