jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1568232 - in /jena/branches/jena-fuseki-new-ui: docs/ src-dev/dev/ src/main/java/org/apache/jena/fuseki/async/ src/main/java/org/apache/jena/fuseki/server/ src/test/java/org/apache/jena/fuseki/ src/test/resources/
Date Fri, 14 Feb 2014 10:41:05 GMT
Author: andy
Date: Fri Feb 14 10:41:05 2014
New Revision: 1568232

URL: http://svn.apache.org/r1568232
Log:
More testing for async tests.
Clean up logging setup for testing.

Added:
    jena/branches/jena-fuseki-new-ui/docs/fuseki-logging.md
Modified:
    jena/branches/jena-fuseki-new-ui/docs/fuseki-main.md
    jena/branches/jena-fuseki-new-ui/src-dev/dev/PROJECT.java
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/async/AsyncPool.java
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/async/AsyncTask.java
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/FusekiServletContextListener.java
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SystemState.java
    jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TS_Fuseki.java
    jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TestAdmin.java
    jena/branches/jena-fuseki-new-ui/src/test/resources/log4j.properties

Added: jena/branches/jena-fuseki-new-ui/docs/fuseki-logging.md
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/docs/fuseki-logging.md?rev=1568232&view=auto
==============================================================================
--- jena/branches/jena-fuseki-new-ui/docs/fuseki-logging.md (added)
+++ jena/branches/jena-fuseki-new-ui/docs/fuseki-logging.md Fri Feb 14 10:41:05 2014
@@ -0,0 +1 @@
+# Fuseki Logging

Modified: jena/branches/jena-fuseki-new-ui/docs/fuseki-main.md
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/docs/fuseki-main.md?rev=1568232&r1=1568231&r2=1568232&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/docs/fuseki-main.md (original)
+++ jena/branches/jena-fuseki-new-ui/docs/fuseki-main.md Fri Feb 14 10:41:05 2014
@@ -25,4 +25,5 @@ Other parts:
 [fuseki-main](fuseki-main.html)
 [fuseki-protocol](fuseki-protocol.html)
 [fuseki-stats](fuseki-stats.html)
+[fuseki-logging](fuseki-logging.html)
 

