Repository: zest-java Updated Branches: refs/heads/ZEST-130 [created] 551c04d59
http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/test/java/org/apache/library/scheduler/SchedulerTest.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/test/java/org/apache/library/scheduler/SchedulerTest.java b/libraries/scheduler/src/test/java/org/apache/library/scheduler/SchedulerTest.java new file mode 100644 index 0000000..2832ec1 --- /dev/null +++ b/libraries/scheduler/src/test/java/org/apache/library/scheduler/SchedulerTest.java @@ -0,0 +1,94 @@ +/* + * 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.library.scheduler; + +import java.util.Date; +import org.apache.zest.api.entity.Identity; +import org.apache.zest.api.unitofwork.UnitOfWork; +import org.apache.zest.api.usecase.UsecaseBuilder; +import org.apache.zest.bootstrap.AssemblyException; +import org.apache.zest.bootstrap.ModuleAssembly; +import org.apache.zest.entitystore.memory.MemoryEntityStoreService; +import org.apache.zest.library.scheduler.SchedulerAssembler; +import org.apache.zest.library.scheduler.SchedulerService; +import org.apache.zest.library.scheduler.ZestJob; +import org.apache.zest.library.scheduler.ZestJobDetail; +import org.apache.zest.spi.uuid.UuidIdentityGeneratorService; +import org.apache.zest.test.AbstractZestTest; +import org.apache.zest.valueserialization.jackson.JacksonValueSerializationAssembler; +import org.apache.zest.valueserialization.orgjson.OrgJsonValueSerializationAssembler; +import org.junit.Test; +import org.quartz.CronExpression; +import org.quartz.CronTrigger; +import org.quartz.Job; +import org.quartz.JobDetail; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; +import org.quartz.Trigger; + +import static org.quartz.CronScheduleBuilder.cronSchedule; +import static org.quartz.TriggerBuilder.newTrigger; + +public class SchedulerTest extends AbstractZestTest +{ + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + new SchedulerAssembler().assemble( module ); + module.services( MemoryEntityStoreService.class ); + module.services( UuidIdentityGeneratorService.class ); + new JacksonValueSerializationAssembler().assemble( module ); + module.entities( ZestJob.class ).withMixins( HelloJob.class ); + } + + @Test + public void givenSchedulerWhenScheduleJobExpectJobExecuted() + throws Exception + { + try(UnitOfWork uow = module.newUnitOfWork( UsecaseBuilder.newUsecase( "testing" )) ) + { + SchedulerService underTest = module.findService( SchedulerService.class ).get(); + ZestJob job = uow.newEntity( ZestJob.class, "job://group1.job1" ); + ZestJobDetail details = underTest.createJobDetails( job ); + + CronTrigger trigger = newTrigger() + .withIdentity("trigger1", "group1") + .withSchedule(cronSchedule("* * * * * ?")) + .build(); + underTest.getScheduler().scheduleJob( details, trigger ); + uow.complete(); + + } + Thread.sleep(15000); + } + + public static abstract class HelloJob + implements ZestJob + { + @Override + public void execute( JobExecutionContext context ) + throws JobExecutionException + { + System.out.println("Hello, Quartz!"); + } + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/AbstractSchedulerTest.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/AbstractSchedulerTest.java b/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/AbstractSchedulerTest.java deleted file mode 100644 index 02d5636..0000000 --- a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/AbstractSchedulerTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2010-2014, Paul Merlin. - * - * Licensed 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.zest.library.scheduler; - -import org.apache.zest.api.entity.EntityBuilder; -import org.apache.zest.api.entity.IdentityGenerator; -import org.apache.zest.api.unitofwork.UnitOfWork; -import org.apache.zest.api.value.ValueSerialization; -import org.apache.zest.bootstrap.AssemblyException; -import org.apache.zest.bootstrap.ModuleAssembly; -import org.apache.zest.bootstrap.ServiceDeclaration; -import org.apache.zest.entitystore.memory.MemoryEntityStoreService; -import org.apache.zest.index.rdf.assembly.RdfMemoryStoreAssembler; -import org.apache.zest.spi.uuid.UuidIdentityGeneratorService; -import org.apache.zest.test.AbstractZestTest; -import org.apache.zest.test.EntityTestAssembler; -import org.apache.zest.valueserialization.orgjson.OrgJsonValueSerializationService; - -public abstract class AbstractSchedulerTest - extends AbstractZestTest -{ - @Override - public final void assemble( ModuleAssembly assembly ) - throws AssemblyException - { - assembly.entities( FooTask.class ); - - assembly.services( MemoryEntityStoreService.class ); - assembly.services( UuidIdentityGeneratorService.class).withMixins( CountingIdentityGeneratorService.class ); - assembly.services( OrgJsonValueSerializationService.class ).taggedWith( ValueSerialization.Formats.JSON ); - new RdfMemoryStoreAssembler().assemble( assembly ); - - onAssembly( assembly ); - } - - protected abstract void onAssembly( ModuleAssembly module ) - throws AssemblyException; - - protected final FooTask createFooTask( UnitOfWork uow, String name, String input ) - { - EntityBuilder<FooTask> builder = uow.newEntityBuilder( FooTask.class ); - FooTask task = builder.instance(); - task.name().set( name ); - task.input().set( input ); - return builder.newInstance(); - } - - public static class CountingIdentityGeneratorService - implements IdentityGenerator - { - int counter = 0; - - @Override - public String generate( Class<?> compositeType ) - { - return compositeType.getSimpleName() + ":" + counter++; - } - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/Constants.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/Constants.java b/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/Constants.java deleted file mode 100644 index 55de82f..0000000 --- a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/Constants.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2010-2014, Paul Merlin. - * Copyright (c) 2012, Niclas Hedhman. - * - * Licensed 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.zest.library.scheduler; - -// TODO Rename to TestConstants -public interface Constants -{ - String BAR = "bar"; - String BAZAR = "bazar"; -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/CronScheduleTest.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/CronScheduleTest.java b/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/CronScheduleTest.java deleted file mode 100644 index ad210a2..0000000 --- a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/CronScheduleTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.zest.library.scheduler; - -import org.apache.zest.api.entity.EntityBuilder; -import org.apache.zest.api.unitofwork.UnitOfWork; -import org.apache.zest.api.value.ValueSerialization; -import org.apache.zest.bootstrap.AssemblyException; -import org.apache.zest.bootstrap.ModuleAssembly; -import org.apache.zest.entitystore.memory.MemoryEntityStoreService; -import org.apache.zest.spi.uuid.UuidIdentityGeneratorService; -import org.apache.zest.test.AbstractZestTest; -import org.apache.zest.valueserialization.orgjson.OrgJsonValueSerializationService; -import org.joda.time.DateTime; -import org.junit.Test; - -import static org.hamcrest.number.IsCloseTo.closeTo; -import static org.junit.Assert.assertThat; - -public class CronScheduleTest extends AbstractZestTest -{ - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - module.services( OrgJsonValueSerializationService.class ) - .taggedWith( ValueSerialization.Formats.JSON ); - module.services( MemoryEntityStoreService.class ); - module.services( UuidIdentityGeneratorService.class ); - module.entities( CronSchedule.class ); - module.entities( Task.class ).withMixins( DummyTask.class ); - } - - @Test - public void given15SecondCronWhenRequestingNextExpectEvery15Seconds() - throws Exception - { - - UnitOfWork work = module.newUnitOfWork(); - EntityBuilder<Task> builder1 = work.newEntityBuilder( Task.class ); - builder1.instance().name().set( "abc" ); - Task task = builder1.newInstance(); - EntityBuilder<CronSchedule> builder = work.newEntityBuilder( CronSchedule.class ); - builder.instance().start().set( DateTime.now() ); - builder.instance().task().set( task ); - builder.instance().cronExpression().set( "*/15 * * * * *" ); - CronSchedule schedule = builder.newInstance(); - long runAt = schedule.nextRun( System.currentTimeMillis() ); - for( int i = 0; i < 1000; i++ ) - { - long nextRun = schedule.nextRun( runAt + 1000 ); // Needs to push forward one second... - assertThat( "At:" + i, (double) nextRun, closeTo( runAt + 15000, 50 ) ); - } - work.discard(); - } - - public static abstract class DummyTask implements Task - { - @Override - public void run() - { - System.out.println( "Dummy" ); - } - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/FooTask.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/FooTask.java b/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/FooTask.java deleted file mode 100644 index 63fbee4..0000000 --- a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/FooTask.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2010-2014, Paul Merlin. - * - * Licensed 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.zest.library.scheduler; - -import org.apache.zest.api.common.Optional; -import org.apache.zest.api.common.UseDefaults; -import org.apache.zest.api.entity.Identity; -import org.apache.zest.api.injection.scope.This; -import org.apache.zest.api.mixin.Mixins; -import org.apache.zest.api.property.Property; -import org.apache.zest.api.unitofwork.concern.UnitOfWorkPropagation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.apache.zest.api.unitofwork.concern.UnitOfWorkPropagation.Propagation.REQUIRES_NEW; - -@Mixins( FooTask.Mixin.class ) -public interface FooTask - extends Task, Identity -{ - Property<String> input(); - - @Optional - Property<String> output(); - - @UseDefaults - Property<Integer> runCounter(); - - abstract class Mixin - implements Task - { - private static final Logger LOGGER = LoggerFactory.getLogger( FooTask.class ); - - @This - private FooTask me; - - @Override - public void run() - { - LOGGER.info( "FooTask.run({})", me.input().get() ); - synchronized( this ) - { - me.runCounter().set( me.runCounter().get() + 1 ); - LOGGER.info( "Identity: " + me.identity().get() ); - LOGGER.info( " Counter: " + me.runCounter().get() ); - } - if( me.input().get().equals( Constants.BAZAR ) ) - { - if( me.output().get() == null ) - { - me.output().set( Constants.BAR ); - } - else - { - me.output().set( me.output().get() + Constants.BAR ); - } - } - } - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/SchedulerTest.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/SchedulerTest.java b/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/SchedulerTest.java deleted file mode 100644 index 15a356c..0000000 --- a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/SchedulerTest.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2010-2014, Paul Merlin. All Rights Reserved. - * Copyright (c) 2012, Niclas Hedhman. All Rights Reserved. - * - * Licensed 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.zest.library.scheduler; - -import java.util.concurrent.Callable; -import org.apache.zest.api.common.Visibility; -import org.apache.zest.api.unitofwork.UnitOfWork; -import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException; -import org.apache.zest.api.usecase.Usecase; -import org.apache.zest.api.usecase.UsecaseBuilder; -import org.apache.zest.bootstrap.AssemblyException; -import org.apache.zest.bootstrap.ModuleAssembly; -import org.apache.zest.library.scheduler.bootstrap.SchedulerAssembler; -import org.apache.zest.library.scheduler.timeline.Timeline; -import org.joda.time.DateTime; -import org.joda.time.Interval; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static com.jayway.awaitility.Awaitility.await; -import static java.util.concurrent.TimeUnit.MILLISECONDS; -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.apache.zest.functional.Iterables.count; -import static org.apache.zest.library.scheduler.Constants.BAR; -import static org.apache.zest.library.scheduler.Constants.BAZAR; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; - -public class SchedulerTest - extends AbstractSchedulerTest -{ - private static final Logger LOGGER = LoggerFactory.getLogger( SchedulerTest.class ); - - @Override - protected void onAssembly( ModuleAssembly testAssembly ) - throws AssemblyException - { - @SuppressWarnings( "UnnecessaryLocalVariable" ) - ModuleAssembly moduleAssembly = testAssembly; - - @SuppressWarnings( "UnnecessaryLocalVariable" ) - ModuleAssembly configModuleAssembly = testAssembly; - - // START SNIPPET: assembly - new SchedulerAssembler().visibleIn( Visibility.application ) - .withConfig( configModuleAssembly, Visibility.layer ) - .withTimeline() - .assemble( moduleAssembly ); - // END SNIPPET: assembly - } - - @Test - public void testTaskWithoutScheduling() - throws UnitOfWorkCompletionException - { - Usecase usecase = UsecaseBuilder.newUsecase( "testTask" ); - String taskId; - try( UnitOfWork uow = module.newUnitOfWork( usecase ) ) - { - FooTask task = createFooTask( uow, "TestTask", BAZAR ); - taskId = task.identity().get(); - task.run(); - uow.complete(); - } - try( UnitOfWork uow = module.newUnitOfWork( usecase ) ) - { - FooTask task = uow.get( FooTask.class, taskId ); - assertThat( task.runCounter().get(), equalTo( 1 ) ); - assertThat( task.output().get(), equalTo( BAR ) ); - } - } - - @Test - public void testMinutely() - throws UnitOfWorkCompletionException - { - Usecase usecase = UsecaseBuilder.newUsecase( "TestMinutely" ); - DateTime start = new DateTime(); - String taskIdentity; - long sleepMillis; - try( UnitOfWork uow = module.newUnitOfWork( usecase ) ) - { - Scheduler scheduler = module.findService( Scheduler.class ).get(); - - FooTask task = createFooTask( uow, usecase.name(), BAZAR ); - taskIdentity = task.identity().get(); - - DateTime expectedRun = start.withMillisOfSecond( 0 ).withSecondOfMinute( 0 ).plusMinutes( 1 ); - scheduler.scheduleCron( task, "@minutely" ); - - uow.complete(); - - sleepMillis = new Interval( start, expectedRun ).toDurationMillis(); - LOGGER.info( "Task scheduled on {} to be run at {}", start.getMillis(), expectedRun.getMillis() ); - } - - await( usecase.name() ) - .atMost( sleepMillis + 5000, MILLISECONDS ) - .until( taskOutput( taskIdentity ), equalTo( 1 ) ); - - //noinspection unused - try( UnitOfWork uow = module.newUnitOfWork( usecase ) ) - { - Timeline timeline = module.findService( Timeline.class ).get(); - DateTime now = new DateTime(); - - // Queries returning past records - assertThat( count( timeline.getLastRecords( 5 ) ), - is( 2L ) ); - assertThat( count( timeline.getRecords( start.getMillis(), now.getMillis() ) ), - is( 2L ) ); - - // Queries returning future records - assertThat( count( timeline.getNextRecords( 4 ) ), - is( 4L ) ); - assertThat( count( timeline.getRecords( now.getMillis() + 100, now.plusMinutes( 5 ).getMillis() ) ), - is( 5L ) ); - - // Queries returning mixed past and future records - assertThat( count( timeline.getRecords( start.getMillis(), now.plusMinutes( 5 ).getMillis() ) ), - is( 7L ) ); - } - } - - @Test - public void testOnce() - throws UnitOfWorkCompletionException, InterruptedException - { - System.setProperty( "zest.entity.print.state", Boolean.TRUE.toString() ); - final Usecase usecase = UsecaseBuilder.newUsecase( "TestOnce" ); - final String taskIdentity; - Scheduler scheduler = module.findService( Scheduler.class ).get(); - - Schedule schedule1; - Schedule schedule2; - Schedule schedule3; - Schedule schedule4; - try( UnitOfWork uow = module.newUnitOfWork( usecase ) ) - { - FooTask task = createFooTask( uow, usecase.name(), BAZAR ); - taskIdentity = task.identity().get(); - - schedule1 = scheduler.scheduleOnce( task, 1 ); - schedule2 = scheduler.scheduleOnce( task, 2 ); - schedule3 = scheduler.scheduleOnce( task, 3 ); - schedule4 = scheduler.scheduleOnce( task, 4 ); - - uow.complete(); - } - await( usecase.name() ) - .atMost( 6, SECONDS ) - .until( taskOutput( taskIdentity ), equalTo( 4 ) ); - - try( UnitOfWork uow = module.newUnitOfWork( usecase ) ) - { - schedule1 = uow.get( schedule1 ); - schedule2 = uow.get( schedule2 ); - schedule3 = uow.get( schedule3 ); - schedule4 = uow.get( schedule4 ); - assertThat(schedule1.cancelled().get(), equalTo( false )); - assertThat(schedule2.cancelled().get(), equalTo( false )); - assertThat(schedule3.cancelled().get(), equalTo( false )); - assertThat(schedule4.cancelled().get(), equalTo( false )); - assertThat(schedule1.done().get(), equalTo( true )); - assertThat(schedule2.done().get(), equalTo( true )); - assertThat(schedule3.done().get(), equalTo( true )); - assertThat(schedule4.done().get(), equalTo( true )); - assertThat(schedule1.running().get(), equalTo( false )); - assertThat(schedule2.running().get(), equalTo( false )); - assertThat(schedule3.running().get(), equalTo( false )); - assertThat(schedule4.running().get(), equalTo( false )); - } - } - - private Callable<Integer> taskOutput( final String taskIdentity ) - { - return () -> { - try( UnitOfWork uow = module.newUnitOfWork() ) - { - FooTask task = uow.get( FooTask.class, taskIdentity ); - Integer count = task.runCounter().get(); - uow.discard(); - return count; - } - }; - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/docsupport/SchedulerDocs.java ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/docsupport/SchedulerDocs.java b/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/docsupport/SchedulerDocs.java deleted file mode 100644 index 998d36b..0000000 --- a/libraries/scheduler/src/test/java/org/apache/zest/library/scheduler/docsupport/SchedulerDocs.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2010-2014, Paul Merlin. - * Copyright (c) 2012, Niclas Hedhman. - * - * Licensed 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.zest.library.scheduler.docsupport; - -import org.apache.zest.api.association.Association; -import org.apache.zest.api.injection.scope.Service; -import org.apache.zest.api.injection.scope.This; -import org.apache.zest.api.property.Property; -import org.apache.zest.api.unitofwork.concern.UnitOfWorkDiscardOn; -import org.apache.zest.api.unitofwork.concern.UnitOfWorkPropagation; -import org.apache.zest.api.unitofwork.concern.UnitOfWorkRetry; -import org.apache.zest.library.scheduler.Scheduler; -import org.apache.zest.library.scheduler.Task; -import org.apache.zest.library.scheduler.Schedule; -import org.apache.zest.library.scheduler.timeline.Timeline; - -public class SchedulerDocs -{ - - // START SNIPPET: timeline - @Service - Timeline timeline; -// END SNIPPET: timeline - - // START SNIPPET: 2 - @Service - Scheduler scheduler; - - public void method() - { - MyTaskEntity myTask = todo(); - Schedule schedule = scheduler.scheduleOnce( myTask, 10 ); - // myTask will be run in 10 seconds from now - } - - // END SNIPPET: 2 - MyTaskEntity todo() - { - return null; - } - - // START SNIPPET: 1 - interface MyTaskEntity extends Task - { - Property<String> myTaskState(); - - Association<AnotherEntity> anotherEntity(); - } - - class MyTaskMixin implements Runnable - { - @This - MyTaskEntity me; - - @Override - public void run() - { - me.myTaskState().set( me.anotherEntity().get().doSomeStuff( me.myTaskState().get() ) ); - } - } - - // END SNIPPET: 1 - interface AnotherEntity - { - String doSomeStuff( String p ); - } - - public class MyTask implements Runnable - { - - // START SNIPPET: strategy - @Override - @UnitOfWorkRetry( retries = 3 ) - @UnitOfWorkDiscardOn( IllegalArgumentException.class ) - @UnitOfWorkPropagation( value = UnitOfWorkPropagation.Propagation.REQUIRES_NEW, usecase = "Load Data" ) - public void run() - { - // END SNIPPET: strategy - - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/551c04d5/libraries/scheduler/src/test/resources/logback-test.xml ---------------------------------------------------------------------- diff --git a/libraries/scheduler/src/test/resources/logback-test.xml b/libraries/scheduler/src/test/resources/logback-test.xml deleted file mode 100644 index 256127e..0000000 --- a/libraries/scheduler/src/test/resources/logback-test.xml +++ /dev/null @@ -1,32 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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. ---> -<configuration> - - <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"> - <layout class="ch.qos.logback.classic.PatternLayout"> - <Pattern>@%-10thread %-5level %logger{20} - %msg%n</Pattern> - </layout> - </appender> - - <root level="info"> - <appender-ref ref="stdout" /> - </root> - - <logger name="org.apache.zest.library.scheduler" level="trace"/> - -</configuration> \ No newline at end of file
