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 2011/10/21 17:55:26 UTC

svn commit: r1187419 - in /incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev: ReportJena102.java ReportJena142.java ReportJena143.java Run.java

Author: andy
Date: Fri Oct 21 15:55:26 2011
New Revision: 1187419

URL: http://svn.apache.org/viewvc?rev=1187419&view=rev
Log: (empty)

Added:
    incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena102.java   (with props)
    incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena142.java   (with props)
    incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena143.java   (with props)
Modified:
    incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Run.java

Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena102.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena102.java?rev=1187419&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena102.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena102.java Fri Oct 21 15:55:26 2011
@@ -0,0 +1,46 @@
+/**
+ * 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.
+ */
+
+package dev;
+
+import java.io.FileInputStream ;
+import java.io.InputStream ;
+
+import org.openjena.atlas.lib.FileOps ;
+
+import com.hp.hpl.jena.tdb.TDBFactory ;
+import com.hp.hpl.jena.tdb.TDBLoader ;
+import com.hp.hpl.jena.tdb.store.DatasetGraphTDB ;
+
+public class ReportJena102
+{
+    public static void main(String[] argv) throws Exception
+    {
+        // JENA-102 : tdbstats handling.
+        String DIR = "tmp/DB" ;
+        FileOps.ensureDir("tmp") ;
+        FileOps.ensureDir(DIR) ;
+//        FileOps.clearDirectory(DIR) ;
+        DatasetGraphTDB dsg = TDBFactory.createDatasetGraph(DIR) ;
+        InputStream in = new FileInputStream("D.nt") ;
+        // Check code path when there is existing data.
+        TDBLoader.load(dsg, in, false) ;
+        System.exit(0) ;
+    }
+}
+

Propchange: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena102.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena142.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena142.java?rev=1187419&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena142.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena142.java Fri Oct 21 15:55:26 2011
@@ -0,0 +1,67 @@
+/**
+ * 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.
+ */
+
+package dev;
+
+import org.junit.Test ;
+import org.openjena.atlas.logging.Log ;
+
+import com.hp.hpl.jena.query.Query ;
+import com.hp.hpl.jena.query.QueryException ;
+import com.hp.hpl.jena.query.QueryFactory ;
+import com.hp.hpl.jena.sparql.lang.SyntaxVarScope ;
+
+public class ReportJena142
+{
+   static { Log.setLog4j() ; }
+    
+    public static void main(String[] argv) throws Exception
+    {
+        //JENA-142
+        String x = "SELECT * WHERE { { ?s ?p ?o} UNION { BIND('default' AS ?s) } }" ;
+        //String x = "SELECT * WHERE { { ?s ?p ?o}  { BIND('default' AS ?s) } }" ;
+        arq.qparse.main(x) ;
+        System.out.println("DONE") ;
+        System.exit(0) ;
+    }
+
+    @Test public void scope_22() { scope("SELECT * { ?s ?p ?o OPTIONAL{?s ?p2 ?o2} BIND(?o2+5 AS ?z) }") ; }
+
+    @Test(expected=QueryException.class)
+    public void scope_23() { scope("SELECT * { ?s ?p ?o OPTIONAL{?s ?p2 ?o2} BIND(5 AS ?o2) }") ; }
+
+    @Test(expected=QueryException.class)
+    public void scope_24() { scope("SELECT * { ?s ?p ?o OPTIONAL{?s ?p2 ?o2} BIND(?o+5 AS ?o2) }") ; }
+
+    @Test(expected=QueryException.class)
+    public void scope_25() { scope("SELECT * { ?s ?p ?o OPTIONAL{?s ?p2 ?o2} BIND(5 AS ?o) }") ; }
+
+    // new tests
+    @Test public void scope_26() { scope("SELECT * WHERE { { ?s ?p ?o} UNION { BIND('default' AS ?s) } }") ; }
+
+    @Test public void scope_27() { scope("SELECT * WHERE { { ?s ?p ?o} BIND('default' AS ?s) }") ; }
+
+    @Test public void scope_28() { scope("SELECT * WHERE { ?s ?p ?o { BIND('default' AS ?s) } }") ; }
+    
+    private static void scope(String queryStr)
+    {
+        Query query = QueryFactory.create(queryStr) ;
+        SyntaxVarScope.check(query) ;
+    }
+}
+

