You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2016/10/14 19:22:11 UTC

[12/15] jena git commit: Using ServerTest straight from http_op_3

Using ServerTest straight from http_op_3


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/3a3628fa
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/3a3628fa
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/3a3628fa

Branch: refs/heads/master
Commit: 3a3628faf90ea610067c6f289154c1588073cbb1
Parents: a50e7e7
Author: ajs6f <aj...@virginia.edu>
Authored: Fri Oct 14 07:18:57 2016 -0400
Committer: ajs6f <aj...@virginia.edu>
Committed: Fri Oct 14 07:18:57 2016 -0400

----------------------------------------------------------------------
 .../java/org/apache/jena/fuseki/ServerTest.java | 50 +++++++++++++-------
 1 file changed, 32 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/3a3628fa/jena-fuseki1/src/test/java/org/apache/jena/fuseki/ServerTest.java
----------------------------------------------------------------------
diff --git a/jena-fuseki1/src/test/java/org/apache/jena/fuseki/ServerTest.java b/jena-fuseki1/src/test/java/org/apache/jena/fuseki/ServerTest.java
index bbde594..f6783a7 100644
--- a/jena-fuseki1/src/test/java/org/apache/jena/fuseki/ServerTest.java
+++ b/jena-fuseki1/src/test/java/org/apache/jena/fuseki/ServerTest.java
@@ -33,6 +33,7 @@ import org.apache.jena.sparql.core.DatasetGraphFactory ;
 import org.apache.jena.sparql.modify.request.Target ;
 import org.apache.jena.sparql.modify.request.UpdateDrop ;
 import org.apache.jena.sparql.sse.SSE ;
+import org.apache.jena.system.Txn ;
 import org.apache.jena.update.Update ;
 import org.apache.jena.update.UpdateExecutionFactory ;
 import org.apache.jena.update.UpdateProcessor ;
@@ -42,14 +43,20 @@ import org.apache.jena.update.UpdateProcessor ;
  * <pre>
     \@BeforeClass public static void beforeClass() { ServerTest.allocServer() ; }
     \@AfterClass  public static void afterClass()  { ServerTest.freeServer() ; }
-    \@Before      public void beforeTest()         { ServerTest.resetServer() ; }
+    \@After       public void after()              { ServerTest.resetServer() ; }
     </pre>
  */
 public class ServerTest
 {
+    // Note:
+    // @Before  public void before()              { ServerTest.resetServer() ; }
+    // If using SPARQL Update to reset the server. 
+    // It can hit the server before it has started properly. 
+    
+    static { Fuseki.init(); }
+    
     // Abstraction that runs a SPARQL server for tests.
     public static final int port             = choosePort() ;   // Different to the Fuseki2 test ports.
-
     public static final String urlRoot       = "http://localhost:"+port+"/" ;
     public static final String datasetPath   = "/dataset" ;
     public static final String serviceUpdate = "http://localhost:"+port+datasetPath+"/update" ; 
@@ -76,22 +83,24 @@ public class ServerTest
     // reference count of start/stop server
     private static AtomicInteger countServer = new AtomicInteger() ; 
     
-    // This will cause there to be one server over all tests.
-    // Must be after initialization of counters 
-    static { allocServer(); }
-
     static public void allocServer() {
-        if (countServer.getAndIncrement() == 0) setupServer();
+        if ( countServer.getAndIncrement() == 0 )
+            setupServer() ;
     }
     
     static public void freeServer() {
-        if (countServer.decrementAndGet() == 0) teardownServer();
+        if ( countServer.decrementAndGet() == 0 )
+            teardownServer() ;
     }
     
+    // Whether to use a transaction on the dataset or to use SPARQL Update. 
+    static boolean CLEAR_DSG_DIRECTLY = true ;
+    static private DatasetGraph dsgTesting ;
+    
     @SuppressWarnings("deprecation")
     protected static void setupServer() {
-        DatasetGraph dsg = DatasetGraphFactory.create() ;
-        server = EmbeddedFusekiServer1.create(port, dsg, datasetPath) ;
+        dsgTesting = DatasetGraphFactory.createTxnMem() ;
+        server = EmbeddedFusekiServer1.create(port, dsgTesting, datasetPath) ;
         server.start() ;
     }
     
@@ -102,13 +111,18 @@ public class ServerTest
             server.stop() ;
         server = null ;
     }
-    public static void resetServer()
-    {
-        if (countServer.get() == 0)  throw new RuntimeException("No server started!");
-        Update clearRequest = new UpdateDrop(Target.ALL) ;
-        UpdateProcessor proc = UpdateExecutionFactory.createRemote(clearRequest, ServerTest.serviceUpdate) ;
-        try {proc.execute() ; }
-        catch (Throwable e) {e.printStackTrace(); throw e;}
+
+    public static void resetServer() {
+        if (countServer.get() == 0)  
+            throw new RuntimeException("No server started!");
+        if ( CLEAR_DSG_DIRECTLY ) {
+            Txn.executeWrite(dsgTesting, ()->dsgTesting.clear()) ;   
+        } else {
+            Update clearRequest = new UpdateDrop(Target.ALL) ;
+            UpdateProcessor proc = UpdateExecutionFactory.createRemote(clearRequest, ServerTest.serviceUpdate) ;
+            try {proc.execute() ; }
+            catch (Throwable e) {e.printStackTrace(); throw e;}
+        }
     }
     
     static int choosePort() {
@@ -118,4 +132,4 @@ public class ServerTest
             throw new FusekiException("Failed to find a port for tests!");
         }
     }
-}
+}
\ No newline at end of file