Modified: jena/branches/jena-fuseki-new-ui/src-dev/dev/PROJECT.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src-dev/dev/PROJECT.java?rev=1568232&r1=1568231&r2=1568232&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src-dev/dev/PROJECT.java (original)
+++ jena/branches/jena-fuseki-new-ui/src-dev/dev/PROJECT.java Fri Feb 14 10:41:05 2014
@@ -19,10 +19,7 @@
 package dev;
 
 public class PROJECT {
-    // Backup and long-lived tasks.
-    
-    // Mixins: CopntainsItem + Async
-    //   Make ActionAsyncTask into a library AsyncLib
+    // POM changes from jena-fuseki.
     
     // Use ActionContainerItem for ActionDatasets
     // Use Action(Container)Item for ActionStats
@@ -34,9 +31,6 @@ public class PROJECT {
     //  -- contains a DS and can't put it down (update/in-memory) (+file)
     //  -- TDB various
     
-    // status -> two entries
-    // Cleaner -> access point -> dataService -> endpoints 
-    
     // --set affects the system DB! 
     
     // Backup task + polling

Modified: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/async/AsyncPool.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/async/AsyncPool.java?rev=1568232&r1=1568231&r2=1568232&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/async/AsyncPool.java
(original)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/async/AsyncPool.java
Fri Feb 14 10:41:05 2014
@@ -18,16 +18,18 @@
 
 package org.apache.jena.fuseki.async;
 
+import static java.lang.String.format ;
+
 import java.util.* ;
 import java.util.concurrent.* ;
-import java.util.concurrent.atomic.AtomicLong ;
 
+import org.apache.jena.fuseki.Fuseki ;
 import org.apache.jena.fuseki.server.DataService ;
 
 /** The set of currently active async tasks */
 public class AsyncPool
 {
-    private static int nMaxThreads = 2 ;
+    private static int nMaxThreads = 4 ;
     private static int MAX_FINISHED = 20 ;
     
     // See Executors.newCachedThreadPool and Executors.newFixedThreadPool 
@@ -35,7 +37,7 @@ public class AsyncPool
                                                               120L, TimeUnit.SECONDS,
                                                               new LinkedBlockingQueue<Runnable>())
;
     private final Object mutex = new Object() ; 
-    private AtomicLong counter = new AtomicLong(0) ;
+    private long counter = 0 ;
     private Map<String, AsyncTask> runningTasks = new LinkedHashMap<>() ; 
     private Map<String, AsyncTask> finishedTasks = new LinkedHashMap<>() ;
     
@@ -47,7 +49,8 @@ public class AsyncPool
     
     public AsyncTask submit(Runnable task, String displayName, DataService dataService) {

         synchronized(mutex) {
-            String taskId = Long.toString(counter.incrementAndGet()) ;
+            String taskId = Long.toString(++counter) ;
+            Fuseki.serverLog.info(format("Task : %s : %s",taskId, displayName)) ;
             Callable<Object> c = Executors.callable(task) ;
             AsyncTask asyncTask = new AsyncTask(c, this, taskId, displayName, dataService)
;
             Future<Object> x = executor.submit(asyncTask) ;

Modified: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/async/AsyncTask.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/async/AsyncTask.java?rev=1568232&r1=1568231&r2=1568232&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/async/AsyncTask.java
(original)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/async/AsyncTask.java
Fri Feb 14 10:41:05 2014
@@ -68,21 +68,23 @@ public class AsyncTask implements Callab
 
     private void start() {
         if ( startPoint != null ) {
-            String msg = format("[%s] Async task has already been started", taskId) ;
+            String msg = format("[Task %s] Async task has already been started", taskId)
;
             Log.warn(Fuseki.serverLog, msg) ;
             throw new InternalErrorException("Finish has already been called ["+getTaskId()+"]")
; 
         }
             
+        Fuseki.serverLog.info(format("[Task %s] starts : %s",taskId, displayName)) ;
         startPoint = Utils.nowAsXSDDateTimeString() ;
     }
     
     public void finish() {
         if ( finishPoint != null ) {
-            String msg = format("[%s] Async task has already been finished", taskId) ;
+            String msg = format("[Task %s] Async task has already been finished", taskId)
;
             Log.warn(Fuseki.serverLog, msg) ;
             throw new InternalErrorException("Finish has already been called ["+getTaskId()+"]")
; 
         }
         finishPoint = Utils.nowAsXSDDateTimeString() ;
+        Fuseki.serverLog.info(format("[Task %s] finishes : %s",taskId, displayName)) ;
     }
     
     @Override

Modified: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/FusekiServletContextListener.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/FusekiServletContextListener.java?rev=1568232&r1=1568231&r2=1568232&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/FusekiServletContextListener.java
(original)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/FusekiServletContextListener.java
Fri Feb 14 10:41:05 2014
@@ -46,7 +46,8 @@ public class FusekiServletContextListene
     @Override
     public void contextInitialized(ServletContextEvent sce) {
         confLog.info("contextInitialized");
-        ServletContext cxt = sce.getServletContext() ;
+        ServletContext servletContext = sce.getServletContext() ;
+        servletContext.log("") ;
         init() ;
     }
 

Modified: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java?rev=1568232&r1=1568231&r2=1568232&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java
(original)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java
Fri Feb 14 10:41:05 2014
@@ -38,6 +38,7 @@ import org.eclipse.jetty.security.authen
 import org.eclipse.jetty.server.* ;
 import org.eclipse.jetty.servlet.FilterHolder ;
 import org.eclipse.jetty.servlet.ServletContextHandler ;
+import org.eclipse.jetty.util.log.Log ;
 import org.eclipse.jetty.util.security.Constraint ;
 import org.eclipse.jetty.webapp.WebAppContext ;
 import org.eclipse.jetty.xml.XmlConfiguration ;
@@ -177,6 +178,15 @@ public class SPARQLServer {
         context.setDescriptor("war-web.xml");
         context.setResourceBase("pages");
         context.setContextPath("/");
+        
+        //-- Jetty setup for the ServletContext logger.
+        // The name of the Jetty-allocated slf4j/log4j logger is
+        // the display name or, if null, the context path name.   
+        // It is set, without checking for a previous call of setLogger in "doStart"
+        // which happens during server startup. 
+        // This the name of the ServletContext logger as well
+        context.setDisplayName(Fuseki.serverLogName);  
+        
         context.setParentLoaderPriority(true);  // Normal Java classloader behaviour.
         context.setErrorHandler(new FusekiErrorHandler()) ;
         server.setHandler(context) ;

Modified: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SystemState.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SystemState.java?rev=1568232&r1=1568231&r2=1568232&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SystemState.java
(original)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SystemState.java
Fri Feb 14 10:41:05 2014
@@ -23,6 +23,7 @@ import org.apache.jena.atlas.lib.StrUtil
 import org.apache.jena.fuseki.Fuseki ;
 
 import com.hp.hpl.jena.query.Dataset ;
+import com.hp.hpl.jena.tdb.TDB ;
 import com.hp.hpl.jena.tdb.TDBFactory ;
 import com.hp.hpl.jena.tdb.base.file.Location ;
 import com.hp.hpl.jena.tdb.transaction.DatasetGraphTransaction ;
@@ -59,6 +60,7 @@ public class SystemState {
             FileOps.ensureDir(location.getDirectoryPath()) ;
         dataset = TDBFactory.createDataset(location) ;
         dsg     = (DatasetGraphTransaction)(dataset.asDatasetGraph()) ;
+        dsg.getContext().set(TDB.symUnionDefaultGraph, false) ;
     }
 
     

Modified: jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TS_Fuseki.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TS_Fuseki.java?rev=1568232&r1=1568231&r2=1568232&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TS_Fuseki.java (original)
+++ jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TS_Fuseki.java Fri
Feb 14 10:41:05 2014
@@ -18,10 +18,14 @@
 
 package org.apache.jena.fuseki;
 
+import java.io.File ;
+
+import org.apache.jena.atlas.lib.StrUtils ;
 import org.apache.jena.atlas.logging.LogCtl ;
 import org.apache.jena.fuseki.http.TestDatasetAccessorHTTP ;
 import org.apache.jena.fuseki.http.TestDatasetGraphAccessorHTTP ;
 import org.apache.jena.fuseki.http.TestHttpOp ;
+import org.apache.jena.riot.SysRIOT ;
 import org.junit.AfterClass ;
 import org.junit.BeforeClass ;
 import org.junit.runner.RunWith ;

Modified: jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TestAdmin.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TestAdmin.java?rev=1568232&r1=1568231&r2=1568232&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TestAdmin.java (original)
+++ jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TestAdmin.java Fri
Feb 14 10:41:05 2014
@@ -45,6 +45,7 @@ import org.apache.jena.atlas.json.JsonAr
 import org.apache.jena.atlas.json.JsonObject ;
 import org.apache.jena.atlas.json.JsonValue ;
 import org.apache.jena.atlas.junit.BaseTest ;
+import org.apache.jena.atlas.lib.Lib ;
 import org.apache.jena.atlas.web.HttpException ;
 import org.apache.jena.atlas.web.TypedInputStream ;
 import org.apache.jena.riot.WebContent ;
@@ -259,12 +260,74 @@ public class TestAdmin extends BaseTest 
         deleteDataset(dsTest) ;
     }
 
+    // Sync task testing
+    
     @Test public void task_1() {
         String x = execSleepTask(null, 10) ;
         assertNotNull(x) ;
         Integer.parseInt(x) ;
     }
     
+    @Test public void task_2() {
+        String x = "NoSuchTask" ;
+        String url = urlRoot+"$/tasks/"+x ;
+        try {
+            httpGetJson(url) ;
+        } catch (HttpException ex) {
+            assertEquals(404, ex.getResponseCode()) ;
+        }
+        try { 
+            checkInTasks(x) ;
+            fail("No failure!") ;
+        } catch (AssertionError ex) {}
+    }
+
+    
+    @Test public void task_3() {
+        // Timing dependent.
+        // Create a "long" running task so we can find it.  
+        String x = execSleepTask(null, 100) ;
+        checkTask(x) ;
+        checkInTasks(x) ;
+        assertNotNull(x) ;
+        Integer.parseInt(x) ;
+    }
+
+    @Test public void task_4() {
+        // Timing dependent.
+        // Create a "short" running task  
+        String x = execSleepTask(null, 1) ;
+        // Check exists in the list of all tasks (should be "finished")
+        checkInTasks(x) ;
+        String url = urlRoot+"$/tasks/"+x ;
+        
+        boolean finished = false ; 
+        for ( int i = 0 ; i < 10 ; i++ ) {
+            if ( i != 0 )
+                Lib.sleep(25) ;
+            JsonValue v = httpGetJson(url) ;
+            checkTask(v) ;
+            if ( v.getAsObject().hasKey("finished") ) {
+                finished = true ;
+                break ;
+            }
+        }
+        if ( ! finished )
+            fail("Task has not finished") ;
+    }
+    
+    @Test public void task_5() {
+        // Short ruuning task - still in info API call.
+        String x = execSleepTask(null, 1) ;
+        checkInTasks(x) ;
+    }
+
+    private JsonValue getTask(String taskId) {
+        String url = urlRoot+"$/tasks/"+taskId ;
+        return httpGetJson(url) ;
+    }
+    
+
     static class JsonResponseHandler implements HttpResponseHandler {
 
         private JsonValue result = null ;
@@ -283,6 +346,8 @@ public class TestAdmin extends BaseTest 
         
     }
     
+    
+    
     private String execSleepTask(String name, int millis) {
         String url = urlRoot+"$/sleep" ;
         if ( name != null ) {
@@ -294,10 +359,55 @@ public class TestAdmin extends BaseTest 
         JsonResponseHandler x = new JsonResponseHandler() ; 
         HttpOp.execHttpPost(url+"?interval="+millis, null, WebContent.contentTypeJSON, x)
;
         JsonValue v = x.getJSON() ;
-        String id = v.getAsObject().get("taskId").getAsString().toString() ;
+        String id = v.getAsObject().get("taskId").getAsString().value() ;
         return id ;
     }
 
+    private JsonValue httpGetJson(String url) {
+        JsonResponseHandler x = new JsonResponseHandler() ; 
+        HttpOp.execHttpGet(url, WebContent.contentTypeJSON, x) ;
+        return x.getJSON() ;
+    }
+    
+    private void checkTask(String x) {
+        String url = urlRoot+"$/tasks/"+x ;
+        JsonValue v = httpGetJson(url) ;
+        checkTask(v) ;
+    }    
+    
+    private void checkTask(JsonValue v) {
+        assertNotNull(v) ;
+        assertTrue(v.isObject()) ;
+        //System.out.println(v) ;
+        JsonObject obj = v.getAsObject() ;
+        try {
+            assertTrue(obj.hasKey("task")) ;
+            assertTrue(obj.hasKey("taskId")) ;
+            // Not present until it runs : "started"
+        } catch (AssertionError ex) { 
+            System.out.println(obj) ;
+            throw ex ; 
+        }
+    }
+        
+   private void checkInTasks(String x) {
+       String url = urlRoot+"$/tasks" ;
+       JsonValue v = httpGetJson(url) ;
+       assertTrue(v.isArray()) ;
+       JsonArray array = v.getAsArray() ; 
+       int found = 0 ;
+       for ( int i = 0 ; i < array.size() ; i++ ) {
+           JsonValue jv = array.get(i) ;
+           assertTrue(jv.isObject()) ;
+           JsonObject obj = jv.getAsObject() ;
+           checkTask(obj) ;
+           if ( obj.get("taskId").getAsString().value().equals(x) ) {
+               found++ ;
+           }
+        }
+       assertEquals("Occurence of taskId count", 1, found) ;
+    }
+
     // Auxilary
     
     private static void askPing(String name) {

Modified: jena/branches/jena-fuseki-new-ui/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/test/resources/log4j.properties?rev=1568232&r1=1568231&r2=1568232&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/test/resources/log4j.properties (original)
+++ jena/branches/jena-fuseki-new-ui/src/test/resources/log4j.properties Fri Feb 14 10:41:05
2014
@@ -12,13 +12,16 @@ log4j.logger.org.apache.jena=WARN
 log4j.logger.org.apache.jena.riot=INFO
 
 # Jetty - Fuseki catches Jetty errors and reports them.
-log4j.logger.org.eclipse.jetty=FATAL
+log4j.logger.org.eclipse.jetty=WARN
+log4j.logger.org.apache.jena.tdb.loader=INFO
+log4j.logger.org.apache.shiro=WARN
 
 # Fuseki
-## log4j.logger.org.apache.jena.fuseki.Server=WARN
-## log4j.logger.org.apache.jena.fuseki.Fuseki=WARN
-## log4j.logger.org.apache.jena.fuseki=WARN
-
-log4j.logger.org.apache.jena.fuseki.Server=INFO
-log4j.logger.org.apache.jena.fuseki.Fuseki=INFO
-log4j.logger.org.apache.jena.fuseki=INFO
\ No newline at end of file
+log4j.logger.org.apache.jena.fuseki.Server=WARN
+log4j.logger.org.apache.jena.fuseki.Config=WARN
+log4j.logger.org.apache.jena.fuseki.Admin=WARN
+log4j.logger.org.apache.jena.fuseki.Builder=WARN
+## Request log.
+log4j.logger.org.apache.jena.fuseki.Fuseki=WARN
+log4j.logger.org.apache.jena.fuseki=INFO
+## ServletContext 



Mime
View raw message