This commit is contained in:
Clebert Suconic 2020-10-29 11:17:36 -04:00
commit 5257c08d74
10 changed files with 123 additions and 21 deletions

View File

@ -131,9 +131,8 @@ public class LinkedListImpl<E> implements LinkedList<E> {
return null; return null;
} }
if (node.prev != null) { // the node will always have a prev element
removeAfter(node.prev); removeAfter(node.prev);
}
return node.val(); return node.val();
} }

View File

@ -36,6 +36,7 @@ import org.apache.activemq.artemis.core.paging.PagingManager;
import org.apache.activemq.artemis.core.paging.PagingStore; import org.apache.activemq.artemis.core.paging.PagingStore;
import org.apache.activemq.artemis.core.persistence.OperationContext; import org.apache.activemq.artemis.core.persistence.OperationContext;
import org.apache.activemq.artemis.core.persistence.StorageManager; import org.apache.activemq.artemis.core.persistence.StorageManager;
import org.apache.activemq.artemis.core.postoffice.Bindings;
import org.apache.activemq.artemis.core.security.CheckType; import org.apache.activemq.artemis.core.security.CheckType;
import org.apache.activemq.artemis.core.security.SecurityAuth; import org.apache.activemq.artemis.core.security.SecurityAuth;
import org.apache.activemq.artemis.core.server.AddressQueryResult; import org.apache.activemq.artemis.core.server.AddressQueryResult;
@ -346,7 +347,11 @@ public class AMQPSessionCallback implements SessionCallback {
} }
} else if (routingType == RoutingType.ANYCAST) { } else if (routingType == RoutingType.ANYCAST) {
if (manager.getServer().locateQueue(unPrefixedAddress) == null) { if (manager.getServer().locateQueue(unPrefixedAddress) == null) {
if (addressSettings.isAutoCreateQueues()) { Bindings bindings = manager.getServer().getPostOffice().lookupBindingsForAddress(address);
if (bindings != null) {
// this means the address has another queue with a different name, which is fine, we just ignore it on this case
result = true;
} else if (addressSettings.isAutoCreateQueues()) {
try { try {
serverSession.createQueue(new QueueConfiguration(address).setRoutingType(routingType).setAutoCreated(true)); serverSession.createQueue(new QueueConfiguration(address).setRoutingType(routingType).setAutoCreated(true));
} catch (ActiveMQQueueExistsException e) { } catch (ActiveMQQueueExistsException e) {

View File

@ -102,7 +102,7 @@ under the License.
<spawn>true</spawn> <spawn>true</spawn>
<ignore>${noServer}</ignore> <ignore>${noServer}</ignore>
<location>${basedir}/target/server0</location> <location>${basedir}/target/server0</location>
<testURI>tcp://localhost:5660</testURI> <testURI>tcp://localhost:5671</testURI>
<args> <args>
<param>run</param> <param>run</param>
</args> </args>

View File

@ -35,7 +35,7 @@ public class BrokerConnectionSenderSSL {
public static void main(final String[] args) throws Exception { public static void main(final String[] args) throws Exception {
Connection connectionOnServer0 = null; Connection connectionOnServer0 = null;
ConnectionFactory connectionFactoryServer0 = new JmsConnectionFactory("amqp://localhost:5660"); ConnectionFactory connectionFactoryServer0 = new JmsConnectionFactory("amqps://localhost:5672?transport.trustStoreLocation=target/server0/etc/activemq.example.truststore&transport.trustStorePassword=activemqexample&transport.verifyHost=false");
// Step 1. Create a connection on server0, and send a few messages // Step 1. Create a connection on server0, and send a few messages
try { try {
@ -50,7 +50,7 @@ public class BrokerConnectionSenderSSL {
sender.send(session.createTextMessage("Hello world overSSL n" + i)); sender.send(session.createTextMessage("Hello world overSSL n" + i));
} }
} finally { } finally {
if (connectionFactoryServer0 != null) { if (connectionOnServer0 != null) {
connectionOnServer0.close(); connectionOnServer0.close();
} }
} }
@ -58,7 +58,7 @@ public class BrokerConnectionSenderSSL {
// Step 2. create a connection on server1, and receive a few messages. // Step 2. create a connection on server1, and receive a few messages.
// the sender on the broker conneciton will take care of the transfer. // the sender on the broker conneciton will take care of the transfer.
Connection connectionOnServer1 = null; Connection connectionOnServer1 = null;
ConnectionFactory connectionFactoryServer1 = new JmsConnectionFactory("amqp://localhost:5771"); ConnectionFactory connectionFactoryServer1 = new JmsConnectionFactory("amqps://localhost:5772?transport.trustStoreLocation=target/server1/etc/activemq.example.truststore&transport.trustStorePassword=activemqexample&transport.verifyHost=false");
try { try {
connectionOnServer1 = connectionFactoryServer1.createConnection(); connectionOnServer1 = connectionFactoryServer1.createConnection();

View File

@ -31,7 +31,8 @@ under the License.
<!-- Acceptors --> <!-- Acceptors -->
<acceptors> <acceptors>
<!-- keystores will be found automatically if they are on the classpath --> <!-- keystores will be found automatically if they are on the classpath -->
<acceptor name="artemis">tcp://0.0.0.0:5660?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;amqpMinLargeMessageSize=102400;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT,OPENWIRE;useEpoll=true;amqpCredits=1000;amqpLowCredits=300;amqpDuplicateDetection=true</acceptor> <acceptor name="artemis">tcp://0.0.0.0:5671?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;amqpMinLargeMessageSize=102400;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT,OPENWIRE;useEpoll=true;amqpCredits=1000;amqpLowCredits=300;amqpDuplicateDetection=true</acceptor>
<acceptor name="netty-ssl-acceptor">tcp://localhost:5672?sslEnabled=true;keyStorePath=activemq.example.keystore;keyStorePassword=activemqexample;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT,OPENWIRE</acceptor>
</acceptors> </acceptors>
<broker-connections> <broker-connections>

View File

@ -0,0 +1,75 @@
/*
* 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.artemis.tests.integration.amqp;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.artemis.api.core.QueueConfiguration;
import org.apache.activemq.artemis.api.core.RoutingType;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.impl.AddressInfo;
import org.apache.activemq.artemis.tests.util.CFUtil;
import org.junit.Assert;
import org.junit.Test;
/**
* Make sure auto create will not create a queue when the queue and its address have a distinct name in anycast.
*/
public class AmqpAnyCastDistinctQueueTest extends AmqpClientTestSupport {
@Override
protected void addAdditionalAcceptors(ActiveMQServer server) throws Exception {
}
@Test(timeout = 60000)
public void testDistinctQueueAddressAnyCast() throws Exception {
String ADDRESS_NAME = "DISTINCT_ADDRESS_testDistinctAddressAnyCast";
String QUEUE_NAME = "DISTINCT_QUEUE_testDistinctQUEUE_AnyCast";
server.addAddressInfo(new AddressInfo(ADDRESS_NAME).setAutoCreated(false).addRoutingType(RoutingType.ANYCAST));
server.createQueue(new QueueConfiguration(QUEUE_NAME).setAddress(ADDRESS_NAME).setDurable(true).setRoutingType(RoutingType.ANYCAST));
final int NUMBER_OF_MESSAGES = 100;
ConnectionFactory jmsCF = CFUtil.createConnectionFactory("AMQP", "tcp://localhost:" + AMQP_PORT);
try (Connection connection = jmsCF.createConnection()) {
Session session = connection.createSession();
Queue queueSending = session.createQueue(ADDRESS_NAME);
MessageProducer producer = session.createProducer(queueSending);
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
producer.send(session.createTextMessage("hello " + i));
}
Queue queueReceiving = session.createQueue(QUEUE_NAME);
connection.start();
MessageConsumer consumer = session.createConsumer(queueReceiving);
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
TextMessage message = (TextMessage)consumer.receive(5000);
Assert.assertNotNull(message);
Assert.assertEquals("hello " + i, message.getText());
}
Assert.assertNull(consumer.receiveNoWait());
}
}
}

View File

@ -36,6 +36,7 @@ import org.apache.activemq.artemis.core.postoffice.Bindings;
import org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding; import org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding;
import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.QueueQueryResult; import org.apache.activemq.artemis.core.server.QueueQueryResult;
import org.apache.activemq.artemis.core.server.impl.AddressInfo;
import org.apache.activemq.artemis.core.settings.impl.AddressSettings; import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
import org.apache.activemq.artemis.tests.util.Wait; import org.apache.activemq.artemis.tests.util.Wait;
import org.apache.activemq.artemis.utils.CompositeAddress; import org.apache.activemq.artemis.utils.CompositeAddress;
@ -278,7 +279,12 @@ public class AmqpFullyQualifiedNameTest extends JMSClientTestSupport {
@Test @Test
public void testQueue() throws Exception { public void testQueue() throws Exception {
server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateQueues(true).setAutoCreateAddresses(true)); server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateQueues(false).setAutoCreateAddresses(false));
server.addAddressInfo(new AddressInfo(anycastAddress).addRoutingType(RoutingType.ANYCAST).setAutoCreated(false));
server.createQueue(new QueueConfiguration(anycastQ1).setAddress(anycastAddress).setRoutingType(RoutingType.ANYCAST).setDurable(true));
server.createQueue(new QueueConfiguration(anycastQ2).setAddress(anycastAddress).setRoutingType(RoutingType.ANYCAST).setDurable(true));
server.createQueue(new QueueConfiguration(anycastQ3).setAddress(anycastAddress).setRoutingType(RoutingType.ANYCAST).setDurable(true));
Connection connection = createConnection(); Connection connection = createConnection();
try { try {

View File

@ -668,7 +668,6 @@ public class AMQPReplicaTest extends AmqpClientTestSupport {
for (int i = START_ID; i <= LAST_ID; i++) { for (int i = START_ID; i <= LAST_ID; i++) {
Message message = consumer.receive(3000); Message message = consumer.receive(3000);
Assert.assertNotNull(message); Assert.assertNotNull(message);
System.out.println("port " + port + ",i::" + message.getIntProperty("i"));
Assert.assertEquals(i, message.getIntProperty("i")); Assert.assertEquals(i, message.getIntProperty("i"));
if (message instanceof TextMessage) { if (message instanceof TextMessage) {
Assert.assertEquals(getText(largeMessage, i), ((TextMessage) message).getText()); Assert.assertEquals(getText(largeMessage, i), ((TextMessage) message).getText());

View File

@ -81,17 +81,22 @@ public class QpidDispatchPeerTest extends AmqpClientTestSupport {
qpidProcess.kill(); qpidProcess.kill();
} }
@Test(timeout = 60_000)
public void testWithMatchingDifferentNamesOnQueue() throws Exception {
internalMultipleQueues(true, true);
}
@Test(timeout = 60_000) @Test(timeout = 60_000)
public void testWithMatching() throws Exception { public void testWithMatching() throws Exception {
internalMultipleQueues(true); internalMultipleQueues(true, false);
} }
@Test(timeout = 60_000) @Test(timeout = 60_000)
public void testwithQueueName() throws Exception { public void testwithQueueName() throws Exception {
internalMultipleQueues(false); internalMultipleQueues(false, true);
} }
private void internalMultipleQueues(boolean useMatching) throws Exception { private void internalMultipleQueues(boolean useMatching, boolean distinctNaming) throws Exception {
final int numberOfMessages = 100; final int numberOfMessages = 100;
final int numberOfQueues = 10; final int numberOfQueues = 10;
AMQPBrokerConnectConfiguration amqpConnection = new AMQPBrokerConnectConfiguration("test", "tcp://localhost:24621").setRetryInterval(10).setReconnectAttempts(-1); AMQPBrokerConnectConfiguration amqpConnection = new AMQPBrokerConnectConfiguration("test", "tcp://localhost:24621").setRetryInterval(10).setReconnectAttempts(-1);
@ -99,14 +104,14 @@ public class QpidDispatchPeerTest extends AmqpClientTestSupport {
amqpConnection.addElement(new AMQPBrokerConnectionElement().setMatchAddress("queue.#").setType(AMQPBrokerConnectionAddressType.PEER)); amqpConnection.addElement(new AMQPBrokerConnectionElement().setMatchAddress("queue.#").setType(AMQPBrokerConnectionAddressType.PEER));
} else { } else {
for (int i = 0; i < numberOfQueues; i++) { for (int i = 0; i < numberOfQueues; i++) {
amqpConnection.addElement(new AMQPBrokerConnectionElement().setQueueName("queue.test" + i).setType(AMQPBrokerConnectionAddressType.PEER)); amqpConnection.addElement(new AMQPBrokerConnectionElement().setQueueName(createQueueName(i, distinctNaming)).setType(AMQPBrokerConnectionAddressType.PEER));
} }
} }
server.getConfiguration().addAMQPConnection(amqpConnection); server.getConfiguration().addAMQPConnection(amqpConnection);
server.start(); server.start();
for (int i = 0; i < numberOfQueues; i++) { for (int i = 0; i < numberOfQueues; i++) {
server.addAddressInfo(new AddressInfo("queue.test" + i).addRoutingType(RoutingType.ANYCAST).setAutoCreated(false).setTemporary(false)); server.addAddressInfo(new AddressInfo("queue.test" + i).addRoutingType(RoutingType.ANYCAST).setAutoCreated(false).setTemporary(false));
server.createQueue(new QueueConfiguration("queue.test" + i).setAddress("queue.test" + i).setRoutingType(RoutingType.ANYCAST)); server.createQueue(new QueueConfiguration(createQueueName(i, distinctNaming)).setAddress("queue.test" + i).setRoutingType(RoutingType.ANYCAST));
} }
for (int dest = 0; dest < numberOfQueues; dest++) { for (int dest = 0; dest < numberOfQueues; dest++) {
@ -120,7 +125,7 @@ public class QpidDispatchPeerTest extends AmqpClientTestSupport {
MessageProducer producer = session.createProducer(queue); MessageProducer producer = session.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
org.apache.activemq.artemis.core.server.Queue testQueueOnServer = server.locateQueue("queue.test" + dest); org.apache.activemq.artemis.core.server.Queue testQueueOnServer = server.locateQueue(createQueueName(dest, distinctNaming));
for (int i = 0; i < numberOfMessages; i++) { for (int i = 0; i < numberOfMessages; i++) {
producer.send(session.createTextMessage("hello " + i)); producer.send(session.createTextMessage("hello " + i));
@ -130,8 +135,6 @@ public class QpidDispatchPeerTest extends AmqpClientTestSupport {
connection.close(); connection.close();
} }
System.out.println("*******************************************************************************************************************************");
System.out.println("Creating consumer");
for (int dest = 0; dest < numberOfQueues; dest++) { for (int dest = 0; dest < numberOfQueues; dest++) {
ConnectionFactory factoryConsumer = CFUtil.createConnectionFactory("AMQP", "tcp://localhost:24622"); ConnectionFactory factoryConsumer = CFUtil.createConnectionFactory("AMQP", "tcp://localhost:24622");
@ -151,7 +154,6 @@ public class QpidDispatchPeerTest extends AmqpClientTestSupport {
System.out.println("*******************************************************************************************************************************"); System.out.println("*******************************************************************************************************************************");
} }
Assert.assertNotNull(received); Assert.assertNotNull(received);
System.out.println("message " + received.getText());
Assert.assertEquals("hello " + i, received.getText()); Assert.assertEquals("hello " + i, received.getText());
} }
Assert.assertNull(consumer.receiveNoWait()); Assert.assertNull(consumer.receiveNoWait());
@ -162,12 +164,20 @@ public class QpidDispatchPeerTest extends AmqpClientTestSupport {
} }
} }
org.apache.activemq.artemis.core.server.Queue testQueueOnServer = server.locateQueue("queue.test" + dest); org.apache.activemq.artemis.core.server.Queue testQueueOnServer = server.locateQueue(createQueueName(dest, distinctNaming));
Wait.assertEquals(0, testQueueOnServer::getMessageCount); Wait.assertEquals(0, testQueueOnServer::getMessageCount);
} }
} }
private String createQueueName(int i, boolean useDistinctName) {
if (useDistinctName) {
return "distinct.test" + i;
} else {
return "queue.test" + i;
}
}
private Connection createConnectionDumbRetry(ConnectionFactory factoryProducer, private Connection createConnectionDumbRetry(ConnectionFactory factoryProducer,
Connection connection) throws InterruptedException { Connection connection) throws InterruptedException {
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {

View File

@ -202,6 +202,13 @@ public class LinkedListTest extends ActiveMQTestBase {
if (deferSupplier) { if (deferSupplier) {
Assert.assertEquals(0, objs.getSizeOfSuppliedIDs()); Assert.assertEquals(0, objs.getSizeOfSuppliedIDs());
objs.setIDSupplier(source -> source.id); objs.setIDSupplier(source -> source.id);
} else {
// clear the ID supplier
objs.clearID();
// and redo it
Assert.assertEquals(0, objs.getSizeOfSuppliedIDs());
objs.setIDSupplier(source -> source.id);
Assert.assertEquals(1000, objs.size());
} }
Assert.assertEquals(1000, objs.getSizeOfSuppliedIDs()); Assert.assertEquals(1000, objs.getSizeOfSuppliedIDs());