jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1552113 - in /jena/branches/jena-fuseki-new-ui/src: main/java/org/apache/jena/fuseki/ main/java/org/apache/jena/fuseki/mgt/ main/java/org/apache/jena/fuseki/server/ test/java/org/apache/jena/fuseki/
Date Wed, 18 Dec 2013 21:34:21 GMT
Author: andy
Date: Wed Dec 18 21:34:21 2013
New Revision: 1552113

URL: http://svn.apache.org/r1552113
Log:
More testing.

Modified:
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/X_Config.java
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java
    jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/ServerTest.java
    jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TestAdmin.java

Modified: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/X_Config.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/X_Config.java?rev=1552113&r1=1552112&r2=1552113&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/X_Config.java (original)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/X_Config.java Wed
Dec 18 21:34:21 2013
@@ -51,9 +51,10 @@ public class X_Config {
             throw new FusekiConfigException("Already registered: key = "+datasetPath) ;
         DatasetRegistry.get().put(datasetPath, dsDesc) ;
         serverLog.info(format("Dataset path = %s", datasetPath)) ;
+        X_Config.addJMX(dsDesc) ;
     }
     
-    public static void addJMX() {
+    public static void XaddJMX() {
         DatasetRegistry registry = DatasetRegistry.get() ;
         for (String ds : registry.keys()) {
             DatasetRef dsRef = registry.get(ds) ;

Modified: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java?rev=1552113&r1=1552112&r2=1552113&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
(original)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
Wed Dec 18 21:34:21 2013
@@ -110,11 +110,6 @@ public class ActionDatasets extends Acti
             execDelete(action) ;
         else
             ServletOps.error(HttpSC.METHOD_NOT_ALLOWED_405) ;
-        
-//      system.begin(ReadWrite.READ) ;
-//      try { RDFDataMgr.write(System.out, system, Lang.TRIG); }
-//      finally { system.end() ; }
-
     }
 
     protected void execGet(HttpAction action) {
@@ -131,8 +126,9 @@ public class ActionDatasets extends Acti
             JSON.write(out, v) ;
             out.println() ; 
             out.flush() ;
+            ServletOps.success(action);
         } catch (IOException ex) { ServletOps.errorOccurred(ex) ; }
-        ServletOps.success(action);
+        
     }
     
     // This does not consult the system database for dormant etc.
@@ -146,7 +142,7 @@ public class ActionDatasets extends Acti
     }
 
     private JsonValue execGetDataset(HttpAction action) {
-        action.log.info(format("[%d] GET ds=%s", action.id, action.dsRef.name)) ;
+        action.log.info(format("[%d] GET dataset %s", action.id, action.dsRef.name)) ;
         JsonBuilder builder = new JsonBuilder() ;
         String datasetPath = DatasetRef.canocialDatasetPath(action.dsRef.name) ;
         DatasetRef dsDesc = DatasetRegistry.get().get(datasetPath) ;
@@ -256,10 +252,15 @@ public class ActionDatasets extends Acti
                 action.log.warn(format("[%d] Service name '%s' is not a string", action.id,
FmtUtils.stringForRDFNode(object)));
 
             String datasetName = object.getLexicalForm() ;
+            String datasetPath = DatasetRef.canocialDatasetPath(datasetName) ;
+            if ( DatasetRegistry.get().isRegistered(datasetPath) ) {
+                // And abort.
+                ServletOps.error(HttpSC.CONFLICT_409, "Name already registered "+datasetName)
;
+            }
+                
             model.removeAll(null, pStatus, null) ;
             model.add(subject, pStatus, FusekiVocab.stateActive) ;
             
-            String datasetPath = DatasetRef.canocialDatasetPath(datasetName) ;
             // Need to be in Resource space at this point.
             DatasetRef dsRef = FusekiConfig.processService(subject) ;
             X_Config.registerDataset(datasetPath, dsRef) ;

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=1552113&r1=1552112&r2=1552113&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
Wed Dec 18 21:34:21 2013
@@ -117,7 +117,6 @@ public class SPARQLServer {
             serverLog.error("SPARQLServer: Failed to start server: " + ex.getMessage(), ex)
;
             System.exit(1) ;
         }
-        X_Config.addJMX() ;
     }
 
     /**

Modified: jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/ServerTest.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/ServerTest.java?rev=1552113&r1=1552112&r2=1552113&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/ServerTest.java
(original)
+++ jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/ServerTest.java
Wed Dec 18 21:34:21 2013
@@ -20,6 +20,7 @@ package org.apache.jena.fuseki;
 
 import java.util.Collection ;
 
+import org.apache.jena.atlas.iterator.Iter ;
 import org.apache.jena.fuseki.mgt.ManagementServer ;
 import org.apache.jena.fuseki.server.* ;
 import org.eclipse.jetty.servlet.ServletContextHandler ;
@@ -135,7 +136,7 @@ public class ServerTest
             server.stop() ;
         server = null ;
         // Clear out the registry.
-        Collection<String> keys = DatasetRegistry.get().keys() ;
+        Collection<String> keys = Iter.toList(DatasetRegistry.get().keys()) ;
         for ( String k : keys )
             DatasetRegistry.get().remove(k);
     }

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=1552113&r1=1552112&r2=1552113&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 Wed
Dec 18 21:34:21 2013
@@ -22,6 +22,7 @@ import static org.apache.jena.fuseki.Ser
 import static org.apache.jena.fuseki.ServerTest.urlRoot ;
 import static org.apache.jena.fuseki.mgt.MgtConst.opDatasets ;
 import static org.apache.jena.fuseki.mgt.MgtConst.opPing ;
+import static org.apache.jena.fuseki.mgt.MgtConst.opStats ;
 import static org.apache.jena.riot.web.HttpOp.execHttpDelete ;
 import static org.apache.jena.riot.web.HttpOp.execHttpGet ;
 import static org.apache.jena.riot.web.HttpOp.execHttpPost ;
@@ -83,34 +84,21 @@ public class TestAdmin extends BaseTest 
     
     @Test public void list_datasets_2() {
         TypedInputStream in = execHttpGet(urlRoot+"$/"+opDatasets) ;
-        assertEqualsIgnoreCase(WebContent.contentTypeJSON, in.getContentType()) ;
-        JsonValue v = JSON.parse(in) ;
-        assertNotNull(v.getAsObject().get("datasets")) ; 
-        JsonArray a = v.getAsObject().get("datasets").getAsArray() ;
-        
-        JsonObject obj = a.get(0).getAsObject() ;
-        checkOne(obj) ;
-        try { in.close() ; }
-        catch (IOException e) { IO.exception(e); }
+        try {
+            assertEqualsIgnoreCase(WebContent.contentTypeJSON, in.getContentType()) ;
+            JsonValue v = JSON.parse(in) ;
+            assertNotNull(v.getAsObject().get("datasets")) ; 
+            checkJsonDatasetsAll(v);
+        } finally { IO.close(in) ; }
     }
 
-    private void checkOne(JsonObject obj) {
-        assertNotNull(obj.get("ds.name")) ;
-        assertNotNull(obj.get("ds.services")) ;
-        assertTrue(obj.get("ds.services").isArray()) ;
-    }
-    
     // Specific dataset
     @Test public void list_datasets_5() {
-        TypedInputStream in = execHttpGet(urlRoot+"$/"+opDatasets+datasetPath) ;
-        try { in.close() ; }
-        catch (IOException e) { IO.exception(e); }
+        checkExists(datasetPath) ;
     }
     
     // Specific dataset
     @Test public void list_datasets_6() {
-        checkNotThere("does-not-exist") ;
-
         try {
             TypedInputStream in = execHttpGet(ServerTest.urlRoot+"$/"+opDatasets+"/does-not-exist")
;
         } catch (HttpException ex) {
@@ -120,30 +108,78 @@ public class TestAdmin extends BaseTest 
     
     // Specific dataset
     @Test public void list_datasets_7() {
-        TypedInputStream in = execHttpGet(urlRoot+"$/"+opDatasets+datasetPath) ;
-        JsonValue v = JSON.parse(in) ;
-        checkOne(v.getAsObject()) ;
-        try { in.close() ; }
-        catch (IOException e) { IO.exception(e); }
+        JsonValue v = execGetJSON(urlRoot+"$/"+opDatasets+datasetPath) ;
+        checkJsonDatasetsOne(v.getAsObject()) ;
     }
 
     // -- Add
     
     // Specific dataset
     @Test public void add_dataset_1() {
+        String dsTest = "test-ds2" ;
+        checkNotThere(dsTest) ;
+
         File f = new File("testing/config-ds-1.ttl") ;
         org.apache.http.entity.ContentType ct = org.apache.http.entity.ContentType.parse(WebContent.contentTypeTurtle+";
charset="+WebContent.charsetUTF8) ;
         HttpEntity e = new FileEntity(f, ct) ;
         execHttpPost(ServerTest.urlRoot+"$/"+opDatasets, e) ;
         
         // Check exists.
-        execHttpGet(urlRoot+"$/"+opDatasets+"/test-ds2") ;
+        checkExists(dsTest) ;
         
         // Remove it.
-        execHttpDelete(ServerTest.urlRoot+"$/"+opDatasets+"/test-ds2") ;
+        execHttpDelete(ServerTest.urlRoot+"$/"+opDatasets+"/"+dsTest) ;
         checkNotThere("test-ds") ;
     }
 
+    // Try to add twice
+    @Test public void add_dataset_2() {
+        String dsTest = "test-ds2" ;
+        checkNotThere(dsTest) ;
+
+        File f = new File("testing/config-ds-1.ttl") ;
+        { 
+            org.apache.http.entity.ContentType ct = org.apache.http.entity.ContentType.parse(WebContent.contentTypeTurtle+";
charset="+WebContent.charsetUTF8) ;
+            HttpEntity e = new FileEntity(f, ct) ;
+            execHttpPost(ServerTest.urlRoot+"$/"+opDatasets, e) ;
+        }
+        // Check exists.
+        checkExists(dsTest) ;
+        try {
+            org.apache.http.entity.ContentType ct = org.apache.http.entity.ContentType.parse(WebContent.contentTypeTurtle+";
charset="+WebContent.charsetUTF8) ;
+            HttpEntity e = new FileEntity(f, ct) ;
+            execHttpPost(ServerTest.urlRoot+"$/"+opDatasets, e) ;
+        } catch (HttpException ex) {
+            assertEquals(HttpSC.CONFLICT_409, ex.getResponseCode()) ;
+        }
+        // Check exists.
+        checkExists(dsTest) ;
+    }
+    
+    // ---- Active/dormant.
+    
+    // ---- Backup
+
+    // ---- Server
+    
+    // ---- Stats
+    
+    @Test public void stats_1() {
+        JsonValue v = execGetJSON(urlRoot+"$/"+opStats) ;
+        checkJsonStatsAll(v); 
+    }
+    
+    // Auxilary
+    
+    private static void checkExists(String name)  {
+        if ( name.startsWith("/") )
+            name = name.substring(1) ;
+        TypedInputStream in = execHttpGet(urlRoot+"$/"+opDatasets+"/"+name) ; 
+        IO.close(in) ;
+        in = execHttpGet(urlRoot+name+"/sparql?query=ASK%7B%7D") ;
+        IO.close(in) ;
+    }
+    
     private static void checkNotThere(String name) {
         if ( name.startsWith("/") )
             name = name.substring(1) ;
@@ -163,7 +199,50 @@ public class TestAdmin extends BaseTest 
         catch (HttpException ex) {
             assertEquals(HttpSC.NOT_FOUND_404, ex.getResponseCode()) ;
         }
-        
+    }
+
+    private static void checkJsonDatasetsAll(JsonValue v) {
+        assertNotNull(v.getAsObject().get("datasets")) ; 
+        JsonArray a = v.getAsObject().get("datasets").getAsArray() ;
+        for ( JsonValue v2 : a ) {
+            checkJsonDatasetsOne(v2) ;
+        }
+
+    }
+    
+    private static void checkJsonDatasetsOne(JsonValue v) {
+        assertTrue(v.isObject()) ;
+        JsonObject obj = v.getAsObject() ;
+        assertNotNull(obj.get("ds.name")) ;
+        assertNotNull(obj.get("ds.services")) ;
+        assertTrue(obj.get("ds.services").isArray()) ;
+    }
+    
+    private static void checkJsonStatsAll(JsonValue v) {
+        assertNotNull(v.getAsObject().get("datasets")) ; 
+        JsonObject a = v.getAsObject().get("datasets").getAsObject() ;
+        for ( String dsname : a.keys() ) {
+            JsonValue obj = a.get(dsname).getAsObject() ;
+            checkJsonStatsOne(obj);
+        }
+    }
+    
+    private static void checkJsonStatsOne(JsonValue v) {
+        JsonObject obj = v.getAsObject() ;
+        assertTrue(obj.hasKey("Requests")) ;
+        assertTrue(obj.hasKey("RequestsGood")) ;
+        assertTrue(obj.hasKey("RequestsBad")) ;
+        assertTrue(obj.hasKey("services")) ;
+        JsonObject obj2 = obj.get("services").getAsObject() ;
+        // More
+    }
+
+    private static JsonValue execGetJSON(String url) {
+        TypedInputStream in = execHttpGet(url) ;
+        try { 
+            assertEqualsIgnoreCase(WebContent.contentTypeJSON, in.getContentType()) ;
+            return JSON.parse(in) ; 
+        } finally { IO.close(in) ; }
     }
     
     /*



Mime
View raw message