You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by st...@apache.org on 2022/11/03 12:05:41 UTC
[sling-org-apache-sling-commons-scheduler] branch SLING-11662 created (now 6bc5eef)
This is an automated email from the ASF dual-hosted git repository.
stefanegli pushed a change to branch SLING-11662
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-scheduler.git
at 6bc5eef SLING-11662 : added test case - ignored currently as it fails - to reproduce the 100% cpu issue
This branch includes the following new commits:
new 6bc5eef SLING-11662 : added test case - ignored currently as it fails - to reproduce the 100% cpu issue
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[sling-org-apache-sling-commons-scheduler] 01/01: SLING-11662 : added test case - ignored currently as it fails - to reproduce the 100% cpu issue
Posted by st...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
stefanegli pushed a commit to branch SLING-11662
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-scheduler.git
commit 6bc5eefcd73b2e01e9e4107b9d0c673d74f585f3
Author: Stefan Egli <st...@apache.org>
AuthorDate: Thu Nov 3 13:05:29 2022 +0100
SLING-11662 : added test case - ignored currently as it fails - to reproduce the 100% cpu issue
---
.../impl/ActivatedQuartzSchedulerFactory.java | 29 ++++++++
.../scheduler/impl/QuartzSchedulerTest.java | 77 ++++++++++++++++++++++
2 files changed, 106 insertions(+)
diff --git a/src/test/java/org/apache/sling/commons/scheduler/impl/ActivatedQuartzSchedulerFactory.java b/src/test/java/org/apache/sling/commons/scheduler/impl/ActivatedQuartzSchedulerFactory.java
index 5c06a81..9afe588 100644
--- a/src/test/java/org/apache/sling/commons/scheduler/impl/ActivatedQuartzSchedulerFactory.java
+++ b/src/test/java/org/apache/sling/commons/scheduler/impl/ActivatedQuartzSchedulerFactory.java
@@ -20,6 +20,7 @@ import java.lang.reflect.Field;
import java.util.Dictionary;
import java.util.Hashtable;
+import org.apache.sling.commons.threads.ThreadPoolManager;
import org.apache.sling.commons.threads.impl.DefaultThreadPoolManager;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -59,4 +60,32 @@ class ActivatedQuartzSchedulerFactory {
}
return quartzScheduler;
}
+
+ public static QuartzScheduler create(BundleContext context, String poolName, ThreadPoolManager tpm) throws Exception {
+ QuartzScheduler quartzScheduler = null;
+ if (context != null) {
+ quartzScheduler = new QuartzScheduler();
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+ props.put(Constants.SERVICE_DESCRIPTION, "org.apache.sling.commons.threads.impl.DefaultThreadPoolManager");
+ props.put(Constants.SERVICE_PID, "org.apache.sling.commons.threads.impl.DefaultThreadPoolManager");
+
+ Field f = QuartzScheduler.class.getDeclaredField("threadPoolManager");
+ f.setAccessible(true);
+ f.set(quartzScheduler, tpm);
+
+ final QuartzSchedulerConfiguration configuration = mock(QuartzSchedulerConfiguration.class);
+ if (poolName == null) {
+ when(configuration.poolName()).thenReturn("testName");
+ } else {
+ final String[] allowedPoolNames = new String[] {"testName", "allowed"};
+ when(configuration.poolName()).thenReturn(poolName);
+ when(configuration.allowedPoolNames()).thenReturn(allowedPoolNames);
+ }
+
+ quartzScheduler.activate(context, configuration);
+ context.registerService("scheduler", quartzScheduler, props);
+ }
+ return quartzScheduler;
+ }
+
}
diff --git a/src/test/java/org/apache/sling/commons/scheduler/impl/QuartzSchedulerTest.java b/src/test/java/org/apache/sling/commons/scheduler/impl/QuartzSchedulerTest.java
index 4905672..8ad3723 100644
--- a/src/test/java/org/apache/sling/commons/scheduler/impl/QuartzSchedulerTest.java
+++ b/src/test/java/org/apache/sling/commons/scheduler/impl/QuartzSchedulerTest.java
@@ -31,11 +31,21 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
import org.apache.sling.commons.scheduler.Job;
+import org.apache.sling.commons.scheduler.ScheduleOptions;
+import org.apache.sling.commons.threads.ModifiableThreadPoolConfig;
+import org.apache.sling.commons.threads.ThreadPool;
+import org.apache.sling.commons.threads.ThreadPoolConfig;
+import org.apache.sling.commons.threads.ThreadPoolConfig.ThreadPoolPolicy;
+import org.apache.sling.commons.threads.ThreadPoolManager;
+import org.apache.sling.commons.threads.impl.DefaultThreadPool;
import org.apache.sling.testing.mock.osgi.MockOsgi;
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -74,6 +84,73 @@ public class QuartzSchedulerTest {
this.proxies = (Map<String, SchedulerProxy>) sField.get(quartzScheduler);
}
+ @Test
+ @Ignore(value="currently fails")
+ public void testThreadPoolConfigs_minSize1_maxSize1_queue1() throws Exception {
+ doTestThreadPool(1, 1, ThreadPoolPolicy.DISCARDOLDEST, 1);
+ }
+
+ @Test
+ @Ignore(value="currently fails")
+ public void testThreadPoolConfigst_minSize0_maxSize1_queue1() throws Exception {
+ doTestThreadPool(0, 1, ThreadPoolPolicy.DISCARDOLDEST, 1);
+ }
+
+ @Test
+ public void testThreadPoolConfigs_minSize0_maxSize2_queue1() throws Exception {
+ doTestThreadPool(0, 2, ThreadPoolPolicy.DISCARDOLDEST, 1);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void doTestThreadPool(int minPoolSize, int maxPoolSize,
+ ThreadPoolPolicy policy, int queueSize) throws Exception,
+ NoSuchFieldException, IllegalAccessException, InterruptedException {
+ ModifiableThreadPoolConfig config = new ModifiableThreadPoolConfig();
+ config.setMinPoolSize(minPoolSize);
+ config.setMaxPoolSize(maxPoolSize);
+ config.setBlockPolicy(policy);
+ config.setQueueSize(queueSize);
+ DefaultThreadPool dtp = new DefaultThreadPool("myPoolName", config);
+
+ ThreadPoolManager fixedThreadPoolManager = new ThreadPoolManager() {
+
+ @Override
+ public void release(ThreadPool pool) {
+ // not implemented
+ }
+
+ @Override
+ public ThreadPool get(String name) {
+ return dtp;
+ }
+
+ @Override
+ public ThreadPool create(ThreadPoolConfig config, String label) {
+ return dtp;
+ }
+
+ @Override
+ public ThreadPool create(ThreadPoolConfig config) {
+ return dtp;
+ }
+ };
+
+ quartzScheduler = ActivatedQuartzSchedulerFactory.create(context, "testName", fixedThreadPoolManager);
+ Field sField = QuartzScheduler.class.getDeclaredField("schedulers");
+ sField.setAccessible(true);
+ this.proxies = (Map<String, SchedulerProxy>) sField.get(quartzScheduler);
+
+ final Semaphore s = new Semaphore(0);
+ ScheduleOptions opts = quartzScheduler.NOW();
+ opts.threadPoolName("myPoolName");
+ this.quartzScheduler.schedule(bundle.getBundleId(), null, new Runnable() {
+ public void run() {
+ s.release();
+ }
+ }, opts);
+ assertTrue("schedule.now not invoked within 5 sec", s.tryAcquire(5, TimeUnit.SECONDS));
+ }
+
@Test
public void testRunNow() {
InternalScheduleOptions scheduleOptions = (InternalScheduleOptions) quartzScheduler.NOW();