You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2014/10/16 16:38:34 UTC
svn commit: r1632323 - in /sling/trunk/bundles/extensions/event: pom.xml
src/test/java/org/apache/sling/event/it/JobHandlingTest.java
Author: cziegeler
Date: Thu Oct 16 14:38:34 2014
New Revision: 1632323
URL: http://svn.apache.org/r1632323
Log:
SLING-4048 : Avoid keeping jobs in memory. Enable tests again and add more basic tests (WiP)
Modified:
sling/trunk/bundles/extensions/event/pom.xml
sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/it/JobHandlingTest.java
Modified: sling/trunk/bundles/extensions/event/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/pom.xml?rev=1632323&r1=1632322&r2=1632323&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/pom.xml (original)
+++ sling/trunk/bundles/extensions/event/pom.xml Thu Oct 16 14:38:34 2014
@@ -116,7 +116,7 @@
-Xmx2048m -XX:MaxPermSize=512m
</argLine>
<includes>
- <include>**/it/Foo*</include>
+ <include>**/it/*</include>
</includes>
</configuration>
</plugin>
Modified: sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/it/JobHandlingTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/it/JobHandlingTest.java?rev=1632323&r1=1632322&r2=1632323&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/it/JobHandlingTest.java (original)
+++ sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/it/JobHandlingTest.java Thu Oct 16 14:38:34 2014
@@ -41,8 +41,12 @@ import org.apache.sling.event.jobs.Job;
import org.apache.sling.event.jobs.JobManager;
import org.apache.sling.event.jobs.JobProcessor;
import org.apache.sling.event.jobs.JobUtil;
+import org.apache.sling.event.jobs.NotificationConstants;
import org.apache.sling.event.jobs.QueueConfiguration;
import org.apache.sling.event.jobs.consumer.JobConsumer;
+import org.apache.sling.event.jobs.consumer.JobExecutionContext;
+import org.apache.sling.event.jobs.consumer.JobExecutionResult;
+import org.apache.sling.event.jobs.consumer.JobExecutor;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -105,10 +109,10 @@ public class JobHandlingTest extends Abs
* The job is executed once and finished successfully.
*/
@Test(timeout = DEFAULT_TEST_TIMEOUT)
- public void testSimpleJobExecution() throws Exception {
+ public void testSimpleJobExecutionUsingBridge() throws Exception {
final Barrier cb = new Barrier(2);
- final ServiceRegistration reg = this.registerEventHandler("sling/test",
+ final ServiceRegistration reg = this.registerEventHandler(TOPIC,
new EventHandler() {
@Override
public void handleEvent(Event event) {
@@ -129,28 +133,80 @@ public class JobHandlingTest extends Abs
}
}
+ /**
+ * Test simple job execution.
+ * The job is executed once and finished successfully.
+ */
@Test(timeout = DEFAULT_TEST_TIMEOUT)
- public void testManyJobs() throws Exception {
- final ServiceRegistration reg1 = this.registerEventHandler("sling/test",
- new EventHandler() {
+ public void testSimpleJobExecutionUsingJobConsumer() throws Exception {
+ final Barrier cb = new Barrier(2);
+
+ final ServiceRegistration reg = this.registerJobConsumer(TOPIC,
+ new JobConsumer() {
+
+ @Override
+ public JobResult process(final Job job) {
+ cb.block();
+ return JobResult.OK;
+ }
+ });
+
+ try {
+ this.eventAdmin.sendEvent(getJobEvent(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));
+ } finally {
+ reg.unregister();
+ }
+ }
+
+ /**
+ * 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);
+
+ final ServiceRegistration reg = this.registerJobExecutor(TOPIC,
+ new JobExecutor() {
+
@Override
- public void handleEvent(Event event) {
- JobUtil.processJob(event, new JobProcessor() {
+ public JobExecutionResult process(final Job job, final JobExecutionContext context) {
+ cb.block();
+ return context.result().succeeded();
+ }
+ });
- @Override
- public boolean process(Event job) {
- try {
- Thread.sleep(200);
- } catch (InterruptedException ie) {
- // ignore
- }
- return true;
- }
- });
+ try {
+ this.eventAdmin.sendEvent(getJobEvent(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));
+ } finally {
+ reg.unregister();
+ }
+ }
+
+ @Test(timeout = DEFAULT_TEST_TIMEOUT)
+ public void testManyJobs() throws Exception {
+ final ServiceRegistration reg1 = this.registerJobConsumer(TOPIC,
+ new JobConsumer() {
+
+ @Override
+ public JobResult process(final Job job) {
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException ie) {
+ // ignore
+ }
+ return JobResult.OK;
}
+
});
final AtomicInteger count = new AtomicInteger(0);
- final ServiceRegistration reg2 = this.registerEventHandler(JobUtil.TOPIC_JOB_FINISHED,
+ final ServiceRegistration reg2 = this.registerEventHandler(NotificationConstants.TOPIC_JOB_FINISHED,
new EventHandler() {
@Override
public void handleEvent(Event event) {
@@ -162,8 +218,7 @@ public class JobHandlingTest extends Abs
// we start "some" jobs
final int COUNT = 300;
for(int i = 0; i < COUNT; i++ ) {
-// final String queueName = "queue" + (i % 20);
- this.eventAdmin.sendEvent(this.getJobEvent(null));
+ this.getJobManager().addJob(TOPIC, null);
}
while ( count.get() < COUNT ) {
try {
@@ -359,7 +414,7 @@ public class JobHandlingTest extends Abs
});
try {
final JobManager jobManager = this.getJobManager();
- final Job job = jobManager.addJob(TOPIC, null, null);
+ final Job job = jobManager.addJob(TOPIC, null);
assertTrue("No event received in the given time.", cb.block(5));
cb.reset();
@@ -428,7 +483,7 @@ public class JobHandlingTest extends Abs
return JobResult.FAILED;
}
});
- final ServiceRegistration eh1Reg = this.registerEventHandler(JobUtil.TOPIC_JOB_CANCELLED,
+ final ServiceRegistration eh1Reg = this.registerEventHandler(NotificationConstants.TOPIC_JOB_CANCELLED,
new EventHandler() {
@Override
@@ -437,7 +492,7 @@ public class JobHandlingTest extends Abs
cancelled.add(id);
}
});
- final ServiceRegistration eh2Reg = this.registerEventHandler(JobUtil.TOPIC_JOB_FAILED,
+ final ServiceRegistration eh2Reg = this.registerEventHandler(NotificationConstants.TOPIC_JOB_FAILED,
new EventHandler() {
@Override
@@ -446,7 +501,7 @@ public class JobHandlingTest extends Abs
failed.add(id);
}
});
- final ServiceRegistration eh3Reg = this.registerEventHandler(JobUtil.TOPIC_JOB_FINISHED,
+ final ServiceRegistration eh3Reg = this.registerEventHandler(NotificationConstants.TOPIC_JOB_FINISHED,
new EventHandler() {
@Override
@@ -455,7 +510,7 @@ public class JobHandlingTest extends Abs
finished.add(id);
}
});
- final ServiceRegistration eh4Reg = this.registerEventHandler(JobUtil.TOPIC_JOB_STARTED,
+ final ServiceRegistration eh4Reg = this.registerEventHandler(NotificationConstants.TOPIC_JOB_STARTED,
new EventHandler() {
@Override
@@ -534,7 +589,7 @@ public class JobHandlingTest extends Abs
unprocessedCount.incrementAndGet();
}
});
- final ServiceRegistration eh3 = this.registerEventHandler(JobUtil.TOPIC_JOB_FINISHED,
+ final ServiceRegistration eh3 = this.registerEventHandler(NotificationConstants.TOPIC_JOB_FINISHED,
new EventHandler() {
@Override