protected void tearDown() throws Exception {
   for (Iterator<StubConnection> iter = connections.iterator(); iter.hasNext(); ) {
     StubConnection connection = iter.next();
     connection.stop();
     iter.remove();
   }
   if (connector != null) {
     connector.stop();
   }
   super.tearDown();
 }
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    producerConnection = createConnection();
    ConnectionInfo producerConnectionInfo = createConnectionInfo();
    SessionInfo producerSessionInfo = createSessionInfo(producerConnectionInfo);
    producerInfo = createProducerInfo(producerSessionInfo);
    producerConnection.send(producerConnectionInfo);
    producerConnection.send(producerSessionInfo);
    producerConnection.send(producerInfo);

    consumerConnection = createRemoteConnection();
    ConnectionInfo consumerConnectionInfo = createConnectionInfo();
    consumerSessionInfo = createSessionInfo(consumerConnectionInfo);
    consumerConnection.send(consumerConnectionInfo);
    consumerConnection.send(consumerSessionInfo);
  }
  private Message createConsumerAndReceiveMessage(ActiveMQDestination destination)
      throws Exception {
    // Now create remote consumer that should cause message to move to this
    // remote consumer.
    ConsumerInfo consumerInfo = createConsumerInfo(consumerSessionInfo, destination);
    consumerConnection.send(consumerInfo);

    Message m = receiveMessage(consumerConnection);
    return m;
  }
  private void assertReceiveNoMessageOn(String destinationName, byte destinationType)
      throws Exception, InterruptedException {

    ActiveMQDestination destination =
        ActiveMQDestination.createDestination(destinationName, destinationType);

    // Send the message to the local broker.
    producerConnection.send(createMessage(producerInfo, destination, destinationType));

    // Make sure the message was delivered via the remote.
    Message m = createConsumerAndReceiveMessage(destination);
    assertNull(m);
  }