Skip to content

Commit

Permalink
Fix issue with skip predicates in scheduled methods
Browse files Browse the repository at this point in the history
Before this fix, the implementations where actually
eligible for bean removal

Fixes: quarkusio#19900
(cherry picked from commit 3614947)
  • Loading branch information
geoand authored and gsmet committed Sep 6, 2021
1 parent 31b19ae commit 1049889
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class SchedulerProcessor {
static final DotName SCHEDULED_NAME = DotName.createSimple(Scheduled.class.getName());
static final DotName SCHEDULES_NAME = DotName.createSimple(Scheduled.Schedules.class.getName());
static final DotName SKIP_NEVER_NAME = DotName.createSimple(Scheduled.Never.class.getName());
static final DotName SKIP_PREDICATE = DotName.createSimple(Scheduled.SkipPredicate.class.getName());

static final Type SCHEDULED_EXECUTION_TYPE = Type.create(DotName.createSimple(ScheduledExecution.class.getName()),
Kind.CLASS);
Expand Down Expand Up @@ -466,4 +467,9 @@ private Throwable validateScheduled(CronParser parser, AnnotationInstance schedu
return null;
}

@BuildStep
UnremovableBeanBuildItem unremoveableSkipPredicates() {
return new UnremovableBeanBuildItem(new UnremovableBeanBuildItem.BeanTypeExclusion(SKIP_PREDICATE));
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.quarkus.scheduler.test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import javax.enterprise.event.Observes;
import javax.inject.Singleton;
Expand Down Expand Up @@ -44,17 +46,25 @@ public void testExecution() {
Thread.currentThread().interrupt();
throw new IllegalStateException(e);
}

assertTrue(OtherIsDisabled.TESTED.get());
assertEquals(0, Jobs.OTHER_COUNT.get());
}

static class Jobs {

static final CountDownLatch COUNTER = new CountDownLatch(1);
static final AtomicInteger OTHER_COUNT = new AtomicInteger(0);

@Scheduled(identity = "foo", every = "1s", skipExecutionIf = IsDisabled.class)
void doSomething() throws InterruptedException {
COUNTER.countDown();
}

@Scheduled(identity = "other-foo", every = "1s", skipExecutionIf = OtherIsDisabled.class)
void doSomethingElse() throws InterruptedException {
OTHER_COUNT.incrementAndGet();
}
}

@Singleton
Expand All @@ -77,4 +87,17 @@ void onSkip(@Observes SkippedExecution event) {
}

}

@Singleton
public static class OtherIsDisabled implements Scheduled.SkipPredicate {

static final AtomicBoolean TESTED = new AtomicBoolean(false);

@Override
public boolean test(ScheduledExecution execution) {
TESTED.set(true);
return true;
}

}
}

0 comments on commit 1049889

Please sign in to comment.