Unit test added.

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1183495 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2011-10-14 20:52:35 +00:00
parent baac9e7e9a
commit 9ff350033f
3 changed files with 70 additions and 14 deletions

View File

@ -183,9 +183,9 @@ public class LegacyFrameTranslator implements FrameTranslator {
String tName = name.substring("/remote-temp-topic/".length(), name.length());
return ActiveMQDestination.createDestination(tName, ActiveMQDestination.TEMP_TOPIC_TYPE);
} else if (name.startsWith("/temp-queue/")) {
return converter.createTempQueue(name);
return converter.createTempDestination(name, false);
} else if (name.startsWith("/temp-topic/")) {
return converter.createTempTopic(name);
return converter.createTempDestination(name, true);
} else {
try {
ActiveMQDestination fallback = ActiveMQDestination.getUnresolvableDestinationTransformer().transform(name);

View File

@ -774,20 +774,14 @@ public class ProtocolConverter {
return stompTransport;
}
public ActiveMQDestination createTempQueue(String name) {
public ActiveMQDestination createTempDestination(String name, boolean topic) {
ActiveMQDestination rc = tempDestinations.get(name);
if( rc == null ) {
rc = new ActiveMQTempQueue(connectionId, tempDestinationGenerator.getNextSequenceId());
sendToActiveMQ(new DestinationInfo(connectionId, DestinationInfo.ADD_OPERATION_TYPE, rc), null);
tempDestinations.put(name, rc);
}
return rc;
}
public ActiveMQDestination createTempTopic(String name) {
ActiveMQDestination rc = tempDestinations.get(name);
if( rc == null ) {
rc = new ActiveMQTempTopic(connectionId, tempDestinationGenerator.getNextSequenceId());
if (topic) {
rc = new ActiveMQTempTopic(connectionId, tempDestinationGenerator.getNextSequenceId());
} else {
rc = new ActiveMQTempQueue(connectionId, tempDestinationGenerator.getNextSequenceId());
}
sendToActiveMQ(new DestinationInfo(connectionId, DestinationInfo.ADD_OPERATION_TYPE, rc), null);
tempDestinations.put(name, rc);
tempDestinationAmqToStompMap.put(rc.getQualifiedName(), name);

View File

@ -1703,6 +1703,68 @@ public class StompTest extends CombinationTestSupport {
assertEquals(0, queueView.getQueueSize());
}
public void testReplyToDestinationNaming() throws Exception {
String frame = "CONNECT\n" + "login: system\n" + "passcode: manager\n\n" + Stomp.NULL;
stompConnection.sendFrame(frame);
frame = stompConnection.receiveFrame();
assertTrue(frame.startsWith("CONNECTED"));
doTestActiveMQReplyToTempDestination("topic");
doTestActiveMQReplyToTempDestination("queue");
}
private void doTestActiveMQReplyToTempDestination(String type) throws Exception {
LOG.info("Starting test on Temp Destinations using a temporary: " + type);
final String dest = "/" + type + "/" + getQueueName();
final String tempDest = String.format("/temp-%s/2C26441740C0ECC9tt1", type);
LOG.info("Test is using out-bound topic: " + dest + ", and replyTo dest: " + tempDest);
// Subscribe both to the out-bound destination and the response tempt destination
stompConnection.subscribe(dest);
stompConnection.subscribe(tempDest);
// Send a Message with the ReplyTo value set.
HashMap<String, String> properties = new HashMap<String, String>();
properties.put(Stomp.Headers.Send.REPLY_TO, tempDest);
LOG.info(String.format("Sending request message: SEND with %s=%s", Stomp.Headers.Send.REPLY_TO, tempDest));
stompConnection.send(dest, "REQUEST", null, properties);
// The subscription should receive a response with the ReplyTo property set.
StompFrame received = stompConnection.receive();
assertNotNull(received);
String remoteReplyTo = received.getHeaders().get(Stomp.Headers.Send.REPLY_TO);
assertNotNull(remoteReplyTo);
assertTrue(remoteReplyTo.startsWith(String.format("/temp-%s/", type)));
LOG.info(String.format("Received request message: %s with %s=%s", received.getAction(), Stomp.Headers.Send.REPLY_TO, remoteReplyTo));
// Reply to the request using the given ReplyTo destination
stompConnection.send(remoteReplyTo, "RESPONSE");
// The response should be received by the Temporary Destination subscription
StompFrame reply = stompConnection.receive();
assertNotNull(reply);
assertEquals("MESSAGE", reply.getAction());
LOG.info(String.format("Response %s received", reply.getAction()));
BrokerViewMBean broker = getProxyToBroker();
if (type.equals("topic")) {
assertEquals(1, broker.getTemporaryTopics().length);
} else {
assertEquals(1, broker.getTemporaryQueues().length);
}
}
private BrokerViewMBean getProxyToBroker() throws MalformedObjectNameException, JMSException {
ObjectName brokerViewMBean = new ObjectName(
"org.apache.activemq:Type=Broker,BrokerName=localhost");
BrokerViewMBean proxy = (BrokerViewMBean) broker.getManagementContext()
.newProxyInstance(brokerViewMBean, BrokerViewMBean.class, true);
return proxy;
}
private QueueViewMBean getProxyToQueue(String name) throws MalformedObjectNameException, JMSException {
ObjectName queueViewMBeanName = new ObjectName("org.apache.activemq"
+ ":Type=Queue,Destination=" + name