You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2017/05/04 08:03:39 UTC

svn commit: r1793745 [2/2] - in /sling/trunk/bundles/extensions/event/resource: ./ src/main/java/org/apache/sling/event/impl/ src/main/java/org/apache/sling/event/impl/jobs/ src/main/java/org/apache/sling/event/impl/jobs/config/ src/main/java/org/apach...

Modified: sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/jmx/QueuesMBeanImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/jmx/QueuesMBeanImpl.java?rev=1793745&r1=1793744&r2=1793745&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/jmx/QueuesMBeanImpl.java (original)
+++ sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/jmx/QueuesMBeanImpl.java Thu May  4 08:03:38 2017
@@ -32,26 +32,26 @@ import javax.management.Notification;
 import javax.management.NotificationBroadcasterSupport;
 import javax.management.StandardEmitterMBean;
 
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.event.jobs.Queue;
 import org.apache.sling.event.jobs.jmx.QueuesMBean;
 import org.apache.sling.event.jobs.jmx.StatisticsMBean;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;
-
-@Component
-@Service(value = { QueuesMBean.class })
-@Property(name = "jmx.objectname", value = "org.apache.sling:type=queues,name=QueueNames")
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+
+@Component(service =  QueuesMBean.class,
+property = {
+        "jmx.objectname=org.apache.sling:type=queues,name=QueueNames",
+        Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
+})
 public class QueuesMBeanImpl extends StandardEmitterMBean implements QueuesMBean {
 
     private static final String QUEUE_NOTIFICATION = "org.apache.sling.event.queue";
     private static final String[] NOTIFICATION_TYPES = { QUEUE_NOTIFICATION };
-    private Map<String, QueueMBeanHolder> queues = new ConcurrentHashMap<String, QueueMBeanHolder>();
+    private Map<String, QueueMBeanHolder> queues = new ConcurrentHashMap<>();
     private String[] names;
     private AtomicLong sequence = new AtomicLong(System.currentTimeMillis());
     private BundleContext bundleContext;
@@ -147,7 +147,7 @@ public class QueuesMBeanImpl extends Sta
 
     private QueueMBeanHolder add(Queue queue) {
         QueueMBeanImpl queueMBean = new QueueMBeanImpl(queue);
-        ServiceRegistration serviceRegistration = bundleContext
+        ServiceRegistration<?> serviceRegistration = bundleContext
                 .registerService(StatisticsMBean.class.getName(), queueMBean,
                         createProperties(
                                 "jmx.objectname","org.apache.sling:type=queues,name="+queue.getName(),
@@ -160,7 +160,7 @@ public class QueuesMBeanImpl extends Sta
     }
 
     private Dictionary<String, Object> createProperties(Object ... values) {
-        Dictionary<String, Object> props = new Hashtable<String, Object>();
+        Dictionary<String, Object> props = new Hashtable<>();
         for ( int i = 0; i < values.length; i+=2) {
             props.put((String) values[i], values[i+1]);
         }
@@ -175,7 +175,7 @@ public class QueuesMBeanImpl extends Sta
     @Override
     public String[] getQueueNames() {
         if (names == null) {
-            List<String> lnames = new ArrayList<String>(queues.keySet());
+            List<String> lnames = new ArrayList<>(queues.keySet());
             Collections.sort(lnames);
             names = lnames.toArray(new String[lnames.size()]);
         }

Modified: sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/notifications/NewJobSender.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/notifications/NewJobSender.java?rev=1793745&r1=1793744&r2=1793745&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/notifications/NewJobSender.java (original)
+++ sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/notifications/NewJobSender.java Thu May  4 08:03:38 2017
@@ -22,10 +22,6 @@ import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.List;
 
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Reference;
 import org.apache.sling.api.resource.observation.ExternalResourceChangeListener;
 import org.apache.sling.api.resource.observation.ResourceChange;
 import org.apache.sling.api.resource.observation.ResourceChange.ChangeType;
@@ -36,6 +32,10 @@ import org.apache.sling.event.jobs.Notif
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
 import org.osgi.service.event.Event;
 import org.osgi.service.event.EventAdmin;
 import org.slf4j.Logger;
@@ -45,7 +45,7 @@ import org.slf4j.LoggerFactory;
  * This component receives resource added events and sends a job
  * created event.
  */
-@Component
+@Component(service = {})
 public class NewJobSender implements ResourceChangeListener, ExternalResourceChangeListener {
 
     /** Logger. */
@@ -68,7 +68,7 @@ public class NewJobSender implements Res
      */
     @Activate
     protected void activate(final BundleContext bundleContext) {
-        final Dictionary<String, Object> properties = new Hashtable<String, Object>();
+        final Dictionary<String, Object> properties = new Hashtable<>();
         properties.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Job Topic Manager Event Handler");
         properties.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
         properties.put(ResourceChangeListener.CHANGES, ChangeType.ADDED.toString());
@@ -104,7 +104,7 @@ public class NewJobSender implements Res
 
                 if ( path.indexOf("_", topicEnd + 1) != -1 ) {
                 	// only job id and topic are guaranteed
-                	final Dictionary<String, Object> properties = new Hashtable<String, Object>();
+                	final Dictionary<String, Object> properties = new Hashtable<>();
                 	properties.put(NotificationConstants.NOTIFICATION_PROPERTY_JOB_ID, jobId);
                     properties.put(NotificationConstants.NOTIFICATION_PROPERTY_JOB_TOPIC, topic);
 

Modified: sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/queues/QueueManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/queues/QueueManager.java?rev=1793745&r1=1793744&r2=1793745&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/queues/QueueManager.java (original)
+++ sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/queues/QueueManager.java Thu May  4 08:03:38 2017
@@ -29,13 +29,6 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicBoolean;
 
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Properties;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.commons.scheduler.Scheduler;
@@ -48,7 +41,6 @@ import org.apache.sling.event.impl.jobs.
 import org.apache.sling.event.impl.jobs.config.ConfigurationChangeListener;
 import org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration;
 import org.apache.sling.event.impl.jobs.config.JobManagerConfiguration;
-import org.apache.sling.event.impl.jobs.config.QueueConfigurationManager;
 import org.apache.sling.event.impl.jobs.config.QueueConfigurationManager.QueueInfo;
 import org.apache.sling.event.impl.jobs.jmx.QueueStatusEvent;
 import org.apache.sling.event.impl.jobs.jmx.QueuesMBeanImpl;
@@ -59,6 +51,11 @@ import org.apache.sling.event.jobs.Job;
 import org.apache.sling.event.jobs.NotificationConstants;
 import org.apache.sling.event.jobs.Queue;
 import org.apache.sling.event.jobs.jmx.QueuesMBean;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
 import org.osgi.service.event.Event;
 import org.osgi.service.event.EventAdmin;
 import org.osgi.service.event.EventConstants;
@@ -70,13 +67,14 @@ import org.slf4j.LoggerFactory;
 /**
  * Implementation of the queue manager.
  */
-@Component(immediate=true)
-@Service(value={Runnable.class, QueueManager.class, EventHandler.class})
-@Properties({
-    @Property(name=Scheduler.PROPERTY_SCHEDULER_PERIOD, longValue=60),
-    @Property(name=Scheduler.PROPERTY_SCHEDULER_CONCURRENT, boolValue=false),
-    @Property(name=EventConstants.EVENT_TOPIC, value=NotificationConstants.TOPIC_JOB_ADDED)
-})
+@Component(immediate=true,
+           service={Runnable.class, QueueManager.class, EventHandler.class},
+           property={
+                   Scheduler.PROPERTY_SCHEDULER_PERIOD + ":Long=60",
+                   Scheduler.PROPERTY_SCHEDULER_CONCURRENT + ":Boolean=false",
+                   EventConstants.EVENT_TOPIC + "=" + NotificationConstants.TOPIC_JOB_ADDED,
+                   Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
+           })
 public class QueueManager
     implements Runnable, EventHandler, ConfigurationChangeListener {
 
@@ -101,7 +99,7 @@ public class QueueManager
     /**
      * Our thread pool.
      */
-    @Reference(referenceInterface=EventingThreadPool.class)
+    @Reference(service=EventingThreadPool.class)
     private ThreadPool threadPool;
 
     /** The job manager configuration. */
@@ -115,7 +113,7 @@ public class QueueManager
     private final Object queuesLock = new Object();
 
     /** All active queues. */
-    private final Map<String, JobQueueImpl> queues = new ConcurrentHashMap<String, JobQueueImpl>();
+    private final Map<String, JobQueueImpl> queues = new ConcurrentHashMap<>();
 
     /** We count the scheduler runs. */
     private volatile long schedulerRuns;
@@ -294,7 +292,7 @@ public class QueueManager
     private void restart() {
         // let's rename/close all queues and clear them
         synchronized ( queuesLock ) {
-            final List<JobQueueImpl> queues = new ArrayList<JobQueueImpl>(this.queues.values());
+            final List<JobQueueImpl> queues = new ArrayList<>(this.queues.values());
             for(final JobQueueImpl queue : queues ) {
                 this.outdateQueue(queue);
             }
@@ -382,7 +380,7 @@ public class QueueManager
      * Scan the resource tree for topics.
      */
     private Set<String> scanTopics() {
-        final Set<String> topics = new HashSet<String>();
+        final Set<String> topics = new HashSet<>();
 
         final ResourceResolver resolver = this.configuration.createResourceResolver();
         try {
@@ -420,12 +418,12 @@ public class QueueManager
      * Get the latest mapping from queue name to topics
      */
     private Map<QueueInfo, Set<String>> updateTopicMapping(final Set<String> topics) {
-        final Map<QueueInfo, Set<String>> mapping = new HashMap<QueueConfigurationManager.QueueInfo, Set<String>>();
+        final Map<QueueInfo, Set<String>> mapping = new HashMap<>();
         for(final String topic : topics) {
             final QueueInfo queueInfo = this.configuration.getQueueConfigurationManager().getQueueInfo(topic);
             Set<String> queueTopics = mapping.get(queueInfo);
             if ( queueTopics == null ) {
-                queueTopics = new HashSet<String>();
+                queueTopics = new HashSet<>();
                 mapping.put(queueInfo, queueTopics);
             }
             queueTopics.add(topic);

Modified: sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/stats/StatisticsManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/stats/StatisticsManager.java?rev=1793745&r1=1793744&r2=1793745&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/stats/StatisticsManager.java (original)
+++ sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/stats/StatisticsManager.java Thu May  4 08:03:38 2017
@@ -22,19 +22,21 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.event.impl.jobs.InternalJobState;
 import org.apache.sling.event.impl.jobs.config.JobManagerConfiguration;
 import org.apache.sling.event.jobs.Statistics;
 import org.apache.sling.event.jobs.TopicStatistics;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 
 /**
  * The statistics manager keeps track of all statistics related tasks.
  */
-@Component
-@Service(value=StatisticsManager.class)
+@Component(service=StatisticsManager.class,
+    property = {
+        Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
+})
 public class StatisticsManager {
 
     /** The job manager configuration. */
@@ -56,10 +58,10 @@ public class StatisticsManager {
     };
 
     /** Statistics per topic. */
-    private final ConcurrentMap<String, TopicStatistics> topicStatistics = new ConcurrentHashMap<String, TopicStatistics>();
+    private final ConcurrentMap<String, TopicStatistics> topicStatistics = new ConcurrentHashMap<>();
 
     /** Statistics per queue. */
-    private final ConcurrentMap<String, Statistics> queueStatistics = new ConcurrentHashMap<String, Statistics>();
+    private final ConcurrentMap<String, Statistics> queueStatistics = new ConcurrentHashMap<>();
 
     /**
      * Get the global statistics.

Modified: sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/tasks/HistoryCleanUpTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/tasks/HistoryCleanUpTask.java?rev=1793745&r1=1793744&r2=1793745&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/tasks/HistoryCleanUpTask.java (original)
+++ sling/trunk/bundles/extensions/event/resource/src/main/java/org/apache/sling/event/impl/jobs/tasks/HistoryCleanUpTask.java Thu May  4 08:03:38 2017
@@ -24,10 +24,6 @@ import java.util.Calendar;
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.api.resource.PersistenceException;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
@@ -39,6 +35,9 @@ import org.apache.sling.event.jobs.Job;
 import org.apache.sling.event.jobs.consumer.JobExecutionContext;
 import org.apache.sling.event.jobs.consumer.JobExecutionResult;
 import org.apache.sling.event.jobs.consumer.JobExecutor;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -52,9 +51,11 @@ import org.slf4j.LoggerFactory;
  *           The value should either be a string or an array of string. Allowed values are:
  *           SUCCEEDED, STOPPED, GIVEN_UP, ERROR, DROPPED
  */
-@Component
-@Service(value = JobExecutor.class)
-@Property(name = JobExecutor.PROPERTY_TOPICS, value = "org/apache/sling/event/impl/jobs/tasks/HistoryCleanUpTask")
+@Component(service = JobExecutor.class,
+    property = {
+        JobExecutor.PROPERTY_TOPICS + "=org/apache/sling/event/impl/jobs/tasks/HistoryCleanUpTask",
+        Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
+})
 public class HistoryCleanUpTask implements JobExecutor {
 
     private static final String PROPERTY_AGE = "age";
@@ -88,7 +89,7 @@ public class HistoryCleanUpTask implemen
 
         final List<String> stateList;
         if ( states != null ) {
-            stateList = new ArrayList<String>();
+            stateList = new ArrayList<>();
             for(final String s : states) {
                 stateList.add(s);
             }

Modified: sling/trunk/bundles/extensions/event/resource/src/test/java/org/apache/sling/event/impl/jobs/JobConsumerManagerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/resource/src/test/java/org/apache/sling/event/impl/jobs/JobConsumerManagerTest.java?rev=1793745&r1=1793744&r2=1793745&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/resource/src/test/java/org/apache/sling/event/impl/jobs/JobConsumerManagerTest.java (original)
+++ sling/trunk/bundles/extensions/event/resource/src/test/java/org/apache/sling/event/impl/jobs/JobConsumerManagerTest.java Thu May  4 08:03:38 2017
@@ -22,7 +22,7 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 
-import java.util.Collections;
+import java.lang.annotation.Annotation;
 
 import org.apache.sling.event.jobs.consumer.JobConsumer;
 import org.apache.sling.event.jobs.consumer.JobExecutor;
@@ -34,10 +34,34 @@ import org.osgi.framework.ServiceReferen
 
 public class JobConsumerManagerTest {
 
+    private JobConsumerManager.Config getDefaultConfig() {
+        return new JobConsumerManager.Config() {
+
+            @Override
+            public Class<? extends Annotation> annotationType() {
+                return JobConsumerManager.Config.class;
+            }
+
+            @Override
+            public boolean org_apache_sling_installer_configuration_persist() {
+                return false;
+            }
+
+            @Override
+            public String[] job_consumermanager_whitelist() {
+                return new String[] {"*"};
+            }
+
+            @Override
+            public String[] job_consumermanager_blacklist() {
+                return null;
+            }
+        };
+    }
     @Test public void testSimpleMappingConsumer() {
         final BundleContext bc = Mockito.mock(BundleContext.class);
         final JobConsumerManager jcs = new JobConsumerManager();
-        jcs.activate(bc, Collections.EMPTY_MAP);
+        jcs.activate(bc, getDefaultConfig());
 
         final JobConsumer jc1 = Mockito.mock(JobConsumer.class);
         final ServiceReference ref1 = Mockito.mock(ServiceReference.class);
@@ -56,7 +80,7 @@ public class JobConsumerManagerTest {
     @Test public void testCategoryMappingConsumer() {
         final BundleContext bc = Mockito.mock(BundleContext.class);
         final JobConsumerManager jcs = new JobConsumerManager();
-        jcs.activate(bc, Collections.EMPTY_MAP);
+        jcs.activate(bc, getDefaultConfig());
 
         final JobConsumer jc1 = Mockito.mock(JobConsumer.class);
         final ServiceReference ref1 = Mockito.mock(ServiceReference.class);
@@ -75,7 +99,7 @@ public class JobConsumerManagerTest {
     @Test public void testSubCategoryMappingConsumer() {
         final BundleContext bc = Mockito.mock(BundleContext.class);
         final JobConsumerManager jcs = new JobConsumerManager();
-        jcs.activate(bc, Collections.EMPTY_MAP);
+        jcs.activate(bc, getDefaultConfig());
 
         final JobConsumer jc1 = Mockito.mock(JobConsumer.class);
         final ServiceReference ref1 = Mockito.mock(ServiceReference.class);
@@ -94,7 +118,7 @@ public class JobConsumerManagerTest {
     @Test public void testSimpleMappingExecutor() {
         final BundleContext bc = Mockito.mock(BundleContext.class);
         final JobConsumerManager jcs = new JobConsumerManager();
-        jcs.activate(bc, Collections.EMPTY_MAP);
+        jcs.activate(bc, getDefaultConfig());
 
         final JobExecutor jc1 = Mockito.mock(JobExecutor.class);
         final ServiceReference ref1 = Mockito.mock(ServiceReference.class);
@@ -113,7 +137,7 @@ public class JobConsumerManagerTest {
     @Test public void testCategoryMappingExecutor() {
         final BundleContext bc = Mockito.mock(BundleContext.class);
         final JobConsumerManager jcs = new JobConsumerManager();
-        jcs.activate(bc, Collections.EMPTY_MAP);
+        jcs.activate(bc, getDefaultConfig());
 
         final JobExecutor jc1 = Mockito.mock(JobExecutor.class);
         final ServiceReference ref1 = Mockito.mock(ServiceReference.class);
@@ -132,7 +156,7 @@ public class JobConsumerManagerTest {
     @Test public void testSubCategoryMappingExecutor() {
         final BundleContext bc = Mockito.mock(BundleContext.class);
         final JobConsumerManager jcs = new JobConsumerManager();
-        jcs.activate(bc, Collections.EMPTY_MAP);
+        jcs.activate(bc, getDefaultConfig());
 
         final JobExecutor jc1 = Mockito.mock(JobExecutor.class);
         final ServiceReference ref1 = Mockito.mock(ServiceReference.class);
@@ -151,7 +175,7 @@ public class JobConsumerManagerTest {
     @Test public void testRanking() {
         final BundleContext bc = Mockito.mock(BundleContext.class);
         final JobConsumerManager jcs = new JobConsumerManager();
-        jcs.activate(bc, Collections.EMPTY_MAP);
+        jcs.activate(bc, getDefaultConfig());
 
         final JobExecutor jc1 = Mockito.mock(JobExecutor.class);
         final JobExecutor jc2 = Mockito.mock(JobExecutor.class);

Modified: sling/trunk/bundles/extensions/event/resource/src/test/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfigurationTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/resource/src/test/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfigurationTest.java?rev=1793745&r1=1793744&r2=1793745&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/resource/src/test/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfigurationTest.java (original)
+++ sling/trunk/bundles/extensions/event/resource/src/test/java/org/apache/sling/event/impl/jobs/config/InternalQueueConfigurationTest.java Thu May  4 08:03:38 2017
@@ -24,68 +24,128 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
+import java.lang.annotation.Annotation;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
 public class InternalQueueConfigurationTest {
 
-    @org.junit.Test public void testMaxParallel() {
-        final Map<String, Object> p = new HashMap<String, Object>();
-        p.put(ConfigurationConstants.PROP_NAME, "QueueConfigurationTest");
-        p.put(ConfigurationConstants.PROP_MAX_PARALLEL, -1);
+    private InternalQueueConfiguration.Config createConfig(final double maxParallel) {
+        return createConfig(null, "QueueConfigurationTest", maxParallel);
+    }
 
-        InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(p);
+    private InternalQueueConfiguration.Config createConfig(final String[] topics) {
+        return createConfig(topics, "QueueConfigurationTest", ConfigurationConstants.DEFAULT_MAX_PARALLEL);
+    }
+
+    private InternalQueueConfiguration.Config createConfig(final String[] topics, final String name) {
+        return createConfig(topics, name, ConfigurationConstants.DEFAULT_MAX_PARALLEL);
+    }
+
+    private InternalQueueConfiguration.Config createConfig(final String[] topics,
+            final String name,
+            final double maxParallel) {
+        return new InternalQueueConfiguration.Config() {
+
+            @Override
+            public Class<? extends Annotation> annotationType() {
+                return InternalQueueConfiguration.Config.class;
+            }
+
+            @Override
+            public String queue_name() {
+                return name;
+            }
+
+            @Override
+            public String[] queue_topics() {
+                return topics;
+            }
+
+            @Override
+            public String queue_type() {
+                return "UNORDERED";
+            }
+
+            @Override
+            public String queue_priority() {
+                return ConfigurationConstants.DEFAULT_PRIORITY;
+            }
+
+            @Override
+            public int queue_retries() {
+                return ConfigurationConstants.DEFAULT_RETRIES;
+            }
+
+            @Override
+            public long queue_retrydelay() {
+                return ConfigurationConstants.DEFAULT_RETRY_DELAY;
+            }
+
+            @Override
+            public double queue_maxparallel() {
+                return maxParallel;
+            }
+
+            @Override
+            public boolean queue_keepJobs() {
+                return false;
+            }
+
+            @Override
+            public boolean queue_preferRunOnCreationInstance() {
+                return false;
+            }
+
+            @Override
+            public int queue_threadPoolSize() {
+                return 0;
+            }
+
+            @Override
+            public int service_ranking() {
+                return 0;
+            }
+        };
+    }
+
+    @org.junit.Test public void testMaxParallel() {
+        InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(Collections.<String, Object>emptyMap(), createConfig(-1));
         assertEquals(Runtime.getRuntime().availableProcessors(), c.getMaxParallel());
 
         // Edge cases 0.0 and 1.0 (treated as int numbers)
-        p.put(ConfigurationConstants.PROP_MAX_PARALLEL, 0.0);
-        c = InternalQueueConfiguration.fromConfiguration(p);
+        c = InternalQueueConfiguration.fromConfiguration(Collections.<String, Object>emptyMap(), createConfig(0.0));
         assertEquals(0, c.getMaxParallel());
 
-        p.put(ConfigurationConstants.PROP_MAX_PARALLEL, 1.0);
-        c = InternalQueueConfiguration.fromConfiguration(p);
+        c = InternalQueueConfiguration.fromConfiguration(Collections.<String, Object>emptyMap(), createConfig(1.0));
         assertEquals(1, c.getMaxParallel());
 
         // percentage (50%)
-        p.put(ConfigurationConstants.PROP_MAX_PARALLEL, 0.5);
-        c = InternalQueueConfiguration.fromConfiguration(p);
+        c = InternalQueueConfiguration.fromConfiguration(Collections.<String, Object>emptyMap(), createConfig(0.5));
         assertEquals((int) Math.round(Runtime.getRuntime().availableProcessors() * 0.5), c.getMaxParallel());
 
         // rounding
-        p.put(ConfigurationConstants.PROP_MAX_PARALLEL, 0.90);
-        c = InternalQueueConfiguration.fromConfiguration(p);
+        c = InternalQueueConfiguration.fromConfiguration(Collections.<String, Object>emptyMap(), createConfig(0.90));
         assertEquals((int) Math.round(Runtime.getRuntime().availableProcessors() * 0.9), c.getMaxParallel());
 
-        p.put(ConfigurationConstants.PROP_MAX_PARALLEL, 0.99);
-        c = InternalQueueConfiguration.fromConfiguration(p);
+        c = InternalQueueConfiguration.fromConfiguration(Collections.<String, Object>emptyMap(), createConfig(0.99));
         assertEquals((int) Math.round(Runtime.getRuntime().availableProcessors() * 0.99), c.getMaxParallel());
 
         // Percentages can't go over 99% (0.99)
-        p.put(ConfigurationConstants.PROP_MAX_PARALLEL, 1.01);
-        c = InternalQueueConfiguration.fromConfiguration(p);
+        c = InternalQueueConfiguration.fromConfiguration(Collections.<String, Object>emptyMap(), createConfig(1.01));
         assertEquals(Runtime.getRuntime().availableProcessors(), c.getMaxParallel());
 
         // Treat negative values same a -1 (all cores)
-        p.put(ConfigurationConstants.PROP_MAX_PARALLEL, -0.5);
-        c = InternalQueueConfiguration.fromConfiguration(p);
+        c = InternalQueueConfiguration.fromConfiguration(Collections.<String, Object>emptyMap(), createConfig(-0.5));
         assertEquals(Runtime.getRuntime().availableProcessors(), c.getMaxParallel());
 
-        p.put(ConfigurationConstants.PROP_MAX_PARALLEL, -2);
-        c = InternalQueueConfiguration.fromConfiguration(p);
+        c = InternalQueueConfiguration.fromConfiguration(Collections.<String, Object>emptyMap(), createConfig(-2));
         assertEquals(Runtime.getRuntime().availableProcessors(), c.getMaxParallel());
-
-        // Invalid number results in ConfigurationConstants.DEFAULT_MAX_PARALLEL
-        p.put(ConfigurationConstants.PROP_MAX_PARALLEL, "a string");
-        c = InternalQueueConfiguration.fromConfiguration(p);
-        assertEquals(ConfigurationConstants.DEFAULT_MAX_PARALLEL, c.getMaxParallel());
     }
 
     @org.junit.Test public void testTopicMatchersDot() {
-        final Map<String, Object> p = new HashMap<String, Object>();
-        p.put(ConfigurationConstants.PROP_TOPICS, new String[] {"a."});
-        p.put(ConfigurationConstants.PROP_NAME, "test");
-
-        InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(p);
+        InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(Collections.<String, Object>emptyMap(), createConfig(new String[] {"a."}));
         assertTrue(c.isValid());
         assertNotNull(c.match("a/b"));
         assertNotNull(c.match("a/c"));
@@ -96,11 +156,7 @@ public class InternalQueueConfigurationT
     }
 
     @org.junit.Test public void testTopicMatchersStar() {
-        final Map<String, Object> p = new HashMap<String, Object>();
-        p.put(ConfigurationConstants.PROP_TOPICS, new String[] {"a*"});
-        p.put(ConfigurationConstants.PROP_NAME, "test");
-
-        InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(p);
+        InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(Collections.<String, Object>emptyMap(), createConfig(new String[] {"a*"}));
         assertTrue(c.isValid());
         assertNotNull(c.match("a/b"));
         assertNotNull(c.match("a/c"));
@@ -111,11 +167,7 @@ public class InternalQueueConfigurationT
     }
 
     @org.junit.Test public void testTopicMatchers() {
-        final Map<String, Object> p = new HashMap<String, Object>();
-        p.put(ConfigurationConstants.PROP_TOPICS, new String[] {"a"});
-        p.put(ConfigurationConstants.PROP_NAME, "test");
-
-        InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(p);
+        InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(Collections.<String, Object>emptyMap(), createConfig(new String[] {"a"}));
         assertTrue(c.isValid());
         assertNull(c.match("a/b"));
         assertNull(c.match("a/c"));
@@ -126,11 +178,7 @@ public class InternalQueueConfigurationT
     }
 
     @org.junit.Test public void testTopicMatcherAndReplacement() {
-        final Map<String, Object> p = new HashMap<String, Object>();
-        p.put(ConfigurationConstants.PROP_TOPICS, new String[] {"a."});
-        p.put(ConfigurationConstants.PROP_NAME, "test-queue-{0}");
-
-        InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(p);
+        InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(Collections.<String, Object>emptyMap(), createConfig(new String[] {"a."}, "test-queue-{0}"));
         assertTrue(c.isValid());
         final String b = "a/b";
         assertNotNull(c.match(b));
@@ -141,11 +189,7 @@ public class InternalQueueConfigurationT
     }
 
     @org.junit.Test public void testTopicMatchersDotAndSlash() {
-        final Map<String, Object> p = new HashMap<String, Object>();
-        p.put(ConfigurationConstants.PROP_TOPICS, new String[] {"a/."});
-        p.put(ConfigurationConstants.PROP_NAME, "test");
-
-        InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(p);
+        InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(Collections.<String, Object>emptyMap(), createConfig(new String[] {"a/."}));
         assertTrue(c.isValid());
         assertNotNull(c.match("a/b"));
         assertNotNull(c.match("a/c"));
@@ -156,11 +200,11 @@ public class InternalQueueConfigurationT
     }
 
     @org.junit.Test public void testTopicMatchersStarAndSlash() {
-        final Map<String, Object> p = new HashMap<String, Object>();
+        final Map<String, Object> p = new HashMap<>();
         p.put(ConfigurationConstants.PROP_TOPICS, new String[] {"a/*"});
         p.put(ConfigurationConstants.PROP_NAME, "test");
 
-        InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(p);
+        InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(Collections.<String, Object>emptyMap(), createConfig(new String[] {"a/*"}));
         assertTrue(c.isValid());
         assertNotNull(c.match("a/b"));
         assertNotNull(c.match("a/c"));
@@ -171,11 +215,7 @@ public class InternalQueueConfigurationT
     }
 
     @org.junit.Test public void testTopicMatcherAndReplacementAndSlash() {
-        final Map<String, Object> p = new HashMap<String, Object>();
-        p.put(ConfigurationConstants.PROP_TOPICS, new String[] {"a/."});
-        p.put(ConfigurationConstants.PROP_NAME, "test-queue-{0}");
-
-        InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(p);
+        InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(Collections.<String, Object>emptyMap(), createConfig(new String[] {"a/."}, "test-queue-{0}"));
         assertTrue(c.isValid());
         final String b = "a/b";
         assertNotNull(c.match(b));
@@ -186,10 +226,10 @@ public class InternalQueueConfigurationT
     }
 
     @org.junit.Test public void testNoTopicMatchers() {
-        final Map<String, Object> p = new HashMap<String, Object>();
+        final Map<String, Object> p = new HashMap<>();
         p.put(ConfigurationConstants.PROP_NAME, "test");
 
-        InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(p);
+        InternalQueueConfiguration c = InternalQueueConfiguration.fromConfiguration(Collections.<String, Object>emptyMap(), createConfig(null));
         assertFalse(c.isValid());
     }
 }

Modified: sling/trunk/bundles/extensions/event/resource/src/test/java/org/apache/sling/event/it/AbstractJobHandlingTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/resource/src/test/java/org/apache/sling/event/it/AbstractJobHandlingTest.java?rev=1793745&r1=1793744&r2=1793745&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/resource/src/test/java/org/apache/sling/event/it/AbstractJobHandlingTest.java (original)
+++ sling/trunk/bundles/extensions/event/resource/src/test/java/org/apache/sling/event/it/AbstractJobHandlingTest.java Thu May  4 08:03:38 2017
@@ -293,10 +293,10 @@ public abstract class AbstractJobHandlin
     public void setup() throws IOException {
         // set load delay to 3 sec
         final org.osgi.service.cm.Configuration c2 = this.configAdmin.getConfiguration("org.apache.sling.event.impl.jobs.jcr.PersistenceHandler", null);
-        Dictionary<String, Object> p2 = new Hashtable<String, Object>();
+        Dictionary<String, Object> p2 = new Hashtable<>();
         p2.put(JobManagerConfiguration.PROPERTY_BACKGROUND_LOAD_DELAY, 3L);
         // and startup.delay to 1sec - otherwise default of 30sec breaks tests!
-        p2.put(JobManagerConfiguration.PROPERTY_STARTUP_DELAY, 1L);
+        p2.put("startup.delay", 1L);
         c2.update(p2);
 
         // SLING-5560 : since the above (re)config is now applied, we're safe
@@ -390,7 +390,7 @@ public abstract class AbstractJobHandlin
      */
     protected ServiceRegistration<EventHandler> registerEventHandler(final String topic,
             final EventHandler handler) {
-        final Dictionary<String, Object> props = new Hashtable<String, Object>();
+        final Dictionary<String, Object> props = new Hashtable<>();
         props.put(EventConstants.EVENT_TOPIC, topic);
         final ServiceRegistration<EventHandler> reg = this.bc.registerService(EventHandler.class,
                 handler, props);
@@ -429,7 +429,7 @@ public abstract class AbstractJobHandlin
     protected ServiceRegistration<JobConsumer> registerJobConsumer(final String topic,
             final JobConsumer handler) {
         long cc = this.getConsumerChangeCount();
-        final Dictionary<String, Object> props = new Hashtable<String, Object>();
+        final Dictionary<String, Object> props = new Hashtable<>();
         props.put(JobConsumer.PROPERTY_TOPICS, topic);
         final ServiceRegistration<JobConsumer> reg = this.bc.registerService(JobConsumer.class,
                 handler, props);
@@ -444,7 +444,7 @@ public abstract class AbstractJobHandlin
     protected ServiceRegistration<JobExecutor> registerJobExecutor(final String topic,
             final JobExecutor handler) {
         long cc = this.getConsumerChangeCount();
-        final Dictionary<String, Object> props = new Hashtable<String, Object>();
+        final Dictionary<String, Object> props = new Hashtable<>();
         props.put(JobConsumer.PROPERTY_TOPICS, topic);
         final ServiceRegistration<JobExecutor> reg = this.bc.registerService(JobExecutor.class,
                 handler, props);