Propchange: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena142.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena143.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena143.java?rev=1187419&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena143.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena143.java Fri Oct 21 15:55:26 2011
@@ -0,0 +1,132 @@
+/**
+ * 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.
+ */
+
+package dev;
+
+import java.io.FileInputStream ;
+import java.io.InputStream ;
+
+import org.openjena.atlas.lib.FileOps ;
+import org.openjena.atlas.lib.Lib ;
+import org.openjena.atlas.logging.Log ;
+
+import com.hp.hpl.jena.query.Dataset ;
+import com.hp.hpl.jena.query.QueryCancelledException ;
+import com.hp.hpl.jena.query.QueryExecution ;
+import com.hp.hpl.jena.query.QueryExecutionFactory ;
+import com.hp.hpl.jena.query.QuerySolution ;
+import com.hp.hpl.jena.query.ResultSet ;
+import com.hp.hpl.jena.sparql.api.wait ;
+import com.hp.hpl.jena.sparql.function.FunctionRegistry ;
+import com.hp.hpl.jena.tdb.DatasetGraphTxn ;
+import com.hp.hpl.jena.tdb.ReadWrite ;
+import com.hp.hpl.jena.tdb.StoreConnection ;
+import com.hp.hpl.jena.tdb.TDBFactory ;
+import com.hp.hpl.jena.tdb.TDBLoader ;
+import com.hp.hpl.jena.tdb.store.DatasetGraphTDB ;
+
+public class ReportJena143
+{
+static { Log.setLog4j() ; }
+    
+    public static void main(String[] argv) throws Exception
+    {
+        // JENA-143 :TDB Concurrency
+        String ns  = "http://example/ns#" ;
+        FunctionRegistry.get().put(ns + "wait", wait.class) ;
+        String DIR = "tmp/DB" ;
+        FileOps.ensureDir("tmp") ;
+        FileOps.ensureDir(DIR) ;
+        
+        String qs = "PREFIX f: <"+ns+"> SELECT * { ?s ?p ?o }" ;
+        
+        DatasetGraphTxn dsGraph = StoreConnection.make(DIR).begin(ReadWrite.READ);
+        Dataset ds = dsGraph.toDataset();
+        
+        QueryExecution qe = QueryExecutionFactory.create(qs, ds) ;
+        
+        Thread t1 = new Thread(new Killer(qe)) ;
+        Thread t2 = new Thread(new QRunner(dsGraph, qe)) ;
+        
+        t2.start() ;
+        t1.start() ;
+        
+        t1.join() ;
+        t2.join() ;
+    }
+    
+    static class Killer implements Runnable
+    {
+        private QueryExecution qe ;
+        public Killer(QueryExecution qe) { this.qe = qe ; }
+        @Override
+        public void run()
+        {
+            Lib.sleep(200) ;
+            qe.abort() ;
+            Lib.sleep(10) ;
+            qe.abort() ;
+            Lib.sleep(10) ;
+        }
+    }
+    
+    static class QRunner implements Runnable
+    {
+        private QueryExecution qe ;
+        private DatasetGraphTxn dsg ;
+        public QRunner(DatasetGraphTxn dsGraph, QueryExecution qe) { this.dsg = dsGraph ; this.qe = qe ; }
+        @Override
+        public void run()
+        {
+            ResultSet results = qe.execSelect();
+            int count = 0 ;
+            try {
+                while(results.hasNext())
+                {
+                    count++ ;
+                    QuerySolution soln = results.next() ;
+                    // Force nodes
+                    soln.toString() ;
+                    if ( count %100 == 0 ) System.out.println(soln) ;
+                }
+                qe.close();
+            } catch (QueryCancelledException e) {
+                System.out.println("QueryCancelledException") ;
+                dsg.abort();
+            } finally {
+                dsg.close();
+            } 
+            // There 344195 triples.
+            System.out.println("count = "+count) ;
+        }
+    }
+
+    private static void jena102() throws Exception
+    {
+        String DIR = "tmp/DB" ;
+        FileOps.ensureDir("tmp") ;
+        FileOps.ensureDir(DIR) ;
+//        FileOps.clearDirectory(DIR) ;
+        DatasetGraphTDB dsg = TDBFactory.createDatasetGraph(DIR) ;
+        InputStream in = new FileInputStream("D.nt") ;
+        // Check code path when there is existing data.
+        TDBLoader.load(dsg, in, false) ;
+        System.exit(0) ;
+    }
+}
+

Propchange: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena143.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Run.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Run.java?rev=1187419&r1=1187418&r2=1187419&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Run.java (original)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Run.java Fri Oct 21 15:55:26 2011
@@ -23,17 +23,26 @@ import java.io.InputStream ;
 
 import org.junit.Test ;
 import org.openjena.atlas.lib.FileOps ;
+import org.openjena.atlas.lib.Lib ;
 import org.openjena.atlas.logging.Log ;
 
+import com.hp.hpl.jena.query.Dataset ;
 import com.hp.hpl.jena.query.Query ;
+import com.hp.hpl.jena.query.QueryCancelledException ;
 import com.hp.hpl.jena.query.QueryException ;
+import com.hp.hpl.jena.query.QueryExecution ;
+import com.hp.hpl.jena.query.QueryExecutionFactory ;
 import com.hp.hpl.jena.query.QueryFactory ;
+import com.hp.hpl.jena.query.QuerySolution ;
+import com.hp.hpl.jena.query.ResultSet ;
+import com.hp.hpl.jena.sparql.api.wait ;
+import com.hp.hpl.jena.sparql.function.FunctionRegistry ;
 import com.hp.hpl.jena.sparql.lang.SyntaxVarScope ;
-import com.hp.hpl.jena.tdb.TDB ;
+import com.hp.hpl.jena.tdb.DatasetGraphTxn ;
+import com.hp.hpl.jena.tdb.ReadWrite ;
+import com.hp.hpl.jena.tdb.StoreConnection ;
 import com.hp.hpl.jena.tdb.TDBFactory ;
 import com.hp.hpl.jena.tdb.TDBLoader ;
