You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by en...@apache.org on 2011/11/17 17:33:54 UTC
svn commit: r1203249 - in
/incubator/stanbol/branches/lto-reasoners/reasoners: ./
services-tests/src/test/java/org/apache/stanbol/reasoners/it/offline/
test/src/main/java/org/apache/stanbol/reasoners/test/
web/src/main/java/org/apache/stanbol/reasoners...
Author: enridaga
Date: Thu Nov 17 16:33:54 2011
New Revision: 1203249
URL: http://svn.apache.org/viewvc?rev=1203249&view=rev
Log:
* Started runtime tests for reasoning jobs (still missing tests on concurrency)
* Moved some shared methods to the shared test mini framework
* Added a ftl for displaying results of bg jobs in html
* Create a profile do-tests to launch runtime tests
* Minor modifications on the Jobs jax-rs resource
All this belong to STANBOL-379 and STANBOL-343
Added:
incubator/stanbol/branches/lto-reasoners/reasoners/services-tests/src/test/java/org/apache/stanbol/reasoners/it/offline/ReasonersOfflineJobsTest.java
incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/
incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/result.ftl
Modified:
incubator/stanbol/branches/lto-reasoners/reasoners/pom.xml
incubator/stanbol/branches/lto-reasoners/reasoners/services-tests/src/test/java/org/apache/stanbol/reasoners/it/offline/ReasonersOfflineTest.java
incubator/stanbol/branches/lto-reasoners/reasoners/test/src/main/java/org/apache/stanbol/reasoners/test/ReasonersTestBase.java
incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/JobsResource.java
incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java
Modified: incubator/stanbol/branches/lto-reasoners/reasoners/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/lto-reasoners/reasoners/pom.xml?rev=1203249&r1=1203248&r2=1203249&view=diff
==============================================================================
--- incubator/stanbol/branches/lto-reasoners/reasoners/pom.xml (original)
+++ incubator/stanbol/branches/lto-reasoners/reasoners/pom.xml Thu Nov 17 16:33:54 2011
@@ -49,5 +49,15 @@
<module>owllink</module>
<module>web</module>
</modules>
-
+ <profiles>
+ <profile>
+ <id>do-tests</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <modules>
+ <module>services-tests</module>
+ </modules>
+ </profile>
+</profiles>
</project>
Added: incubator/stanbol/branches/lto-reasoners/reasoners/services-tests/src/test/java/org/apache/stanbol/reasoners/it/offline/ReasonersOfflineJobsTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/lto-reasoners/reasoners/services-tests/src/test/java/org/apache/stanbol/reasoners/it/offline/ReasonersOfflineJobsTest.java?rev=1203249&view=auto
==============================================================================
--- incubator/stanbol/branches/lto-reasoners/reasoners/services-tests/src/test/java/org/apache/stanbol/reasoners/it/offline/ReasonersOfflineJobsTest.java (added)
+++ incubator/stanbol/branches/lto-reasoners/reasoners/services-tests/src/test/java/org/apache/stanbol/reasoners/it/offline/ReasonersOfflineJobsTest.java Thu Nov 17 16:33:54 2011
@@ -0,0 +1,71 @@
+package org.apache.stanbol.reasoners.it.offline;
+
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.exec.Executor;
+import org.apache.stanbol.commons.testing.http.Request;
+import org.apache.stanbol.reasoners.it.offline.ReasonersOfflineTest;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests background jobs
+ *
+ */
+public class ReasonersOfflineJobsTest extends ReasonersOfflineTest {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @BeforeClass
+ public static void prepare() throws URISyntaxException {
+ ReasonersOfflineTest.prepare();
+ }
+
+ @Before
+ public void setupMultipart() {
+ super.setupMultipart();
+ }
+
+ @Test
+ public void testSubsequentJobs() throws Exception{
+ log.info("testSimpleJob()");
+ // We send a file to a job then we ping it, we do this for all services and tasks
+
+ for(String s : allServices() ){
+ for(String t : TASKS){
+ StringBuilder sb = new StringBuilder(REASONERS_PATH);
+ sb.append(s).append(t).append("/job");
+ Request request = buildMultipartRequest(sb.toString(),multiPart);
+ executeAndPingSingleJob(request);
+ }
+ }
+ }
+
+ @Test
+ public void testSubsequentJobs2() throws Exception{
+ log.info("testSubsequentJobs2()");
+
+ // We start all jobs and the we ping all
+ List<String> jids = new ArrayList<String>();
+ for(String s : allServices() ){
+ for(String t : TASKS){
+ StringBuilder sb = new StringBuilder(REASONERS_PATH);
+ sb.append(s).append(t).append("/job");
+ Request request = buildMultipartRequest(sb.toString(), multiPart);
+ String jid = job(request);
+ log.info("Started job {}", jid);
+ jids.add(jid);
+ }
+ }
+
+ // We ping all in sequence
+ for(String jid : jids){
+ pingSingleJob(jid);
+ }
+ }
+}
Modified: incubator/stanbol/branches/lto-reasoners/reasoners/services-tests/src/test/java/org/apache/stanbol/reasoners/it/offline/ReasonersOfflineTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/lto-reasoners/reasoners/services-tests/src/test/java/org/apache/stanbol/reasoners/it/offline/ReasonersOfflineTest.java?rev=1203249&r1=1203248&r2=1203249&view=diff
==============================================================================
--- incubator/stanbol/branches/lto-reasoners/reasoners/services-tests/src/test/java/org/apache/stanbol/reasoners/it/offline/ReasonersOfflineTest.java (original)
+++ incubator/stanbol/branches/lto-reasoners/reasoners/services-tests/src/test/java/org/apache/stanbol/reasoners/it/offline/ReasonersOfflineTest.java Thu Nov 17 16:33:54 2011
@@ -34,10 +34,10 @@ import org.slf4j.LoggerFactory;
*
*/
public class ReasonersOfflineTest extends ReasonersTestBase {
- private static String fileName = null;
- private String fileParam = "file";
- private static File file = null;
- private MultipartEntity multiPart = null;
+ protected static String fileName = null;
+ protected String fileParam = "file";
+ protected static File file = null;
+ protected MultipartEntity multiPart = null;
private final Logger log = LoggerFactory.getLogger(getClass());
@@ -156,6 +156,7 @@ public class ReasonersOfflineTest extend
*/
@Test
public void testOutputFormats() throws Exception{
+ log.info("testOutputFormats()");
final String[] formats = {
// Each group of 3 elements is: Accept header, Expected content-type,
// Expected regexp
Modified: incubator/stanbol/branches/lto-reasoners/reasoners/test/src/main/java/org/apache/stanbol/reasoners/test/ReasonersTestBase.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/lto-reasoners/reasoners/test/src/main/java/org/apache/stanbol/reasoners/test/ReasonersTestBase.java?rev=1203249&r1=1203248&r2=1203249&view=diff
==============================================================================
--- incubator/stanbol/branches/lto-reasoners/reasoners/test/src/main/java/org/apache/stanbol/reasoners/test/ReasonersTestBase.java (original)
+++ incubator/stanbol/branches/lto-reasoners/reasoners/test/src/main/java/org/apache/stanbol/reasoners/test/ReasonersTestBase.java Thu Nov 17 16:33:54 2011
@@ -8,12 +8,15 @@ import org.apache.http.client.methods.Ht
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.stanbol.commons.testing.http.Request;
import org.apache.stanbol.commons.testing.stanbol.StanbolTestBase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ReasonersTestBase extends StanbolTestBase{
protected final String REASONERS_PATH = "/reasoners";
protected final String[] SERVICES = {"/owl", "/owlmini", "/rdfs"};
protected final String[] TASKS = {"/check", "/classify", "/enrich"};
+ private final Logger log = LoggerFactory.getLogger(getClass());
protected Request buildMultipartRequest(String path,MultipartEntity multiPart) {
HttpPost httpPost = new HttpPost(builder.buildUrl(path));
@@ -30,4 +33,36 @@ public class ReasonersTestBase extends S
sl.addAll(Arrays.asList(SERVICES));
return sl;
}
+
+
+ // Evoke the job service, returns the job Id
+ protected String job(Request request) throws Exception{
+ return executor.execute(request).assertStatus(200).getContent();
+ }
+
+ //
+ protected void executeAndPingSingleJob(Request request) throws Exception{
+ log.info("Executing: {}", request.getRequest().getURI());
+ String jid = job(request);
+ log.info("jid is {}", jid);
+ // Get the result and ping the jId
+ pingSingleJob(jid);
+ }
+
+ //
+ protected void pingSingleJob(String jid) throws Exception{
+ String url = REASONERS_PATH + "/jobs/ping/" + jid;
+ log.info("Pinging {} ... ", url);
+ boolean waiting = true;
+ while(waiting){
+ String content = executor.execute(builder.buildGetRequest(url)).assertStatus(200).getContent();
+ if(content.equals("Job is still working")){
+ log.info(" ... still working ...");
+ Thread.sleep(500);
+ }else{
+ waiting = false;
+ log.info(" ... done!");
+ }
+ }
+ }
}
Modified: incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/JobsResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/JobsResource.java?rev=1203249&r1=1203248&r2=1203249&view=diff
==============================================================================
--- incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/JobsResource.java (original)
+++ incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/JobsResource.java Thu Nov 17 16:33:54 2011
@@ -8,7 +8,6 @@ import javax.servlet.ServletContext;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
-import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
@@ -63,8 +62,9 @@ public class JobsResource extends BaseSt
Object o;
try {
o = f.get();
- if(o instanceof ReasoningServiceResult<?>){
- ReasoningServiceResult<?> result = (ReasoningServiceResult<?>) f.get();
+ if(o instanceof ReasoningServiceResult){
+ log.debug("Is a ReasoningServiceResult");
+ ReasoningServiceResult<?> result = (ReasoningServiceResult<?>) o;
return new ResponseTaskBuilder(uriInfo,context,headers).build(result);
}else if(o instanceof String){
// FIXME We keep this for the moment, must remove later on
Modified: incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java?rev=1203249&r1=1203248&r2=1203249&view=diff
==============================================================================
--- incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java (original)
+++ incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/java/org/apache/stanbol/reasoners/web/resources/ReasoningServiceTaskResource.java Thu Nov 17 16:33:54 2011
@@ -226,7 +226,7 @@ public class ReasoningServiceTaskResourc
private Response processBackgroundRequest(){
// If parameters is empty it's a bad request...
if (this.parameters.isEmpty()) {
- log.error("Cannot start job without input parameters...");
+ log.error("Cannot start job without input parameters... sending BAD REQUEST");
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
String target = getTarget();
Added: incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/result.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/result.ftl?rev=1203249&view=auto
==============================================================================
--- incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/result.ftl (added)
+++ incubator/stanbol/branches/lto-reasoners/reasoners/web/src/main/resources/org/apache/stanbol/reasoners/web/templates/org/apache/stanbol/reasoners/web/resources/JobsResource/result.ftl Thu Nov 17 16:33:54 2011
@@ -0,0 +1,27 @@
+<#--
+ 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.
+-->
+<#import "/imports/common.ftl" as common>
+<#escape x as x?html>
+<@common.page title="Reasoners: Background Job Result" hasrestapi=false>
+
+ <div class="panel">
+<pre>
+${it.result}
+</pre>
+</div>
+ </...@common.page>
+</#escape>
\ No newline at end of file