Repository: deltaspike Updated Branches: refs/heads/master 158c82b0a -> fe8f62401
DELTASPIKE-651 Support for disabling context start up. Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/fe8f6240 Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/fe8f6240 Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/fe8f6240 Branch: refs/heads/master Commit: fe8f6240177500bf9c6fdbe4e0dec3ebb9e0327d Parents: 158c82b Author: John D. Ament <[email protected]> Authored: Sat Jun 28 19:13:32 2014 -0400 Committer: John D. Ament <[email protected]> Committed: Sat Jun 28 19:13:32 2014 -0400 ---------------------------------------------------------------------- .../scheduler/impl/QuartzScheduler.java | 10 ++- .../custom/CustomDeactivatedConfigSource.java | 67 +++++++++++++++++ .../test/scheduler/custom/RequestScopedJob.java | 29 ++++++++ .../scheduler/custom/ScopeNotStartedTest.java | 77 ++++++++++++++++++++ 4 files changed, 181 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fe8f6240/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/QuartzScheduler.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/QuartzScheduler.java b/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/QuartzScheduler.java index 9350cf1..7bba1a5 100644 --- a/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/QuartzScheduler.java +++ b/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/QuartzScheduler.java @@ -56,6 +56,8 @@ import java.util.logging.Logger; //vetoed class (see SchedulerExtension) public class QuartzScheduler implements Scheduler<Job> { + public static final String START_SCOPES_KEY = "deltaspike.scheduler.start_scopes_for_jobs"; + private static final Logger LOG = Logger.getLogger(QuartzScheduler.class.getName()); private static final Scheduled DEFAULT_SCHEDULED_LITERAL = AnnotationInstanceProvider.of(Scheduled.class); @@ -124,8 +126,12 @@ public class QuartzScheduler implements Scheduler<Job> try { this.scheduler = schedulerFactory.getScheduler(); - this.scheduler.getListenerManager().addJobListener(new InjectionAwareJobListener()); - + final String startScopes = ConfigResolver + .getPropertyValue(START_SCOPES_KEY, "true"); + if ("true".equalsIgnoreCase(startScopes)) + { + this.scheduler.getListenerManager().addJobListener(new InjectionAwareJobListener()); + } if (!this.scheduler.isStarted()) { String delayedStart = http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fe8f6240/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/CustomDeactivatedConfigSource.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/CustomDeactivatedConfigSource.java b/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/CustomDeactivatedConfigSource.java new file mode 100644 index 0000000..ce9d342 --- /dev/null +++ b/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/CustomDeactivatedConfigSource.java @@ -0,0 +1,67 @@ +/* + * 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.deltaspike.test.scheduler.custom; + +import org.apache.deltaspike.core.spi.activation.ClassDeactivator; +import org.apache.deltaspike.core.spi.config.ConfigSource; +import org.apache.deltaspike.scheduler.impl.QuartzScheduler; +import org.apache.deltaspike.scheduler.impl.SchedulerExtension; + +import java.util.HashMap; +import java.util.Map; + +public class CustomDeactivatedConfigSource implements ConfigSource +{ + private Map<String, String> config = new HashMap<String, String>() + {{ + put(SchedulerExtension.JOB_CLASS_CONFIG_KEY, CustomJob.class.getName()); + put(QuartzScheduler.START_SCOPES_KEY,"false"); + put(ClassDeactivator.class.getName(), QuartzDeactivator.class.getName()); + }}; + + @Override + public int getOrdinal() + { + return 1001; + } + + @Override + public Map<String, String> getProperties() + { + return this.config; + } + + @Override + public String getPropertyValue(String key) + { + return this.config.get(key); + } + + @Override + public String getConfigName() + { + return "scheduler-test-config"; + } + + @Override + public boolean isScannable() + { + return true; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fe8f6240/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/RequestScopedJob.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/RequestScopedJob.java b/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/RequestScopedJob.java new file mode 100644 index 0000000..b76c5f7 --- /dev/null +++ b/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/RequestScopedJob.java @@ -0,0 +1,29 @@ +/* + * 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.deltaspike.test.scheduler.custom; + +import org.apache.deltaspike.scheduler.api.Scheduled; + +import javax.enterprise.context.RequestScoped; + +@RequestScoped +@Scheduled(cronExpression = "*/1 * * * * ?", onStartup = false) +public class RequestScopedJob implements CustomJob +{ +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fe8f6240/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/ScopeNotStartedTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/ScopeNotStartedTest.java b/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/ScopeNotStartedTest.java new file mode 100644 index 0000000..9f71d24 --- /dev/null +++ b/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/ScopeNotStartedTest.java @@ -0,0 +1,77 @@ +/* + * 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.deltaspike.test.scheduler.custom; + +import junit.framework.Assert; +import org.apache.deltaspike.core.spi.config.ConfigSource; +import org.apache.deltaspike.scheduler.spi.Scheduler; +import org.apache.deltaspike.test.util.ArchiveUtils; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; + +@RunWith(Arquillian.class) +public class ScopeNotStartedTest +{ + //TODO even though this test exists, the tests in this module don't execute for quartz. + @Deployment + public static WebArchive deploy() + { + String simpleName = ScopeNotStartedTest.class.getSimpleName(); + String archiveName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1); + + JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "scopeNotStartedTest.jar") + .addPackage(CustomSchedulerWarFileTest.class.getPackage().getName()) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") + .addAsResource(new StringAsset(MockedScheduler.class.getName()), + "META-INF/services/" + Scheduler.class.getName()) + .addAsResource(new StringAsset(CustomDeactivatedConfigSource.class.getName()), + "META-INF/services/" + ConfigSource.class.getName()); + + return ShrinkWrap.create(WebArchive.class, archiveName + ".war") + .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndSchedulerArchive()) + .addAsLibraries(testJar) + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Inject + private Scheduler scheduler; + + @Inject + private TestJobManager testJobManager; + + @Test + public void testRegisterBadJob() + { + Assert.assertTrue(testJobManager.isStarted()); + + this.scheduler.registerNewJob(ManualJob.class); + Assert.assertEquals(2, testJobManager.getRegisteredJobs().size()); + Assert.assertEquals(2, testJobManager.getRunningJobs().size()); + + } +}
