[ 
https://issues.apache.org/jira/browse/ARTEMIS-6056?focusedWorklogId=1020153&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1020153
 ]

ASF GitHub Bot logged work on ARTEMIS-6056:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 14/May/26 05:11
            Start Date: 14/May/26 05:11
    Worklog Time Spent: 10m 
      Work Description: brusdev commented on code in PR #6438:
URL: https://github.com/apache/artemis/pull/6438#discussion_r3239209615


##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/paging/WildcardRouteTest.java:
##########
@@ -0,0 +1,315 @@
+/*
+ * 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.paging;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import java.lang.invoke.MethodHandles;
+import java.util.function.Predicate;
+
+import org.apache.activemq.artemis.api.core.ActiveMQException;
+import org.apache.activemq.artemis.api.core.QueueConfiguration;
+import org.apache.activemq.artemis.api.core.RoutingType;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.api.core.client.ClientSession;
+import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
+import org.apache.activemq.artemis.api.core.client.ServerLocator;
+import org.apache.activemq.artemis.core.paging.PagingStore;
+import org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl;
+import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.core.server.Queue;
+import org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy;
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
+import org.apache.activemq.artemis.tests.util.CFUtil;
+import org.apache.activemq.artemis.tests.util.Wait;
+import org.apache.activemq.artemis.utils.SizeAwareMetric;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class WildcardRouteTest extends ActiveMQTestBase {
+
+   private static final Logger logger = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+   protected ActiveMQServer server;
+   protected ClientSession session;
+   protected ClientSessionFactory sf;
+   protected ServerLocator locator;
+
+   final String addressToSend = "a.b.c.d.e.f.g";
+   final String[] queueToReceive = new String[]{"a.b.c.d.e.f.g", 
"a.b.c.d.e.f.*", "a.b.c.d.e.*.*", "a.b.c.d.*.*.*", "a.b.c.*.*.*.*", 
"a.b.*.*.*.*.*", "a.*.*.*.*.*.*"};
+   final String addressSettingsMatch = "a.#";
+
+   @Override
+   @BeforeEach
+   public void setUp() throws Exception {
+      super.setUp();
+      server = createServer(true, createDefaultNettyConfig());
+      server.start();
+      locator = createInVMNonHALocator();
+      sf = createSessionFactory(locator);
+      session = addClientSession(sf.createSession(false, true, true));
+   }
+
+   public void printSizes() throws Exception {
+      SimpleString[] stores = server.getPagingManager().getStoreNames();
+
+      for (SimpleString q : stores) {
+         PagingStore store = server.getPagingManager().getPageStore(q);
+         logger.debug("Store {} has {} elements and {}", store.getAddress(), 
store.getAddressElements(), store.getAddressSize());
+      }
+   }
+
+   public void printHierarchy() throws Exception {
+      for (String q : queueToReceive) {
+         PagingStoreImpl store = 
(PagingStoreImpl)server.getPagingManager().lookupPageStore(SimpleString.of(q));
+         if (store == null) {
+            logger.info("no address for {}", q);
+         } else {
+            logger.info("hierarchy from {}/{}:\n {}", q, 
store.getSizeMetric(), store.getSizeMetric().debugHierarchy());
+         }
+      }
+   }
+
+   @Test
+   public void testInvalidWildcard() throws Exception {
+
+      server.getAddressSettingsRepository().addMatch(addressSettingsMatch, new 
AddressSettings().setMaxSizeMessages(100_000).setAddressFullMessagePolicy(AddressFullMessagePolicy.FAIL));
+
+      ConnectionFactory factory = CFUtil.createConnectionFactory("CORE", 
"tcp://localhost:61616");
+
+      session.createAddress(SimpleString.of(addressToSend), 
RoutingType.MULTICAST, false);
+      for (String q : queueToReceive) {
+         
session.createQueue(QueueConfiguration.of(q).setRoutingType(RoutingType.MULTICAST).setAddress(q));
+      }
+
+      assertThrows(Exception.class, () -> {
+         try (Connection connection = factory.createConnection()) {
+            Session session = connection.createSession(true, 
Session.SESSION_TRANSACTED);
+            MessageProducer producer = 
session.createProducer(session.createTopic("a.*.*.*.*.*.*"));
+            producer.send(session.createTextMessage("hello"));
+            session.commit();
+         }
+      });
+   }
+
+   @Test
+   public void testMultipleSends() throws Exception {
+      internalMultipleSends(false, true);
+   }
+
+   @Test
+   public void testMultipleSendsNoRouteOnMainQueue() throws Exception {
+      internalMultipleSends(true, true);
+   }
+
+   @Test
+   public void testMultipleSendsNoQueueOnSendingAddress() throws Exception {
+      internalMultipleSends(true, true);

Review Comment:
   Should `useFilterOnSkip` be false for 
testMultipleSendsNoQueueOnSendingAddress?





Issue Time Tracking
-------------------

    Worklog Id:     (was: 1020153)
    Time Spent: 20m  (was: 10m)

> Proper exception if wildcard address is used on producers
> ---------------------------------------------------------
>
>                 Key: ARTEMIS-6056
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-6056
>             Project: Artemis
>          Issue Type: Bug
>            Reporter: Clebert Suconic
>            Assignee: Clebert Suconic
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 2.54.0
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> When sending a message to a producer, the validation of the fact the address 
> is a real address, and not a wildcard, is currently an assert, which won't be 
> caught if JVM assertions are disabled.
> If a wildcard is used, the message might belong to an address that is never 
> used, and that could cause issues on message counting and their addresses.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to