Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7DEDD17351 for ; Wed, 7 Oct 2015 09:42:18 +0000 (UTC) Received: (qmail 5240 invoked by uid 500); 7 Oct 2015 09:42:18 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 5201 invoked by uid 500); 7 Oct 2015 09:42:18 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 5192 invoked by uid 99); 7 Oct 2015 09:42:18 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Oct 2015 09:42:18 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E7DC6E00AF; Wed, 7 Oct 2015 09:42:17 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dejanb@apache.org To: commits@activemq.apache.org Message-Id: <3fbbc33c560c4122be5191f7ebe9e087@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: activemq git commit: https://issues.apache.org/jira/browse/AMQ-6002 - escape client id in virtual topic mqtt subscription; add test Date: Wed, 7 Oct 2015 09:42:17 +0000 (UTC) Repository: activemq Updated Branches: refs/heads/master aa743cbd7 -> 816e8dfe5 https://issues.apache.org/jira/browse/AMQ-6002 - escape client id in virtual topic mqtt subscription; add test Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/816e8dfe Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/816e8dfe Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/816e8dfe Branch: refs/heads/master Commit: 816e8dfe5413cf9316bf1946afe6f236d85f8351 Parents: aa743cb Author: Dejan Bosanac Authored: Wed Oct 7 11:42:03 2015 +0200 Committer: Dejan Bosanac Committed: Wed Oct 7 11:42:03 2015 +0200 ---------------------------------------------------------------------- .../mqtt/PahoVirtualTopicMQTTTest.java | 86 ++++++++++++++++++++ 1 file changed, 86 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/816e8dfe/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/PahoVirtualTopicMQTTTest.java ---------------------------------------------------------------------- diff --git a/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/PahoVirtualTopicMQTTTest.java b/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/PahoVirtualTopicMQTTTest.java new file mode 100644 index 0000000..5f58202 --- /dev/null +++ b/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/PahoVirtualTopicMQTTTest.java @@ -0,0 +1,86 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.transport.mqtt; + +import org.apache.activemq.broker.region.Destination; +import org.apache.activemq.broker.region.RegionBroker; +import org.apache.activemq.command.ActiveMQQueue; +import org.eclipse.paho.client.mqttv3.MqttClient; +import org.eclipse.paho.client.mqttv3.MqttConnectOptions; +import org.junit.Before; +import org.junit.Test; + +import javax.jms.MessageConsumer; +import javax.jms.Session; + +import static org.junit.Assert.assertEquals; + +public class PahoVirtualTopicMQTTTest extends PahoMQTTTest { + + @Override + @Before + public void setUp() throws Exception { + protocolConfig = "transport.subscriptionStrategy=mqtt-virtual-topic-subscriptions"; + super.setUp(); + } + + @Override + protected MessageConsumer createConsumer(Session s, String topic) throws Exception { + return s.createConsumer(s.createQueue("Consumer.X.VirtualTopic." + topic)); + } + + @Test(timeout = 300000) + public void testVirtualTopicQueueRestore() throws Exception { + String user10 = "user10"; + String password10 = "user10"; + String clientId10 = "client-10"; + String topic10 = "user10/"; + MqttConnectOptions options10 = new MqttConnectOptions(); + options10.setCleanSession(false); + options10.setUserName(user10); + options10.setPassword(password10.toCharArray()); + MqttClient client10 = createClient(false, clientId10, null); + client10.subscribe(topic10 + clientId10 + "/#", 1); + client10.subscribe(topic10 + "#", 1); + + String user1 = "user1"; + String password1 = "user1"; + String clientId1 = "client-1"; + String topic1 = "user1/"; + MqttConnectOptions options1 = new MqttConnectOptions(); + options1.setCleanSession(false); + options1.setUserName(user1); + options1.setPassword(password1.toCharArray()); + + MqttClient client1 = createClient(false, clientId1, null); + client1.subscribe(topic1 + clientId1 + "/#", 1); + client1.subscribe(topic1 + "#", 1); + + RegionBroker regionBroker = (RegionBroker) brokerService.getBroker().getAdaptor(RegionBroker.class); + + String[] queues = new String[]{"Consumer.client-10:AT_LEAST_ONCE.VirtualTopic.user10.>", + "Consumer.client-10:AT_LEAST_ONCE.VirtualTopic.user10.client-10.>", + "Consumer.client-1:AT_LEAST_ONCE.VirtualTopic.user1.>", + "Consumer.client-1:AT_LEAST_ONCE.VirtualTopic.user1.client-1.>"}; + + for (String queueName : queues) { + Destination queue = regionBroker.getQueueRegion().getDestinations(new ActiveMQQueue(queueName)).iterator().next(); + assertEquals("Queue " + queueName + " have more than one consumer", 1, queue.getConsumers().size()); + } + } + +}