SLING-10489 related : support for unschedule added
diff --git a/src/test/java/org/apache/sling/discovery/commons/providers/base/DummyScheduler.java b/src/test/java/org/apache/sling/discovery/commons/providers/base/DummyScheduler.java
index 630a99b..be37704 100644
--- a/src/test/java/org/apache/sling/discovery/commons/providers/base/DummyScheduler.java
+++ b/src/test/java/org/apache/sling/discovery/commons/providers/base/DummyScheduler.java
@@ -20,6 +20,7 @@
import java.io.Serializable;
import java.util.Date;
+import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
@@ -75,13 +76,25 @@
@Override
public ScheduleOptions threadPoolName(String name) {
- this.name = name;
+ // not supported
return this;
}
}
private boolean failMode;
+ private Map<String,Thread> schedules = new HashMap<>();
+
+ private boolean manageSchedules;
+
+ public DummyScheduler() {
+ this(false);
+ }
+
+ public DummyScheduler(boolean manageSchedules) {
+ this.manageSchedules = manageSchedules;
+ }
+
@Override
public void addJob(String name, Object job, Map<String, Serializable> config, String schedulingExpression,
boolean canRunConcurrently) throws Exception {
@@ -127,6 +140,19 @@
Thread.yield();
}
}
+ if (manageSchedules) {
+ synchronized(schedules) {
+ if (schedules.get(name) != Thread.currentThread()) {
+ // we got unscheduled
+ System.out.println("(ignoring cancelled schedule) "
+ + " (currentThread " + System.identityHashCode(Thread.currentThread())
+ + ", scheduledThread " + System.identityHashCode(schedules.get(name)) + ")");
+ return;
+ }
+ schedules.remove(name);
+ }
+ System.out.println("(running schedule) " + System.identityHashCode(Thread.currentThread()));
+ }
if (job instanceof Job) {
Job j = (Job)job;
JobContext context = new JobContext() {
@@ -156,6 +182,14 @@
throw new IllegalStateException("failMode");
}
Thread th = new Thread(r);
+ if (manageSchedules) {
+ synchronized(schedules) {
+ Thread previousTh = schedules.put(name, th);
+ System.out.println("(added a schedule) " + System.identityHashCode(th)
+ + " (previous = " + System.identityHashCode(previousTh) + ")"
+ + " (size = " + schedules.size() + ")");
+ }
+ }
th.setName("async test thread for "+name);
th.setDaemon(true);
th.start();
@@ -188,7 +222,17 @@
@Override
public boolean unschedule(String jobName) {
- throw new IllegalStateException("not yet impl");
+ if (manageSchedules) {
+ final Thread removed;
+ synchronized(schedules) {
+ removed = schedules.remove(jobName);
+ System.out.println("(unscheduled) " + System.identityHashCode(removed)
+ + " (size = " + schedules.size() + ")");
+ }
+ return removed != null;
+ } else {
+ throw new IllegalStateException("not yet impl");
+ }
}
@Override