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 2016/07/14 18:56:10 UTC

svn commit: r1752724 - in /sling/trunk/bundles/commons/scheduler: ./ src/main/java/org/apache/sling/commons/scheduler/impl/ src/test/java/org/apache/sling/commons/scheduler/impl/

Author: cziegeler
Date: Thu Jul 14 18:56:10 2016
New Revision: 1752724

URL: http://svn.apache.org/viewvc?rev=1752724&view=rev
Log:
SLING-5831 : Support different thread pools for scheduled tasks

Added:
    sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzThreadPool.java   (with props)
    sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/SchedulerProxy.java   (with props)
Modified:
    sling/trunk/bundles/commons/scheduler/pom.xml
    sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzScheduler.java
    sling/trunk/bundles/commons/scheduler/src/test/java/org/apache/sling/commons/scheduler/impl/QuartzJobExecutorTest.java
    sling/trunk/bundles/commons/scheduler/src/test/java/org/apache/sling/commons/scheduler/impl/QuartzSchedulerTest.java

Modified: sling/trunk/bundles/commons/scheduler/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/scheduler/pom.xml?rev=1752724&r1=1752723&r2=1752724&view=diff
==============================================================================
--- sling/trunk/bundles/commons/scheduler/pom.xml (original)
+++ sling/trunk/bundles/commons/scheduler/pom.xml Thu Jul 14 18:56:10 2016
@@ -178,12 +178,11 @@
         <dependency>
             <groupId>org.quartz-scheduler</groupId>
             <artifactId>quartz</artifactId>
-            <version>2.2.2</version>
+            <version>2.2.3</version>
         </dependency>
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
-            <version>4.12</version>
             <scope>test</scope>
         </dependency>
         <dependency>

Modified: sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzScheduler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzScheduler.java?rev=1752724&r1=1752723&r2=1752724&view=diff
==============================================================================
--- sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzScheduler.java (original)
+++ sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzScheduler.java Thu Jul 14 18:56:10 2016
@@ -18,7 +18,6 @@ package org.apache.sling.commons.schedul
 
 import java.io.Serializable;
 import java.util.Date;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
@@ -33,7 +32,6 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.commons.scheduler.Job;
 import org.apache.sling.commons.scheduler.ScheduleOptions;
-import org.apache.sling.commons.threads.ThreadPool;
 import org.apache.sling.commons.threads.ThreadPoolManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
@@ -49,9 +47,7 @@ import org.quartz.SimpleScheduleBuilder;
 import org.quartz.SimpleTrigger;
 import org.quartz.Trigger;
 import org.quartz.TriggerBuilder;
-import org.quartz.impl.DirectSchedulerFactory;
 import org.quartz.impl.matchers.GroupMatcher;
-import org.quartz.simpl.RAMJobStore;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -69,10 +65,6 @@ public class QuartzScheduler implements
     /** Default logger. */
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
-    private static final String PREFIX = "Apache Sling Quartz Scheduler ";
-
-    private static final String QUARTZ_SCHEDULER_NAME = "ApacheSling";
-
     /** Map key for the job object */
     static final String DATA_MAP_OBJECT = "QuartzJobScheduler.Object";
 
@@ -95,13 +87,11 @@ public class QuartzScheduler implements
     static final String DATA_MAP_SERVICE_ID = "QuartzJobScheduler.serviceId";
 
     /** The quartz scheduler. */
-    private volatile org.quartz.Scheduler scheduler;
+    private volatile SchedulerProxy scheduler;
 
     @Reference
     private ThreadPoolManager threadPoolManager;
 
-    private ThreadPool threadPool;
-
     @Property(label="Thread Pool Name",
               description="The name of a configured thread pool - if no name is configured " +
                           "the default pool is used.")
