use of org.apache.activemq.transport.TransportFilter in project activemq-artemis by apache.
the class TcpTransportServerTest method hasTransportLogger.
private boolean hasTransportLogger(Transport transport) {
boolean end = false;
Transport current = transport;
while (!end) {
if (current instanceof TransportFilter) {
TransportFilter filter = (TransportFilter) current;
if (filter instanceof TransportLogger) {
return true;
}
current = filter.getNext();
} else {
end = true;
}
}
return false;
}
use of org.apache.activemq.transport.TransportFilter in project activemq-artemis by apache.
the class NetworkFailoverTest method testRequestReply.
public void testRequestReply() throws Exception {
final MessageProducer remoteProducer = remoteSession.createProducer(null);
MessageConsumer remoteConsumer = remoteSession.createConsumer(included);
remoteConsumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message msg) {
final TextMessage textMsg = (TextMessage) msg;
try {
String payload = "REPLY: " + textMsg.getText() + ", " + textMsg.getJMSMessageID();
Destination replyTo;
replyTo = msg.getJMSReplyTo();
textMsg.clearBody();
textMsg.setText(payload);
LOG.info("*** Sending response: {}", textMsg.getText());
remoteProducer.send(replyTo, textMsg);
LOG.info("replied with: " + textMsg.getJMSMessageID());
} catch (DestinationDoesNotExistException expected) {
// been removed but not yet recreated
replyToNonExistDest.incrementAndGet();
try {
LOG.info("NED: " + textMsg.getJMSMessageID());
} catch (JMSException e) {
e.printStackTrace();
}
} catch (Exception e) {
LOG.warn("*** Responder listener caught exception: ", e);
e.printStackTrace();
}
}
});
Queue tempQueue = localSession.createTemporaryQueue();
MessageProducer requestProducer = localSession.createProducer(included);
requestProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
MessageConsumer requestConsumer = localSession.createConsumer(tempQueue);
// track remote dlq for forward failures
MessageConsumer dlqconsumer = remoteSession.createConsumer(new ActiveMQQueue(SharedDeadLetterStrategy.DEFAULT_DEAD_LETTER_QUEUE_NAME));
dlqconsumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
try {
LOG.info("dlq " + message.getJMSMessageID());
} catch (JMSException e) {
e.printStackTrace();
}
remoteDLQCount.incrementAndGet();
}
});
// allow for consumer infos to perculate around
Thread.sleep(2000);
long done = System.currentTimeMillis() + (MESSAGE_COUNT * 6000);
int i = 0;
while (MESSAGE_COUNT > roundTripComplete.get() + remoteDLQCount.get() + replyToNonExistDest.get() && done > System.currentTimeMillis()) {
if (i < MESSAGE_COUNT) {
String payload = "test msg " + i;
i++;
TextMessage msg = localSession.createTextMessage(payload);
msg.setJMSReplyTo(tempQueue);
requestProducer.send(msg);
LOG.info("Sent: " + msg.getJMSMessageID() + ", Failing over");
((FailoverTransport) ((TransportFilter) ((TransportFilter) ((ActiveMQConnection) localConnection).getTransport()).getNext()).getNext()).handleTransportFailure(new IOException("Forcing failover from test"));
}
TextMessage result = (TextMessage) requestConsumer.receive(5000);
if (result != null) {
LOG.info("Got reply: " + result.getJMSMessageID() + ", " + result.getText());
roundTripComplete.incrementAndGet();
}
}
LOG.info("complete: " + roundTripComplete.get() + ", remoteDLQCount: " + remoteDLQCount.get() + ", replyToNonExistDest: " + replyToNonExistDest.get());
assertEquals("complete:" + roundTripComplete.get() + ", remoteDLQCount: " + remoteDLQCount.get() + ", replyToNonExistDest: " + replyToNonExistDest.get(), MESSAGE_COUNT, roundTripComplete.get() + remoteDLQCount.get() + replyToNonExistDest.get());
}
use of org.apache.activemq.transport.TransportFilter in project activemq-artemis by apache.
the class FanoutTransportBrokerTest method testPublisherWaitsForServerToBeUp.
/*
public void initCombosForTestPublisherWaitsForServerToBeUp() {
addCombinationValues("deliveryMode", new Object[]{Integer.valueOf(DeliveryMode.NON_PERSISTENT), Integer.valueOf(DeliveryMode.PERSISTENT)});
addCombinationValues("destination", new Object[]{new ActiveMQTopic("TEST")});
}
*/
@Test
public void testPublisherWaitsForServerToBeUp() throws Exception {
if (name.getMethodName().contains("test-0") || name.getMethodName().contains("test-2")) {
System.out.println("Discarding invalid test: " + name.getMethodName());
return;
}
// Start a normal consumer on the local broker
StubConnection connection1 = createConnection();
ConnectionInfo connectionInfo1 = createConnectionInfo();
SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
connection1.send(connectionInfo1);
connection1.send(sessionInfo1);
connection1.request(consumerInfo1);
// Start a normal consumer on a remote broker
StubConnection connection2 = createRemoteConnection();
ConnectionInfo connectionInfo2 = createConnectionInfo();
SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
connection2.send(connectionInfo2);
connection2.send(sessionInfo2);
connection2.request(consumerInfo2);
// Start a fanout publisher.
LOG.info("Starting the fanout connection.");
final StubConnection connection3 = createFanoutConnection();
ConnectionInfo connectionInfo3 = createConnectionInfo();
SessionInfo sessionInfo3 = createSessionInfo(connectionInfo3);
final ProducerInfo producerInfo3 = createProducerInfo(sessionInfo3);
connection3.send(connectionInfo3);
connection3.send(sessionInfo3);
connection3.send(producerInfo3);
// Send the message using the fail over publisher.
connection3.request(createMessage(producerInfo3, destination, deliveryMode));
Assert.assertNotNull(receiveMessage(connection1));
assertNoMessagesLeft(connection1);
Assert.assertNotNull(receiveMessage(connection2));
assertNoMessagesLeft(connection2);
final CountDownLatch publishDone = new CountDownLatch(1);
// The MockTransport is on the remote connection.
// Slip in a new transport filter after the MockTransport
MockTransport mt = connection3.getTransport().narrow(MockTransport.class);
mt.install(new TransportFilter(mt.getNext()) {
@Override
public void oneway(Object command) throws IOException {
LOG.info("Dropping: " + command);
// just eat it! to simulate a recent failure.
}
});
// Send a message (async) as this will block
new Thread() {
@Override
public void run() {
// Send the message using the fail over publisher.
try {
connection3.request(createMessage(producerInfo3, destination, deliveryMode));
} catch (Throwable e) {
e.printStackTrace();
}
publishDone.countDown();
}
}.start();
// Assert that we block:
Assert.assertFalse(publishDone.await(3, TimeUnit.SECONDS));
// Restart the remote server. State should be re-played and the publish
// should continue.
LOG.info("Restarting Broker");
restartRemoteBroker();
LOG.info("Broker Restarted");
// This should reconnect, and resend
Assert.assertTrue(publishDone.await(20, TimeUnit.SECONDS));
}
Aggregations