Skip to content

Commit

Permalink
ARTEMIS-2073 - make sure connection gets set for interceptors
Browse files Browse the repository at this point in the history
  • Loading branch information
andytaylor authored and clebertsuconic committed Sep 4, 2018
1 parent 1b9062b commit 170fa4c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Expand Up @@ -50,6 +50,7 @@ public ActiveMQProtonRemotingConnection(ProtonProtocolManager manager,
super(transportConnection, executor);
this.manager = manager;
this.amqpConnection = amqpConnection;
transportConnection.setProtocolConnection(this);
}

public Executor getExecutor() {
Expand Down
Expand Up @@ -176,4 +176,50 @@ public boolean intercept(AMQPMessage packet, RemotingConnection connection) thro
receiver.close();
connection.close();
}

@Test(timeout = 60000)
public void testCheckRemotingConnection() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final boolean[] passed = {false};
server.getRemotingService().addIncomingInterceptor(new AmqpInterceptor() {
@Override
public boolean intercept(AMQPMessage message, RemotingConnection connection) throws ActiveMQException {
passed[0] = connection != null;
latch.countDown();
return true;
}
});

AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();

AmqpSender sender = session.createSender(getTestName());
AmqpMessage message = new AmqpMessage();
message.setMessageId("msg" + 1);
message.setText("Test-Message");
sender.send(message);

assertTrue(latch.await(2, TimeUnit.SECONDS));
assertTrue("connection not set", passed[0]);

final CountDownLatch latch2 = new CountDownLatch(1);
server.getRemotingService().addOutgoingInterceptor(new AmqpInterceptor() {
@Override
public boolean intercept(AMQPMessage packet, RemotingConnection connection) throws ActiveMQException {
passed[0] = connection != null;
latch2.countDown();
return true;
}
});
AmqpReceiver receiver = session.createReceiver(getTestName());
receiver.flow(2);
AmqpMessage amqpMessage = receiver.receive(5, TimeUnit.SECONDS);
assertNotNull(amqpMessage);
assertEquals(latch2.getCount(), 0);
assertTrue("connection not set", passed[0]);
sender.close();
receiver.close();
connection.close();
}
}

0 comments on commit 170fa4c

Please sign in to comment.