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/11/20 19:33:39 UTC
svn commit: r1204206 - in /incubator/jena/Scratch/AFS/Jena-Dev/trunk:
.classpath dwim src/dev/ReportBuildingQueries.java
src/dev/ReportJena143_TDBConcurrency.java
src/dev/ReportJena163_TDBDifferentIds.java src/dev/Run.java
Author: andy
Date: Sun Nov 20 18:33:39 2011
New Revision: 1204206
URL: http://svn.apache.org/viewvc?rev=1204206&view=rev
Log: (empty)
Added:
incubator/jena/Scratch/AFS/Jena-Dev/trunk/dwim (with props)
incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportBuildingQueries.java
incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena163_TDBDifferentIds.java
Removed:
incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena143_TDBConcurrency.java
Modified:
incubator/jena/Scratch/AFS/Jena-Dev/trunk/.classpath
incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Run.java
Modified: incubator/jena/Scratch/AFS/Jena-Dev/trunk/.classpath
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/.classpath?rev=1204206&r1=1204205&r2=1204206&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/.classpath (original)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/.classpath Sun Nov 20 18:33:39 2011
@@ -1,24 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
- <classpathentry combineaccessrules="false" kind="src" path="/ARQ"/>
- <classpathentry kind="var" path="M2_REPO/commons-codec/commons-codec/1.4/commons-codec-1.4.jar" sourcepath="M2_REPO/commons-codec/commons-codec/1.4/commons-codec-1.4-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar" sourcepath="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/apache/httpcomponents/httpclient/4.1.2/httpclient-4.1.2.jar" sourcepath="M2_REPO/org/apache/httpcomponents/httpclient/4.1.2/httpclient-4.1.2-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/apache/httpcomponents/httpcore/4.1.2/httpcore-4.1.2.jar" sourcepath="M2_REPO/org/apache/httpcomponents/httpcore/4.1.2/httpcore-4.1.2-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/com/ibm/icu/icu4j/3.4.4/icu4j-3.4.4.jar" sourcepath="M2_REPO/com/ibm/icu/icu4j/3.4.4/icu4j-3.4.4-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/com/hp/hpl/jena/iri/0.8/iri-0.8.jar" sourcepath="M2_REPO/com/hp/hpl/jena/iri/0.8/iri-0.8-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/com/hp/hpl/jena/jena/2.6.4/jena-2.6.4-tests.jar" sourcepath="M2_REPO/com/hp/hpl/jena/jena/2.6.4/jena-2.6.4-test-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/com/hp/hpl/jena/jena/2.6.4/jena-2.6.4.jar" sourcepath="M2_REPO/com/hp/hpl/jena/jena/2.6.4/jena-2.6.4-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/junit/junit/4.8.2/junit-4.8.2.jar" sourcepath="M2_REPO/junit/junit/4.8.2/junit-4.8.2-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.16/log4j-1.2.16.jar" sourcepath="M2_REPO/log4j/log4j/1.2.16/log4j-1.2.16-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar" sourcepath="M2_REPO/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar" sourcepath="M2_REPO/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/slf4j/jcl-over-slf4j/1.6.1/jcl-over-slf4j-1.6.1.jar" sourcepath="M2_REPO/org/slf4j/jcl-over-slf4j/1.6.1/jcl-over-slf4j-1.6.1-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/stax/stax-api/1.0.1/stax-api-1.0.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/codehaus/woodstox/wstx-asl/3.2.9/wstx-asl-3.2.9.jar" sourcepath="M2_REPO/org/codehaus/woodstox/wstx-asl/3.2.9/wstx-asl-3.2.9-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.7.1/xercesImpl-2.7.1.jar"/>
- <classpathentry combineaccessrules="false" kind="src" path="/TDB"/>
- <classpathentry kind="output" path="classes"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/ARQ"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/jena/jena-iri/0.9.0-incubating-SNAPSHOT/jena-iri-0.9.0-incubating-SNAPSHOT.jar" sourcepath="M2_REPO/org/apache/jena/jena-iri/0.9.0-incubating-SNAPSHOT/jena-iri-0.9.0-incubating-SNAPSHOT-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/jena/jena-core/2.6.5-incubating-SNAPSHOT/jena-core-2.6.5-incubating-SNAPSHOT-tests.jar" sourcepath="M2_REPO/org/apache/jena/jena-core/2.6.5-incubating-SNAPSHOT/jena-core-2.6.5-incubating-SNAPSHOT-test-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/jena/jena-core/2.6.5-incubating-SNAPSHOT/jena-core-2.6.5-incubating-SNAPSHOT.jar" sourcepath="M2_REPO/org/apache/jena/jena-core/2.6.5-incubating-SNAPSHOT/jena-core-2.6.5-incubating-SNAPSHOT-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-codec/commons-codec/1.4/commons-codec-1.4.jar" sourcepath="M2_REPO/commons-codec/commons-codec/1.4/commons-codec-1.4-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar" sourcepath="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/httpcomponents/httpclient/4.1.2/httpclient-4.1.2.jar" sourcepath="M2_REPO/org/apache/httpcomponents/httpclient/4.1.2/httpclient-4.1.2-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/httpcomponents/httpcore/4.1.2/httpcore-4.1.2.jar" sourcepath="M2_REPO/org/apache/httpcomponents/httpcore/4.1.2/httpcore-4.1.2-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/ibm/icu/icu4j/3.4.4/icu4j-3.4.4.jar" sourcepath="M2_REPO/com/ibm/icu/icu4j/3.4.4/icu4j-3.4.4-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/4.8.2/junit-4.8.2.jar" sourcepath="M2_REPO/junit/junit/4.8.2/junit-4.8.2-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.16/log4j-1.2.16.jar" sourcepath="M2_REPO/log4j/log4j/1.2.16/log4j-1.2.16-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar" sourcepath="M2_REPO/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar" sourcepath="M2_REPO/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/slf4j/jcl-over-slf4j/1.6.1/jcl-over-slf4j-1.6.1.jar" sourcepath="M2_REPO/org/slf4j/jcl-over-slf4j/1.6.1/jcl-over-slf4j-1.6.1-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/stax/stax-api/1.0.1/stax-api-1.0.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/codehaus/woodstox/wstx-asl/3.2.9/wstx-asl-3.2.9.jar" sourcepath="M2_REPO/org/codehaus/woodstox/wstx-asl/3.2.9/wstx-asl-3.2.9-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.7.1/xercesImpl-2.7.1.jar"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/TDB"/>
+ <classpathentry kind="output" path="classes"/>
</classpath>
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/dwim
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/dwim?rev=1204206&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/dwim (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/dwim Sun Nov 20 18:33:39 2011
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+CP="$(../TDB/bin/tdb_path)"
+CP="classes:$CP"
+
+java -cp "$CP" dev.ReportJena143_AbortCorruption
Propchange: incubator/jena/Scratch/AFS/Jena-Dev/trunk/dwim
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportBuildingQueries.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportBuildingQueries.java?rev=1204206&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportBuildingQueries.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportBuildingQueries.java Sun Nov 20 18:33:39 2011
@@ -0,0 +1,48 @@
+/**
+ * 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.openjena.atlas.io.IndentedWriter ;
+
+import com.hp.hpl.jena.query.Query ;
+import com.hp.hpl.jena.query.QueryFactory ;
+import com.hp.hpl.jena.sparql.algebra.Algebra ;
+import com.hp.hpl.jena.sparql.algebra.Op ;
+import com.hp.hpl.jena.sparql.algebra.OpAsQuery ;
+
+public class ReportBuildingQueries
+{
+ public static void main(String... argv)
+ {
+ String queryString = "SELECT (sample(?a) + 1 AS ?c) {} GROUP BY ?x" ;
+ Query query1 = QueryFactory.create(queryString) ;
+ System.out.println("---- Test Original Query --------------------------------------------------") ;
+ query1.serialize(new IndentedWriter(System.out)) ;
+
+ System.out.println("---- Test Original Query Algebra--------------------------------------------") ;
+
+ Op o1 = Algebra.compile(query1) ;
+ o1.output(new IndentedWriter(System.out)) ;
+
+ System.out.println("---- Test OpAsQuery Query --------------------------------------------------") ;
+
+ Query queryRe1 = OpAsQuery.asQuery(o1) ;
+ queryRe1.serialize(new IndentedWriter(System.out)) ;
+ }
+}
Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena163_TDBDifferentIds.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena163_TDBDifferentIds.java?rev=1204206&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena163_TDBDifferentIds.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/ReportJena163_TDBDifferentIds.java Sun Nov 20 18:33:39 2011
@@ -0,0 +1,500 @@
+/*
+ * 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 static com.hp.hpl.jena.tdb.transaction.TransTestLib.count ;
+import static java.lang.String.format ;
+
+import java.util.Iterator ;
+import java.util.concurrent.Callable ;
+import java.util.concurrent.ExecutorService ;
+import java.util.concurrent.Executors ;
+import java.util.concurrent.TimeUnit ;
+import java.util.concurrent.atomic.AtomicInteger ;
+
+import org.junit.AfterClass ;
+import org.junit.BeforeClass ;
+import org.openjena.atlas.lib.FileOps ;
+import org.openjena.atlas.lib.Lib ;
+import org.openjena.atlas.lib.RandomLib ;
+import org.openjena.atlas.lib.StrUtils ;
+import org.slf4j.Logger ;
+import org.slf4j.LoggerFactory ;
+
+import com.hp.hpl.jena.datatypes.xsd.XSDDatatype ;
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.query.* ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.Statement ;
+import com.hp.hpl.jena.sparql.core.DatasetGraph ;
+import com.hp.hpl.jena.sparql.core.Quad ;
+import com.hp.hpl.jena.sparql.sse.SSE ;
+import com.hp.hpl.jena.tdb.ConfigTest ;
+import com.hp.hpl.jena.tdb.DatasetGraphTxn ;
+import com.hp.hpl.jena.tdb.StoreConnection ;
+import com.hp.hpl.jena.tdb.base.block.FileMode ;
+import com.hp.hpl.jena.tdb.base.file.Location ;
+import com.hp.hpl.jena.tdb.sys.SystemTDB ;
+import com.hp.hpl.jena.tdb.transaction.SysTxnState ;
+import com.hp.hpl.jena.tdb.transaction.TransactionManager ;
+
+/** System testing of the transactions. */
+public class ReportJena163_TDBDifferentIds
+{
+ static { org.openjena.atlas.logging.Log.setLog4j() ; }
+ private static Logger log = LoggerFactory.getLogger(ReportJena163_TDBDifferentIds.class) ;
+
+ /* Notes:
+ * MS Windows does not allow memory mapped files to be deleted during the run of a JVM.
+ * This means we can't delete a database and reuse it's directory (see clean()).
+ * Therefore, this test program this does not run on MS Windows 64 bit mode.
+ */
+
+ static {
+ //SystemTDB.isWindows
+ if ( true )
+ SystemTDB.setFileMode(FileMode.direct) ;
+
+ if ( SystemTDB.isWindows && SystemTDB.fileMode() == FileMode.mapped )
+ log.error("**** Running with file mapped mode on MS Windows - expected test failure") ;
+ }
+
+ static boolean MEM = false ;
+
+ static final Location LOC = MEM ? Location.mem() : new Location(ConfigTest.getTestingDirDB()) ;
+
+ static final int Iterations = MEM ? 1000 : 1000 ;
+ // Output style.
+ static boolean inlineProgress = true ; // (! log.isDebugEnabled()) && Iterations > 20 ;
+ static boolean logging = ! inlineProgress ; // (! log.isDebugEnabled()) && Iterations > 20 ;
+
+ static final int numReaderTasks = 5 ;
+ static final int numWriterTasksA = 2 ;
+ static final int numWriterTasksC = 5 ;
+
+ static final int readerSeqRepeats = 8 ;
+ static final int readerMaxPause = 25 ;
+
+ static final int writerAbortSeqRepeats = 4 ;
+ static final int writerCommitSeqRepeats = 4 ;
+ static final int writerMaxPause = 20 ;
+
+ static final int numTreadsInPool = 4 ; // If <= 0 then use an unbounded thread pool.
+ private static ExecutorService execService = null ;
+
+ public static void main(String...args) throws InterruptedException
+ {
+ String x = (MEM?"memory":"disk["+SystemTDB.fileMode()+"]") ;
+
+ if ( logging )
+ log.info("START ({}, {} iterations)", x, Iterations) ;
+ else
+ printf("START (%s, %d iterations)\n", x, Iterations) ;
+
+ int N = (Iterations < 10) ? 1 : Iterations / 10 ;
+ N = Math.min(N, 100) ;
+ int i ;
+
+ for ( i = 0 ; i < Iterations ; i++ )
+ {
+ clean() ;
+
+ execService = ( numTreadsInPool > 0 )
+ ? Executors.newFixedThreadPool(numTreadsInPool)
+ : Executors.newCachedThreadPool() ;
+
+ if (!inlineProgress && logging)
+ log.info(format("Iteration: %d\n", i)) ;
+ if ( inlineProgress )
+ {
+ if ( i%N == 0 )
+ printf("%03d: ",i) ;
+ printf(".") ;
+ if ( i%N == (N-1) )
+ println() ;
+ }
+ new ReportJena163_TDBDifferentIds().manyReaderAndOneWriter() ;
+ execService.shutdown() ;
+ if ( ! execService.awaitTermination(10, TimeUnit.SECONDS) )
+ System.err.println("Shutdown didn;'t complete in time") ;
+
+ }
+ if ( inlineProgress )
+ {
+ if ( i%N != 0 )
+ System.out.println() ;
+ println() ;
+ printf("DONE (%03d)\n",i) ;
+ }
+ if (logging)
+ log.info("FINISH ({})", i) ;
+ else
+ printf("FINISH") ;
+ }
+
+ private static void clean()
+ {
+ if ( ! LOC.isMem() )
+ {
+ StoreConnection.release(LOC) ;
+ FileOps.clearDirectory(LOC.getDirectoryPath()) ;
+ }
+ }
+
+ static class Reader implements Callable<Object>
+ {
+ private final int repeats ;
+ private final int maxpause ;
+ private final StoreConnection sConn ;
+
+ Reader(StoreConnection sConn, int numSeqRepeats, int pause)
+ {
+ this.repeats = numSeqRepeats ;
+ this.maxpause = pause ;
+ this.sConn = sConn ;
+ }
+
+ @Override
+ public Object call()
+ {
+ DatasetGraphTxn dsg = null ;
+ try
+ {
+ int id = gen.incrementAndGet() ;
+ for (int i = 0; i < repeats; i++)
+ {
+ dsg = sConn.begin(ReadWrite.READ) ;
+ log.debug("reader start " + id + "/" + i) ;
+
+ // Original T_TransSystem code
+// int x1 = count("SELECT * { ?s ?p ?o }", dsg) ;
+// pause(maxpause) ;
+// int x2 = count("SELECT * { ?s ?p ?o }", dsg) ;
+// if (x1 != x2) log.warn(format("READER: %s Change seen: %d/%d : id=%d: i=%d",
+// dsg.getTransaction().getLabel(), x1, x2, id, i)) ;
+
+ // Add in an abort.
+ long start = System.currentTimeMillis();
+ int x1 = count("SELECT * { ?s ?p ?o }", dsg) ;
+ pause(maxpause) ;
+
+ String qs1 = StrUtils.strjoinNL("PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>",
+ "SELECT * { {FILTER(afn:wait(10))} UNION {?s ?p ?o }}") ;
+ String qs2 = StrUtils.strjoinNL("DESCRIBE ?s { ?s ?p ?o }") ;
+ try {
+ //countWithAbort(qs1, dsg, 5) ;
+ describeWithAbort(qs2, dsg, -1) ;
+ } catch (QueryCancelledException e)
+ {
+ System.out.print("A");
+ }
+
+ log.debug("reader finish " + id + "/" + i) ;
+ dsg.end() ;
+ dsg = null ;
+ }
+ return null ;
+ } catch (RuntimeException ex)
+ {
+ ex.printStackTrace(System.err) ;
+ if ( dsg != null )
+ {
+ dsg.abort() ;
+ dsg.end() ;
+ dsg = null ;
+ }
+ return null ;
+ }
+ }
+ }
+
+ public static int countWithAbort(String queryStr, DatasetGraph dsg, long abortTime)
+ {
+ int counter = 0 ;
+ Query query = QueryFactory.create(queryStr, Syntax.syntaxARQ) ;
+ QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.create(dsg)) ;
+ try {
+ qExec.setTimeout(abortTime);
+ ResultSet rs = qExec.execSelect() ;
+ for (; rs.hasNext() ; )
+ {
+ rs.nextBinding() ;
+ counter++ ;
+ }
+ return counter ;
+ } finally { qExec.close() ; }
+ }
+
+ public static int describeWithAbort(String queryStr, DatasetGraph dsg, long abortTime)
+ {
+ int counter = 0 ;
+ Query query = QueryFactory.create(queryStr, Syntax.syntaxARQ) ;
+ QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.create(dsg)) ;
+ try {
+ qExec.setTimeout(abortTime);
+ Model model = qExec.execDescribe();
+ //ResultSet rs = qExec.execSelect() ;
+ for(Iterator<Statement> stmIterator = model.listStatements(); stmIterator.hasNext();) {
+ stmIterator.next();
+ counter++;
+ }
+ return counter ;
+ } finally { qExec.close() ; }
+ }
+
+
+ static abstract class Writer implements Callable<Object>
+ {
+ private final int repeats ;
+ private final int maxpause ;
+ private final StoreConnection sConn ;
+ private final boolean commit ;
+
+ protected Writer(StoreConnection sConn, int numSeqRepeats, int pause, boolean commit)
+ {
+ this.repeats = numSeqRepeats ;
+ this.maxpause = pause ;
+ this.sConn = sConn ;
+ this.commit = commit ;
+ }
+
+ @Override
+ public Object call()
+ {
+ DatasetGraphTxn dsg = null ;
+ try {
+ int id = gen.incrementAndGet() ;
+ for ( int i = 0 ; i < repeats ; i++ )
+ {
+ dsg = sConn.begin(ReadWrite.WRITE) ;
+ log.debug("writer start "+id+"/"+i) ;
+
+ int x1 = count("SELECT * { ?s ?p ?o }", dsg) ;
+ int z = change(dsg, id, i) ;
+ pause(maxpause) ;
+ int x2 = count("SELECT * { ?s ?p ?o }", dsg) ;
+ if ( x1+z != x2 )
+ {
+ TransactionManager txnMgr = dsg.getTransaction().getTxnMgr() ;
+ SysTxnState state = txnMgr.state() ;
+ String label = dsg.getTransaction().getLabel() ;
+ log.warn(format("WRITER: %s Change seen: %d + %d != %d : id=%d: i=%d", label, x1, z, x2, id, i)) ;
+ log.warn(state.toString()) ;
+ dsg.abort() ;
+ dsg.end() ;
+ dsg = null ;
+ return null ;
+ }
+ if (commit)
+ dsg.commit() ;
+ else
+ dsg.abort() ;
+ SysTxnState state = sConn.getTransMgrState() ;
+ log.debug(state.toString()) ;
+ log.debug("writer finish "+id+"/"+i) ;
+ dsg.end() ;
+ dsg = null ;
+ }
+ return null ;
+ }
+ catch (RuntimeException ex)
+ {
+ ex.printStackTrace(System.err) ;
+ System.exit(1) ;
+ if ( dsg != null )
+ {
+ dsg.abort() ;
+ dsg.end() ;
+ dsg = null ;
+ }
+ return null ;
+ }
+ }
+
+ // return the delta.
+ protected abstract int change(DatasetGraphTxn dsg, int id, int i) ;
+ }
+
+ @BeforeClass
+ public static void beforeClass()
+ {
+ if ( ! LOC.isMem() )
+ FileOps.clearDirectory(LOC.getDirectoryPath()) ;
+ StoreConnection.reset() ;
+ StoreConnection sConn = StoreConnection.make(LOC) ;
+ DatasetGraphTxn dsg = sConn.begin(ReadWrite.WRITE) ;
+ dsg.add(q1) ;
+ dsg.add(q2) ;
+ initCount = 2 ;
+ dsg.commit() ;
+ dsg.end() ;
+ }
+
+ @AfterClass
+ public static void afterClass() {}
+
+ private StoreConnection sConn ;
+ protected synchronized StoreConnection getStoreConnection()
+ {
+ StoreConnection sConn = StoreConnection.make(LOC) ;
+ //sConn.getTransMgr().recording(true) ;
+ return sConn ;
+ }
+
+ public ReportJena163_TDBDifferentIds() {}
+
+ //@Test
+ public void manyRead()
+ {
+ final StoreConnection sConn = getStoreConnection() ;
+ Callable<?> proc = new Reader(sConn, 50, 200) ; // Number of repeats, max pause
+
+ for ( int i = 0 ; i < 5 ; i++ )
+ execService.submit(proc) ;
+ try
+ {
+ execService.shutdown() ;
+ execService.awaitTermination(100, TimeUnit.SECONDS) ;
+ } catch (InterruptedException e)
+ {
+ e.printStackTrace(System.err) ;
+ }
+ }
+
+ //@Test
+ public void manyReaderAndOneWriter()
+ {
+ final StoreConnection sConn = getStoreConnection() ;
+
+ Callable<?> procR = new Reader(sConn, readerSeqRepeats, readerMaxPause) ; // Number of repeats, max pause
+ Callable<?> procW_a = new Writer(sConn, writerAbortSeqRepeats, writerMaxPause, false) // Number of repeats, max pause, commit.
+ {
+ @Override
+ protected int change(DatasetGraphTxn dsg, int id, int i)
+ {
+ return changeProc(dsg, id, i) ;
+ }
+ } ;
+
+ Callable<?> procW_c = new Writer(sConn, writerCommitSeqRepeats, writerMaxPause, true) // Number of repeats, max pause, commit.
+ {
+ @Override
+ protected int change(DatasetGraphTxn dsg, int id, int i)
+ {
+ return changeProc(dsg, id, i) ;
+ }
+ } ;
+
+ submit(execService, procR, numReaderTasks, "READ-") ;
+ submit(execService, procW_c, numWriterTasksC, "COMMIT-") ;
+ submit(execService, procW_a, numWriterTasksA, "ABORT-") ;
+
+ try
+ {
+ execService.shutdown() ;
+ execService.awaitTermination(100, TimeUnit.SECONDS) ;
+ } catch (InterruptedException e)
+ {
+ e.printStackTrace(System.err) ;
+ }
+ }
+
+ static class Callable2Runnable<T> implements Runnable
+ {
+ private Callable<T> callable ;
+
+ Callable2Runnable(Callable<T> callable) { this.callable = callable ; }
+
+ @Override public void run() { try { callable.call() ; } catch (Exception ex) {} }
+ }
+
+ private static int counter = 0 ;
+ private <T> void submit(ExecutorService execService, Callable<T> proc, int numTasks, String label)
+ {
+ for ( int i = 0 ; i < numTasks ; i++ )
+ {
+ execService.submit(proc) ;
+// counter++ ;
+// Thread t = new Thread(new Callable2Runnable<T>(proc), label+counter) ;
+// t.start();
+ }
+ }
+
+ static int changeProc(DatasetGraphTxn dsg, int id, int i)
+ {
+ int count = 0 ;
+ int maxN = 500 ;
+ int N = RandomLib.qrandom.nextInt(maxN) ;
+ for ( int j = 0 ; j < N; j++ )
+ {
+ Quad q = genQuad(id*maxN+j) ;
+ if ( ! dsg.contains(q) )
+ {
+ dsg.add(q) ;
+ count++ ;
+ }
+ }
+ log.debug("Change = "+dsg.getDefaultGraph().size()) ;
+ return count ;
+ }
+
+ static void pause(int maxInternal)
+ {
+ int x = (int)Math.round(Math.random()*maxInternal) ;
+ Lib.sleep(x) ;
+ }
+
+ static Quad genQuad(int value)
+ {
+ Quad q1 = SSE.parseQuad("(_ <s> <p> <o>)") ;
+ Node g1 = q.getGraph() ;
+
+ Node g = Quad.defaultGraphNodeGenerated ; // urn:x-arq:DefaultGraphNode
+ Node s = Node.createURI("S") ;
+ Node p = Node.createURI("P") ;
+ Node o = Node.createLiteral(Integer.toString(value), null, XSDDatatype.XSDinteger) ;
+ return new Quad(g,s,p,o) ;
+ }
+
+ private static void println()
+ {
+ printf("\n") ; System.out.flush() ;
+ }
+
+ private static void printf(String string, Object...args)
+ {
+ System.out.printf(string, args) ;
+ }
+
+ static Quad q = SSE.parseQuad("(_ <s> <p> <o>) ") ;
+
+ static Quad q1 = SSE.parseQuad("(_ <s> <p> <o1>)") ;
+
+ static Quad q2 = SSE.parseQuad("(_ <s> <p> <o2>)") ;
+
+ static Quad q3 = SSE.parseQuad("(_ <s> <p> <o3>)") ;
+
+ static Quad q4 = SSE.parseQuad("(_ <s> <p> <o4>)") ;
+
+ private static int initCount = -1 ;
+
+ //static final Location LOC = new Location(ConfigTest.getTestingDirDB()) ;
+ static final AtomicInteger gen = new AtomicInteger() ;
+
+}
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=1204206&r1=1204205&r2=1204206&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 Sun Nov 20 18:33:39 2011
@@ -37,8 +37,8 @@ import com.hp.hpl.jena.query.QueryFactor
import com.hp.hpl.jena.query.QuerySolution ;
import com.hp.hpl.jena.query.ReadWrite ;
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.function.library.wait ;
import com.hp.hpl.jena.sparql.lang.SyntaxVarScope ;
import com.hp.hpl.jena.sparql.sse.SSE ;
import com.hp.hpl.jena.tdb.DatasetGraphTransaction ;