This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-event.git


The following commit(s) were added to refs/heads/master by this push:
     new 71c6d4b  Add tests for multiple applicable configs
71c6d4b is described below

commit 71c6d4b3219adb640fa5628fb31cad84d31eff2b
Author: Konrad Windszus <k...@apache.org>
AuthorDate: Thu Feb 29 16:55:48 2024 +0100

    Add tests for multiple applicable configs
---
 .../config/InternalQueueConfigurationTest.java     | 17 ++++--
 .../jobs/config/QueueConfigurationManagerTest.java | 64 ++++++++++++++++++++++
 2 files changed, 76 insertions(+), 5 deletions(-)

diff --git 
a/src/test/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfigurationTest.java
 
b/src/test/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfigurationTest.java
index 948d953..b6aa5e4 100644
--- 
a/src/test/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfigurationTest.java
+++ 
b/src/test/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfigurationTest.java
@@ -31,21 +31,28 @@ import java.util.Map;
 
 public class InternalQueueConfigurationTest {
 
-    private InternalQueueConfiguration.Config createConfig(final double 
maxParallel) {
+    static InternalQueueConfiguration.Config createConfig(final double 
maxParallel) {
         return createConfig(null, "QueueConfigurationTest", maxParallel);
     }
 
-    private InternalQueueConfiguration.Config createConfig(final String[] 
topics) {
+    static InternalQueueConfiguration.Config createConfig(final String[] 
topics) {
         return createConfig(topics, "QueueConfigurationTest", 
ConfigurationConstants.DEFAULT_MAX_PARALLEL);
     }
 
-    private InternalQueueConfiguration.Config createConfig(final String[] 
topics, final String name) {
+    static InternalQueueConfiguration.Config createConfig(final String[] 
topics, final String name) {
         return createConfig(topics, name, 
ConfigurationConstants.DEFAULT_MAX_PARALLEL);
     }
 
-    private InternalQueueConfiguration.Config createConfig(final String[] 
topics,
+    static InternalQueueConfiguration.Config createConfig(final String[] 
topics,
             final String name,
             final double maxParallel) {
+        return createConfig(topics, name, maxParallel, 0);
+    }
+    
+    static InternalQueueConfiguration.Config createConfig(final String[] 
topics,
+            final String name,
+            final double maxParallel,
+            final int ranking) {
         return new InternalQueueConfiguration.Config() {
 
             @Override
@@ -105,7 +112,7 @@ public class InternalQueueConfigurationTest {
 
             @Override
             public int service_ranking() {
-                return 0;
+                return ranking;
             }
 
             @Override
diff --git 
a/src/test/java/org/apache/sling/event/impl/jobs/config/QueueConfigurationManagerTest.java
 
b/src/test/java/org/apache/sling/event/impl/jobs/config/QueueConfigurationManagerTest.java
new file mode 100644
index 0000000..9eb4b5a
--- /dev/null
+++ 
b/src/test/java/org/apache/sling/event/impl/jobs/config/QueueConfigurationManagerTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.sling.event.impl.jobs.config;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Collections;
+
+import 
org.apache.sling.event.impl.jobs.config.QueueConfigurationManager.QueueInfo;
+import org.junit.Test;
+
+public class QueueConfigurationManagerTest {
+
+    @Test
+    public void testMultipleMatchingConfigsWithSameRankingAndSameTopic() {
+        QueueConfigurationManager configMgr = new QueueConfigurationManager();
+        
configMgr.bindConfig(InternalQueueConfiguration.fromConfiguration(Collections.<String,
 Object>emptyMap(), 
+                InternalQueueConfigurationTest.createConfig(new String[] 
{"topic1"}, "queue1", 2, 0)));
+        
configMgr.bindConfig(InternalQueueConfiguration.fromConfiguration(Collections.<String,
 Object>emptyMap(), 
+                InternalQueueConfigurationTest.createConfig(new String[] 
{"topic1"}, "queue2", 2, 0)));
+        
configMgr.bindConfig(InternalQueueConfiguration.fromConfiguration(Collections.<String,
 Object>emptyMap(), 
+                InternalQueueConfigurationTest.createConfig(new String[] 
{"topic1"}, "queue3", 2, -3)));
+        QueueInfo queueInfo = configMgr.getQueueInfo("topic1");
+        assertEquals("queue1", queueInfo.queueName); // first queue wins
+    }
+
+    @Test
+    public void testMultipleMatchingConfigsWithSameRankingAndDifferentTopic() {
+        QueueConfigurationManager configMgr = new QueueConfigurationManager();
+        
configMgr.bindConfig(InternalQueueConfiguration.fromConfiguration(Collections.<String,
 Object>emptyMap(), 
+                InternalQueueConfigurationTest.createConfig(new String[] 
{"*"}, "queue1", 2, 0)));
+        
configMgr.bindConfig(InternalQueueConfiguration.fromConfiguration(Collections.<String,
 Object>emptyMap(), 
+                InternalQueueConfigurationTest.createConfig(new String[] 
{"topic1/test"}, "queue2", 2, 0)));
+        QueueInfo queueInfo = configMgr.getQueueInfo("topic1/test");
+        assertEquals("queue1", queueInfo.queueName); // first queue wins 
(although topic in config is more generic)
+    }
+
+    @Test
+    public void testMultipleMatchingConfigsWithDifferentRanking() {
+        QueueConfigurationManager configMgr = new QueueConfigurationManager();
+        
configMgr.bindConfig(InternalQueueConfiguration.fromConfiguration(Collections.<String,
 Object>emptyMap(), 
+                InternalQueueConfigurationTest.createConfig(new String[] 
{"topic1/test"}, "queue1", 2, 1)));
+        
configMgr.bindConfig(InternalQueueConfiguration.fromConfiguration(Collections.<String,
 Object>emptyMap(), 
+                InternalQueueConfigurationTest.createConfig(new String[] 
{"topic1/*"}, "queue2", 2, 2)));
+        QueueInfo queueInfo = configMgr.getQueueInfo("topic1/test");
+        assertEquals("queue2", queueInfo.queueName); // highest ranking wins
+    }
+}

Reply via email to