use of org.apache.sling.event.jobs.consumer.JobExecutor in project sling by apache.
the class TopicMatchingTest method testDeepMatching.
/**
* Test deep pattern matching /**
*/
@Test(timeout = DEFAULT_TEST_TIMEOUT)
public void testDeepMatching() throws Exception {
final Barrier barrier = new Barrier(2);
this.registerJobExecutor("sling/**", new JobExecutor() {
@Override
public JobExecutionResult process(final Job job, final JobExecutionContext context) {
return context.result().succeeded();
}
});
this.registerEventHandler(NotificationConstants.TOPIC_JOB_FINISHED, new EventHandler() {
@Override
public void handleEvent(final Event event) {
barrier.block();
}
});
this.getJobManager().addJob(TOPIC, null);
barrier.block();
}
use of org.apache.sling.event.jobs.consumer.JobExecutor in project sling by apache.
the class TopicMatchingTest method testSimpleMatching.
/**
* Test simple pattern matching /*
*/
@Test(timeout = DEFAULT_TEST_TIMEOUT)
public void testSimpleMatching() throws Exception {
final Barrier barrier = new Barrier(2);
this.registerJobExecutor("sling/test/*", new JobExecutor() {
@Override
public JobExecutionResult process(final Job job, final JobExecutionContext context) {
return context.result().succeeded();
}
});
this.registerEventHandler(NotificationConstants.TOPIC_JOB_FINISHED, new EventHandler() {
@Override
public void handleEvent(final Event event) {
barrier.block();
}
});
this.getJobManager().addJob(TOPIC, null);
barrier.block();
}
use of org.apache.sling.event.jobs.consumer.JobExecutor in project sling by apache.
the class JobConsumerManagerTest method testCategoryMappingExecutor.
@Test
public void testCategoryMappingExecutor() {
final BundleContext bc = Mockito.mock(BundleContext.class);
final JobConsumerManager jcs = new JobConsumerManager();
jcs.activate(bc, getDefaultConfig());
final JobExecutor jc1 = Mockito.mock(JobExecutor.class);
final ServiceReference ref1 = Mockito.mock(ServiceReference.class);
Mockito.when(ref1.getProperty(JobExecutor.PROPERTY_TOPICS)).thenReturn("a/*");
Mockito.when(ref1.getProperty(Constants.SERVICE_RANKING)).thenReturn(1);
Mockito.when(ref1.getProperty(Constants.SERVICE_ID)).thenReturn(1L);
Mockito.when(bc.getService(ref1)).thenReturn(jc1);
jcs.bindJobExecutor(ref1);
assertNotNull(jcs.getExecutor("a/b"));
assertNull(jcs.getExecutor("a"));
assertNotNull(jcs.getExecutor("a/c"));
assertNull(jcs.getExecutor("a/b/a"));
}
use of org.apache.sling.event.jobs.consumer.JobExecutor in project sling by apache.
the class JobConsumerManagerTest method testSubCategoryMappingExecutor.
@Test
public void testSubCategoryMappingExecutor() {
final BundleContext bc = Mockito.mock(BundleContext.class);
final JobConsumerManager jcs = new JobConsumerManager();
jcs.activate(bc, getDefaultConfig());
final JobExecutor jc1 = Mockito.mock(JobExecutor.class);
final ServiceReference ref1 = Mockito.mock(ServiceReference.class);
Mockito.when(ref1.getProperty(JobExecutor.PROPERTY_TOPICS)).thenReturn("a/**");
Mockito.when(ref1.getProperty(Constants.SERVICE_RANKING)).thenReturn(1);
Mockito.when(ref1.getProperty(Constants.SERVICE_ID)).thenReturn(1L);
Mockito.when(bc.getService(ref1)).thenReturn(jc1);
jcs.bindJobExecutor(ref1);
assertNotNull(jcs.getExecutor("a/b"));
assertNull(jcs.getExecutor("a"));
assertNotNull(jcs.getExecutor("a/c"));
assertNotNull(jcs.getExecutor("a/b/a"));
}
use of org.apache.sling.event.jobs.consumer.JobExecutor in project sling by apache.
the class TopicMatchingTest method testOrdering.
/**
* Test ordering of matchers
*/
@Test(timeout = DEFAULT_TEST_TIMEOUT)
public void testOrdering() throws Exception {
final Barrier barrier1 = new Barrier(2);
final Barrier barrier2 = new Barrier(2);
final Barrier barrier3 = new Barrier(2);
this.registerJobExecutor("sling/**", new JobExecutor() {
@Override
public JobExecutionResult process(final Job job, final JobExecutionContext context) {
barrier1.block();
return context.result().succeeded();
}
});
final ServiceRegistration<JobExecutor> reg2 = this.registerJobExecutor("sling/test/*", new JobExecutor() {
@Override
public JobExecutionResult process(final Job job, final JobExecutionContext context) {
barrier2.block();
return context.result().succeeded();
}
});
final ServiceRegistration<JobExecutor> reg3 = this.registerJobExecutor(TOPIC, new JobExecutor() {
@Override
public JobExecutionResult process(final Job job, final JobExecutionContext context) {
barrier3.block();
return context.result().succeeded();
}
});
// first test, all three registered, reg3 should get the precedence
this.getJobManager().addJob(TOPIC, null);
barrier3.block();
// second test, unregister reg3, now it should be reg2
long cc = this.getConsumerChangeCount();
this.unregister(reg3);
this.waitConsumerChangeCount(cc + 1);
this.getJobManager().addJob(TOPIC, null);
barrier2.block();
// third test, unregister reg2, reg1 is now the only one
cc = this.getConsumerChangeCount();
this.unregister(reg2);
this.waitConsumerChangeCount(cc + 1);
this.getJobManager().addJob(TOPIC, null);
barrier1.block();
}
Aggregations