-import com.hp.hpl.jena.tdb.base.file.FileFactory ;
-import com.hp.hpl.jena.tdb.base.objectfile.StringFile ;
 import com.hp.hpl.jena.tdb.store.DatasetGraphTDB ;
 
 public class Run
@@ -42,38 +51,113 @@ public class Run
     
     public static void main(String[] argv) throws Exception
     {
-        // JENA-102
-        {
-            String DIR = "tmp/DB" ;
-            FileOps.ensureDir("tmp") ;
-            FileOps.ensureDir(DIR) ;
-//            FileOps.clearDirectory(DIR) ;
-            DatasetGraphTDB dsg = TDBFactory.createDatasetGraph(DIR) ;
-            InputStream in = new FileInputStream("D.nt") ;
-            // Check code path when there is existing data.
-            TDBLoader.load(dsg, in, false) ;
-            System.exit(0) ;
-        }
+        // JENA-102 : tdbstats handling.
+        if ( false ) jena102() ;
+       
+        // JENA-142 : Var scoping and 
+        if ( false ) jena142() ;
+
+        // JENA-143
+        jena143() ;
+    }
+    
+    private static void jena143() throws Exception
+    {
+        String ns  = "http://example/ns#" ;
+        FunctionRegistry.get().put(ns + "wait", wait.class) ;
+        String DIR = "tmp/DB" ;
+        FileOps.ensureDir("tmp") ;
+        FileOps.ensureDir(DIR) ;
+
+        
+        String qs = "PREFIX f: <"+ns+"> SELECT * { ?s ?p ?o }" ;
         
+        DatasetGraphTxn dsGraph = StoreConnection.make(DIR).begin(ReadWrite.READ);
+        Dataset ds = dsGraph.toDataset();
         
+        QueryExecution qe = QueryExecutionFactory.create(qs, ds) ;
+        
+        Thread t1 = new Thread(new Killer(qe)) ;
+        Thread t2 = new Thread(new QRunner(dsGraph, qe)) ;
+        
+        t2.start() ;
+        t1.start() ;
+        
+        t1.join() ;
+        t2.join() ;
+        
+        
+    }
+    
+    static class Killer implements Runnable
+    {
+        private QueryExecution qe ;
+        public Killer(QueryExecution qe) { this.qe = qe ; }
+        @Override
+        public void run()
         {
-            //JENA-142
+            Lib.sleep(200) ;
+            qe.abort() ;
+            Lib.sleep(10) ;
+            qe.abort() ;
+            Lib.sleep(10) ;
+        }
+    }
+    
+    static class QRunner implements Runnable
+    {
+        private QueryExecution qe ;
+        private DatasetGraphTxn dsg ;
+        public QRunner(DatasetGraphTxn dsGraph, QueryExecution qe) { this.dsg = dsGraph ; this.qe = qe ; }
+        @Override
+        public void run()
+        {
+            ResultSet results = qe.execSelect();
+            int count = 0 ;
+            try {
+                while(results.hasNext())
+                {
+                    count++ ;
+                    QuerySolution soln = results.next() ;
+                    // Force nodes
+                    soln.toString() ;
+                    if ( count %100 == 0 ) System.out.println(soln) ;
+                }
+                qe.close();
+            } catch (QueryCancelledException e) {
+                System.out.println("QueryCancelledException") ;
+                dsg.abort();
+            } finally {
+                dsg.close();
+            } 
+            // There 344195 triples.
+            System.out.println("count = "+count) ;
+        }
+    }
+
+    private static void jena142()
+    {
+        //JENA-142
         String x = "SELECT * WHERE { { ?s ?p ?o} UNION { BIND('default' AS ?s) } }" ;
         //String x = "SELECT * WHERE { { ?s ?p ?o}  { BIND('default' AS ?s) } }" ;
         arq.qparse.main(x) ;
         System.out.println("DONE") ;
         System.exit(0) ;
-        }
-        String DIR = "tmp/DBZ" ;
-        TDB.init() ;
+    }
+
+    private static void jena102() throws Exception
+    {
+        String DIR = "tmp/DB" ;
+        FileOps.ensureDir("tmp") ;
         FileOps.ensureDir(DIR) ;
-        FileOps.clearDirectory(DIR) ;
-        tdb.tdbloader.main("--loc="+DIR, "tmp/D.nq") ;
-        
-        StringFile x = FileFactory.createStringFileDisk(DIR+"/nodes.dat") ;
-        x.dump() ;
+//        FileOps.clearDirectory(DIR) ;
+        DatasetGraphTDB dsg = TDBFactory.createDatasetGraph(DIR) ;
+        InputStream in = new FileInputStream("D.nt") ;
+        // Check code path when there is existing data.
+        TDBLoader.load(dsg, in, false) ;
+        System.exit(0) ;
     }
-    
+
     @Test public void scope_22() { scope("SELECT * { ?s ?p ?o OPTIONAL{?s ?p2 ?o2} BIND(?o2+5 AS ?z) }") ; }
 
     @Test(expected=QueryException.class)