Skip to content

Commit

Permalink
merge bug 20729
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Sackman committed May 18, 2009
2 parents c214a04 + bb24503 commit 0d7acfc
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 18 deletions.
70 changes: 53 additions & 17 deletions test/src/com/rabbitmq/client/test/functional/BindingLifecycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,18 @@
import com.rabbitmq.client.GetResponse;
import com.rabbitmq.client.QueueingConsumer;

import com.rabbitmq.tools.Host;

import java.io.IOException;

/**
* This tests whether bindings are created and nuked properly.
*
* The tests attempt to declare durable queues on a secondary node, if
* present, and that node is restarted as part of the tests while the
* primary node is still running. That way we exercise any node-down
* handler code in the server.
*
* TODO: Adjust this test when Queue.Unbind is implemented in the
* server
*/
Expand All @@ -55,27 +62,56 @@ public class BindingLifecycle extends PersisterRestartBase {
protected static final String X = "X-" + System.currentTimeMillis();
protected static final String K = "K-" + System.currentTimeMillis();

/**
* Create a durable queue on secondary node, if possible, falling
* back on the primary node if necessary.
*/
@Override protected void declareDurableQueue(String q)
throws IOException
{
Connection connection;
try {
connection = connectionFactory.newConnection("localhost", 5673);
} catch (IOException e) {
super.declareDurableQueue(q);
return;
public Connection secondaryConnection;
public Channel secondaryChannel;

@Override public void openConnection() throws IOException {
super.openConnection();
if (secondaryConnection == null) {
try {
secondaryConnection = connectionFactory.newConnection("localhost", 5673);
} catch (IOException e) {
// just use a single node
}
}
}

Channel channel = connection.createChannel();
@Override public void closeConnection() throws IOException {
if (secondaryConnection != null) {
secondaryConnection.abort();
secondaryConnection = null;
}
super.closeConnection();
}

channel.queueDeclare(q, true);
@Override public void openChannel() throws IOException {
if (secondaryConnection != null) {
secondaryChannel = secondaryConnection.createChannel();
}
super.openChannel();
}

@Override public void closeChannel() throws IOException {
if (secondaryChannel != null) {
secondaryChannel.abort();
secondaryChannel = null;
}
super.closeChannel();
}

@Override protected void restart() throws IOException {
if (secondaryConnection != null) {
secondaryConnection.abort();
secondaryConnection = null;
secondaryChannel = null;
Host.executeCommand("cd ../rabbitmq-test; make restart-secondary-node");
}
super.restart();
}

channel.abort();
connection.abort();
@Override protected void declareDurableQueue(String q) throws IOException {
(secondaryChannel == null ? channel : secondaryChannel).
queueDeclare(q, true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected void restart()
throws IOException
{
tearDown();
Host.executeCommand("cd ../rabbitmq-test; make restart-on-node");
Host.executeCommand("cd ../rabbitmq-test; make restart-app");
setUp();
}

Expand Down

0 comments on commit 0d7acfc

Please sign in to comment.