Search in sources :

Example 6 with JobExecutionContext

use of org.apache.sling.event.jobs.consumer.JobExecutionContext in project sling by apache.

the class JobHandlingTest method testSimpleJobExecutionUsingJobExecutor.

/**
     * Test simple job execution.
     * The job is executed once and finished successfully.
     */
@Test(timeout = DEFAULT_TEST_TIMEOUT)
public void testSimpleJobExecutionUsingJobExecutor() throws Exception {
    final Barrier cb = new Barrier(2);
    this.registerJobExecutor(TOPIC, new JobExecutor() {

        @Override
        public JobExecutionResult process(final Job job, final JobExecutionContext context) {
            cb.block();
            return context.result().succeeded();
        }
    });
    this.getJobManager().addJob(TOPIC, null);
    assertTrue("No event received in the given time.", cb.block(5));
    cb.reset();
    assertFalse("Unexpected event received in the given time.", cb.block(5));
}
Also used : JobExecutionResult(org.apache.sling.event.jobs.consumer.JobExecutionResult) JobExecutor(org.apache.sling.event.jobs.consumer.JobExecutor) JobExecutionContext(org.apache.sling.event.jobs.consumer.JobExecutionContext) Barrier(org.apache.sling.event.impl.Barrier) Job(org.apache.sling.event.jobs.Job) Test(org.junit.Test)

Aggregations

JobExecutionContext (org.apache.sling.event.jobs.consumer.JobExecutionContext)6 Job (org.apache.sling.event.jobs.Job)5 JobExecutionResult (org.apache.sling.event.jobs.consumer.JobExecutionResult)5 JobExecutor (org.apache.sling.event.jobs.consumer.JobExecutor)5 Test (org.junit.Test)5 Barrier (org.apache.sling.event.impl.Barrier)4 Event (org.osgi.service.event.Event)2 EventHandler (org.osgi.service.event.EventHandler)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1