@@ -114,6 +104,9 @@ public class QuartzScheduler implements
      */
     @Activate
     protected void activate(final BundleContext ctx, final Map<String, Object> props) throws Exception {
+        // SLING-2261 Prevent Quartz from checking for updates
+        System.setProperty("org.terracotta.quartz.skipUpdateCheck", Boolean.TRUE.toString());
+
         final Object poolNameObj = props.get(PROPERTY_POOL_NAME);
         final String poolName;
         if ( poolNameObj != null && poolNameObj.toString().trim().length() > 0 ) {
@@ -125,7 +118,7 @@ public class QuartzScheduler implements
         ctx.addBundleListener(this);
 
         // start scheduler
-        this.scheduler = this.init(poolName);
+        this.scheduler = new SchedulerProxy(this.threadPoolManager, poolName);
     }
 
     /**
@@ -136,9 +129,18 @@ public class QuartzScheduler implements
     protected void deactivate(final BundleContext ctx) {
         ctx.removeBundleListener(this);
 
-        final org.quartz.Scheduler s = this.scheduler;
+        final SchedulerProxy s = this.scheduler;
         this.scheduler = null;
-        this.dispose(s);
+        if ( s != null ) {
+            s.dispose();
+        }
+    }
+
+    private org.quartz.Scheduler getScheduler(final SchedulerProxy proxy) {
+        if ( proxy != null ) {
+            return proxy.getScheduler();
+        }
+        return null;
     }
 
     /**
@@ -149,7 +151,7 @@ public class QuartzScheduler implements
         if ( event.getType() == BundleEvent.STOPPED ) {
             final Long bundleId = event.getBundle().getBundleId();
 
-            final org.quartz.Scheduler s = this.scheduler;
+            final org.quartz.Scheduler s = getScheduler(this.scheduler);
             if ( s != null ) {
                 synchronized ( this ) {
                     try {
@@ -182,74 +184,6 @@ public class QuartzScheduler implements
     }
 
     /**
-     * Initialize the quartz scheduler
-     * @return Return the new scheduler instance.
-     * @throws SchedulerException
-     */
-    private org.quartz.Scheduler init(final String poolName) throws SchedulerException {
-
-        // SLING-2261 Prevent Quartz from checking for updates
-        System.setProperty("org.terracotta.quartz.skipUpdateCheck", Boolean.TRUE.toString());
-
-        final ThreadPoolManager tpm = this.threadPoolManager;
-        // sanity null check
-        if ( tpm == null ) {
-            throw new SchedulerException("Thread pool manager missing");
-        }
-
-        // create the pool
-        this.threadPool = tpm.get(poolName);
-        final QuartzThreadPool quartzPool = new QuartzThreadPool(this.threadPool);
-
-        final DirectSchedulerFactory factory = DirectSchedulerFactory.getInstance();
-        // unique run id
-        final String runID = new Date().toString().replace(' ', '_');
-        factory.createScheduler(QUARTZ_SCHEDULER_NAME, runID, quartzPool, new RAMJobStore());
-        // quartz does not provide a way to get the scheduler by name AND runID, so we have to iterate!
-        final Iterator<org.quartz.Scheduler> allSchedulersIter = factory.getAllSchedulers().iterator();
-        org.quartz.Scheduler s = null;
-        while ( s == null && allSchedulersIter.hasNext() ) {
-            final org.quartz.Scheduler current = allSchedulersIter.next();
-            if ( QUARTZ_SCHEDULER_NAME.equals(current.getSchedulerName())
-                 && runID.equals(current.getSchedulerInstanceId()) ) {
-                s = current;
-            }
-        }
-        if ( s == null ) {
-            throw new SchedulerException("Unable to find new scheduler with name " + QUARTZ_SCHEDULER_NAME + " and run ID " + runID);
-        }
-
-        s.start();
-        if ( this.logger.isDebugEnabled() ) {
-            this.logger.debug(PREFIX + "started.");
-        }
-        return s;
-    }
-
-    /**
-     * Dispose the quartz scheduler
-     * @param s The scheduler.
-     */
-    private void dispose(final org.quartz.Scheduler s) {
-        if ( s != null ) {
-            try {
-                s.shutdown();
-            } catch (SchedulerException e) {
-                this.logger.debug("Exception during shutdown of scheduler.", e);
-            }
-            if ( this.logger.isDebugEnabled() ) {
-                this.logger.debug(PREFIX + "stopped.");
-            }
-        }
-        final ThreadPoolManager tpm = this.threadPoolManager;
-        if ( tpm != null && this.threadPool != null ) {
-            tpm.release(this.threadPool);
-        }
-        this.threadPool = null;
-    }
-
-
-    /**
      * Initialize the data map for the job executor.
      * @param jobName
      * @param job
@@ -427,7 +361,7 @@ public class QuartzScheduler implements
     public void removeJob(final Long bundleId, final String name) throws NoSuchElementException {
         // as this method might be called from unbind and during
         // unbind a deactivate could happen, we check the scheduler first
-        final org.quartz.Scheduler s = this.scheduler;
+        final org.quartz.Scheduler s = this.getScheduler(this.scheduler);
         if ( s != null ) {
             synchronized ( this ) {
                 try {
@@ -442,81 +376,10 @@ public class QuartzScheduler implements
 
     /** Used by the web console plugin. */
     org.quartz.Scheduler getScheduler() {
-        return this.scheduler;
+        return this.getScheduler(this.scheduler);
     }
 
-    public static final class QuartzThreadPool implements org.quartz.spi.ThreadPool {
-
-        /** Our executor thread pool */
-        private ThreadPool executor;
-
-        /**
-         * Create a new wrapper implementation for Quartz.
-         */
-        public QuartzThreadPool(final ThreadPool executor) {
-            this.executor = executor;
-        }
-
-        /**
-         * @see org.quartz.spi.QuartzThreadPool#getPoolSize()
-         */
-        @Override
-        public int getPoolSize() {
-            return this.executor.getConfiguration().getMaxPoolSize();
-        }
-
-        /**
-         * @see org.quartz.spi.QuartzThreadPool#initialize()
-         */
-        @Override
-        public void initialize() {
-            // nothing to do
-        }
-
-        /**
-         * @see org.quartz.spi.ThreadPool#setInstanceId(java.lang.String)
-         */
-        @Override
-        public void setInstanceId(final String id) {
-            // we ignore this
-        }
-
-        /**
-         * @see org.quartz.spi.ThreadPool#setInstanceName(java.lang.String)
-         */
-        @Override
-        public void setInstanceName(final String name) {
-            // we ignore this
-        }
 
-        /**
-         * @see org.quartz.spi.QuartzThreadPool#runInThread(java.lang.Runnable)
-         */
-        @Override
-        public boolean runInThread(final Runnable job) {
-            this.executor.execute(job);
-
-            return true;
-        }
-
-        /**
-         * @see org.quartz.spi.ThreadPool#blockForAvailableThreads()
-         */
-        @Override
-        public int blockForAvailableThreads() {
-            return this.executor.getConfiguration().getMaxPoolSize() - this.executor.getConfiguration().getQueueSize();
-        }
-
-        /**
-         * @see org.quartz.spi.QuartzThreadPool#shutdown(boolean)
-         */
-        @Override
-        public void shutdown(final boolean waitForJobsToComplete) {
-            // the pool is managed by the thread pool manager,
-            // so we can just return
-            this.executor = null;
-        }
-    }
 
     /**
      * @see org.apache.sling.commons.scheduler.Scheduler#NOW()
@@ -617,7 +480,7 @@ public class QuartzScheduler implements
      * @see org.apache.sling.commons.scheduler.Scheduler#unschedule(java.lang.String)
      */
     public boolean unschedule(final Long bundleId, final String jobName) {
-        final org.quartz.Scheduler s = this.scheduler;
+        final org.quartz.Scheduler s = this.getScheduler(this.scheduler);
         if ( jobName != null && s != null ) {
             synchronized ( this ) {
                 try {
@@ -656,7 +519,7 @@ public class QuartzScheduler implements
 
         // as this method might be called from unbind and during
         // unbind a deactivate could happen, we check the scheduler first
-        final org.quartz.Scheduler s = this.scheduler;
+        final org.quartz.Scheduler s = this.getScheduler(this.scheduler);
         if ( s == null ) {
             throw new IllegalStateException("Scheduler is not available anymore.");
         }

Added: sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzThreadPool.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzThreadPool.java?rev=1752724&view=auto
==============================================================================
--- sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzThreadPool.java (added)
+++ sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzThreadPool.java Thu Jul 14 18:56:10 2016
@@ -0,0 +1,92 @@
+/*
+ * 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.commons.scheduler.impl;
+
+import org.apache.sling.commons.threads.ThreadPool;
+
+public class QuartzThreadPool implements org.quartz.spi.ThreadPool {
+
+    /** Our executor thread pool */
+    private ThreadPool executor;
+
+    /**
+     * Create a new wrapper implementation for Quartz.
+     */
+    public QuartzThreadPool(final ThreadPool executor) {
+        this.executor = executor;
+    }
+
+    /**
+     * @see org.quartz.spi.QuartzThreadPool#getPoolSize()
+     */
+    @Override
+    public int getPoolSize() {
+        return this.executor.getConfiguration().getMaxPoolSize();
+    }
+
+    /**
+     * @see org.quartz.spi.QuartzThreadPool#initialize()
+     */
+    @Override
+    public void initialize() {
+        // nothing to do
+    }
+
+    /**
+     * @see org.quartz.spi.ThreadPool#setInstanceId(java.lang.String)
+     */
+    @Override
+    public void setInstanceId(final String id) {
+        // we ignore this
+    }
+
+    /**
+     * @see org.quartz.spi.ThreadPool#setInstanceName(java.lang.String)
+     */
+    @Override
+    public void setInstanceName(final String name) {
+        // we ignore this
+    }
+
+    /**
+     * @see org.quartz.spi.QuartzThreadPool#runInThread(java.lang.Runnable)
+     */
+    @Override
+    public boolean runInThread(final Runnable job) {
+        this.executor.execute(job);
+
+        return true;
+    }
+
+    /**
+     * @see org.quartz.spi.ThreadPool#blockForAvailableThreads()
+     */
+    @Override
+    public int blockForAvailableThreads() {
+        return this.executor.getConfiguration().getMaxPoolSize() - this.executor.getConfiguration().getQueueSize();
+    }
+
+    /**
+     * @see org.quartz.spi.QuartzThreadPool#shutdown(boolean)
+     */
+    @Override
+    public void shutdown(final boolean waitForJobsToComplete) {
+        // the pool is managed by the thread pool manager,
+        // so we can just return
+        this.executor = null;
+    }
+}
\ No newline at end of file

Propchange: sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzThreadPool.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzThreadPool.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/SchedulerProxy.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/SchedulerProxy.java?rev=1752724&view=auto
==============================================================================
--- sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/SchedulerProxy.java (added)
+++ sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/SchedulerProxy.java Thu Jul 14 18:56:10 2016
@@ -0,0 +1,120 @@
+/*
+ * 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.commons.scheduler.impl;
+
+import java.util.Date;
+import java.util.Iterator;
+
+import org.apache.sling.commons.threads.ThreadPool;
+import org.apache.sling.commons.threads.ThreadPoolManager;
+import org.quartz.SchedulerException;
+import org.quartz.impl.DirectSchedulerFactory;
+import org.quartz.simpl.RAMJobStore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A per thread pool quartz scheduler
+ */
+public class SchedulerProxy {
+
+    private static final String PREFIX = "Apache Sling Quartz Scheduler ";
+
+    private static final String QUARTZ_SCHEDULER_NAME = "ApacheSling";
+
+    /** Default logger. */
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+    /** The quartz scheduler. */
+    private final org.quartz.Scheduler scheduler;
+
+    private final ThreadPoolManager threadPoolManager;
+
+    private final ThreadPool threadPool;
+
+    private final String poolName;
+
+    public SchedulerProxy(final ThreadPoolManager manager,
+            final String pName) throws SchedulerException {
+        this.poolName = pName == null ? ThreadPoolManager.DEFAULT_THREADPOOL_NAME : pName;
+
+        this.threadPoolManager = manager;
+        // sanity null check
+        if ( this.threadPoolManager == null ) {
+            throw new SchedulerException("Thread pool manager missing");
+        }
+
+        // create the pool
+        this.threadPool = this.threadPoolManager.get(poolName);
+        final QuartzThreadPool quartzPool = new QuartzThreadPool(this.threadPool);
+
+        boolean succeeded = false;
+
+        try {
+            final String name = QUARTZ_SCHEDULER_NAME + this.poolName.replace(' ', '_');
+            final DirectSchedulerFactory factory = DirectSchedulerFactory.getInstance();
+            // unique run id
+            final String runID = new Date().toString().replace(' ', '_') + this.hashCode();
+
+            factory.createScheduler(name, runID, quartzPool, new RAMJobStore());
+            // quartz does not provide a way to get the scheduler by name AND runID, so we have to iterate!
+            final Iterator<org.quartz.Scheduler> allSchedulersIter = factory.getAllSchedulers().iterator();
+            org.quartz.Scheduler s = null;
+            while ( s == null && allSchedulersIter.hasNext() ) {
+                final org.quartz.Scheduler current = allSchedulersIter.next();
+                if ( name.equals(current.getSchedulerName())
+                    && runID.equals(current.getSchedulerInstanceId()) ) {
+                    s = current;
+                }
+            }
+            if ( s == null ) {
+                throw new SchedulerException("Unable to find new scheduler with name " + name + " and run ID " + runID);
+            }
+
+            s.start();
+            if ( this.logger.isDebugEnabled() ) {
+                this.logger.debug("{}for pool {} started.", PREFIX, poolName);
+            }
+            this.scheduler = s;
+            succeeded = true;
+        } finally {
+            if ( !succeeded) {
+                this.threadPoolManager.release(this.threadPool);
+            }
+        }
+    }
+
+    /**
+     * Dispose the quartz scheduler
+     */
+    public void dispose() {
+        try {
+            this.scheduler.shutdown();
+        } catch (SchedulerException e) {
+            this.logger.debug("Exception during shutdown of scheduler.", e);
+        }
+        if ( this.logger.isDebugEnabled() ) {
+            this.logger.debug("{}for pool {} stopped.", PREFIX, poolName);
+        }
+
+        this.threadPoolManager.release(this.threadPool);
+    }
+
+    public org.quartz.Scheduler getScheduler() {
+        return this.scheduler;
+    }
+}

Propchange: sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/SchedulerProxy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/commons/scheduler/src/main/java/org/apache/sling/commons/scheduler/impl/SchedulerProxy.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Modified: sling/trunk/bundles/commons/scheduler/src/test/java/org/apache/sling/commons/scheduler/impl/QuartzJobExecutorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/scheduler/src/test/java/org/apache/sling/commons/scheduler/impl/QuartzJobExecutorTest.java?rev=1752724&r1=1752723&r2=1752724&view=diff
==============================================================================
--- sling/trunk/bundles/commons/scheduler/src/test/java/org/apache/sling/commons/scheduler/impl/QuartzJobExecutorTest.java (original)
+++ sling/trunk/bundles/commons/scheduler/src/test/java/org/apache/sling/commons/scheduler/impl/QuartzJobExecutorTest.java Thu Jul 14 18:56:10 2016
@@ -16,6 +16,17 @@
  */
 package org.apache.sling.commons.scheduler.impl;
 
+import static org.apache.sling.commons.scheduler.Scheduler.VALUE_RUN_ON_LEADER;
+import static org.apache.sling.commons.scheduler.Scheduler.VALUE_RUN_ON_SINGLE;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.io.Serializable;
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.sling.commons.scheduler.Job;
 import org.apache.sling.commons.scheduler.JobContext;
 import org.apache.sling.testing.mock.osgi.MockOsgi;
@@ -26,18 +37,11 @@ import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.osgi.framework.BundleContext;
-import org.quartz.*;
-
-import java.io.Serializable;
-import java.lang.reflect.Field;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.apache.sling.commons.scheduler.Scheduler.VALUE_RUN_ON_LEADER;
-import static org.apache.sling.commons.scheduler.Scheduler.VALUE_RUN_ON_SINGLE;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
+import org.quartz.JobDetail;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobKey;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
 
 @RunWith(MockitoJUnitRunner.class)
 public class QuartzJobExecutorTest {
@@ -59,7 +63,7 @@ public class QuartzJobExecutorTest {
 
         Field schedulerField = QuartzScheduler.class.getDeclaredField("scheduler");
         schedulerField.setAccessible(true);
-        scheduler = (Scheduler) schedulerField.get(quartzScheduler);
+        scheduler = ((SchedulerProxy) schedulerField.get(quartzScheduler)).getScheduler();
     }
 
     @Test
@@ -183,12 +187,14 @@ public class QuartzJobExecutorTest {
     }
 
     private class SimpleJob implements Job {
+        @Override
         public void execute(JobContext context) {
             isRunnablePseudoJobCompleted = true;
         }
     }
 
     private class SimpleRunnableJob implements Runnable {
+        @Override
         public void run() {
             isRunnablePseudoJobCompleted = true;
         }

Modified: sling/trunk/bundles/commons/scheduler/src/test/java/org/apache/sling/commons/scheduler/impl/QuartzSchedulerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/scheduler/src/test/java/org/apache/sling/commons/scheduler/impl/QuartzSchedulerTest.java?rev=1752724&r1=1752723&r2=1752724&view=diff
==============================================================================
--- sling/trunk/bundles/commons/scheduler/src/test/java/org/apache/sling/commons/scheduler/impl/QuartzSchedulerTest.java (original)
+++ sling/trunk/bundles/commons/scheduler/src/test/java/org/apache/sling/commons/scheduler/impl/QuartzSchedulerTest.java Thu Jul 14 18:56:10 2016
@@ -16,6 +16,18 @@
  */
 package org.apache.sling.commons.scheduler.impl;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.io.Serializable;
+import java.lang.reflect.Field;
+import java.util.Date;
+import java.util.HashMap;
+
 import org.apache.sling.commons.scheduler.Job;
 import org.apache.sling.testing.mock.osgi.MockOsgi;
 import org.junit.After;
@@ -34,17 +46,11 @@ import org.quartz.Scheduler;
 import org.quartz.SchedulerException;
 import org.quartz.TriggerBuilder;
 
-import java.io.Serializable;
-import java.lang.reflect.Field;
-import java.util.Date;
-import java.util.HashMap;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.when;
-
 @RunWith(MockitoJUnitRunner.class)
 public class QuartzSchedulerTest {
+
     private Scheduler s;
+    private SchedulerProxy proxy;
     private BundleContext context;
     private QuartzScheduler quartzScheduler;
 
@@ -59,6 +65,9 @@ public class QuartzSchedulerTest {
         context = MockOsgi.newBundleContext();
         quartzScheduler = ActivatedQuartzSchedulerFactory.create(context, "testName");
         s = quartzScheduler.getScheduler();
+        Field sField = QuartzScheduler.class.getDeclaredField("scheduler");
+        sField.setAccessible(true);
+        this.proxy = (SchedulerProxy) sField.get(quartzScheduler);
     }
 
     @Test
@@ -282,8 +291,8 @@ public class QuartzSchedulerTest {
     private void returnInternalSchedulerBack() throws NoSuchFieldException, IllegalAccessException {
         Field sField = QuartzScheduler.class.getDeclaredField("scheduler");
         sField.setAccessible(true);
-        if (quartzScheduler.getScheduler() == null && s != null) {
-            sField.set(quartzScheduler, s);
+        if (quartzScheduler.getScheduler() == null && proxy != null) {
+            sField.set(quartzScheduler, proxy);
         }
     }
 }