http://git-wip-us.apache.org/repos/asf/jena/blob/edab900a/jena-tdb/src/test/java/org/apache/jena/tdb/extra/T_TransSystem.java ---------------------------------------------------------------------- diff --git a/jena-tdb/src/test/java/org/apache/jena/tdb/extra/T_TransSystem.java b/jena-tdb/src/test/java/org/apache/jena/tdb/extra/T_TransSystem.java deleted file mode 100644 index 3c3bb2e..0000000 --- a/jena-tdb/src/test/java/org/apache/jena/tdb/extra/T_TransSystem.java +++ /dev/null @@ -1,674 +0,0 @@ -/* - * 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 org.apache.jena.tdb.extra ; - -import static java.lang.Math.max ; -import static java.lang.Math.min ; -import static java.lang.String.format ; -import static org.apache.jena.tdb.transaction.TransTestLib.count ; - -import java.util.Iterator ; -import java.util.concurrent.* ; -import java.util.concurrent.atomic.AtomicInteger ; - -import org.apache.jena.atlas.lib.FileOps ; -import org.apache.jena.atlas.lib.Lib ; -import org.apache.jena.atlas.lib.RandomLib ; -import org.apache.jena.atlas.lib.StrUtils ; -import org.apache.jena.datatypes.xsd.XSDDatatype ; -import org.apache.jena.graph.Node ; -import org.apache.jena.graph.NodeFactory ; -import org.apache.jena.query.* ; -import org.apache.jena.rdf.model.Model ; -import org.apache.jena.rdf.model.Statement ; -import org.apache.jena.sparql.core.DatasetGraph ; -import org.apache.jena.sparql.core.Quad ; -import org.apache.jena.sparql.sse.SSE ; -import org.apache.jena.tdb.ConfigTest ; -import org.apache.jena.tdb.StoreConnection ; -import org.apache.jena.tdb.TDBException ; -import org.apache.jena.tdb.base.block.FileMode ; -import org.apache.jena.tdb.base.file.Location ; -import org.apache.jena.tdb.sys.SystemTDB ; -import org.apache.jena.tdb.transaction.DatasetGraphTxn ; -import org.apache.jena.tdb.transaction.SysTxnState ; -import org.apache.jena.tdb.transaction.TransactionManager ; -import org.junit.AfterClass ; -import org.junit.BeforeClass ; -import org.slf4j.Logger ; -import org.slf4j.LoggerFactory ; - -/** System testing of the transactions. */ -public class T_TransSystem -{ - static { org.apache.jena.atlas.logging.LogCtl.setLog4j() ; } - private static Logger log = LoggerFactory.getLogger(T_TransSystem.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 boolean MEM = true ; - static String location = true ? "/mnt/ssd1/tmp/DB163" : ConfigTest.getTestingDirDB() ; // Using an SSD here is very helpful - //static String location = ConfigTest.getTestingDirDB() ; // Using an SSD here is very helpful - static final Location LOC = MEM ? Location.mem() : Location.create(location) ; - - static { - //SystemTDB.isWindows - if ( false ) - SystemTDB.setFileMode(FileMode.direct) ; - - if ( SystemTDB.isWindows && SystemTDB.fileMode() == FileMode.mapped ) - log.error("**** Running with file mapped mode on MS Windows - expected test failure") ; - - FileOps.ensureDir(location) ; - } - - private static boolean inlineProgress = false ; // Set true so that every transaction print a letter for what it does. - private static boolean silent = false ; // No progress output - - static { - //TransactionManager.DEBUG = inlineProgress ; // This cause one character details to be printed. - if ( TransactionManager.DEBUG != inlineProgress ) - log.warn("TransactionManager.DEBUG != inlineProgress (need change source code to make DEBUG not final)" ) ; - - - // Various flags (may not still exist) - //ObjectFileStorage.logging = true ; - // FileBase.DEBUG = inlineProgress ; - //NodeTableTrans.FIXUP = true ; - //NodeTableTrans.APPEND_LOG = true ; - // See also log4j.properties. - } - - static final int Iterations = MEM ? 10000 : 10000 ; - // Output style. - static boolean logging = false ; - - // XXX Switch to threads choosing a mix of actions. - // Jena-163 - good number choice? - // 1/0/2 8/10 3/3/10 4 - - static final int numReaderTasks = 5 ; // 5 - static final int numWriterTasksA = 3 ; // 3 - static final int numWriterTasksC = 5 ; // 5 - - static final int readerSeqRepeats = 4 ; // 8 - static final int readerMaxPause = 20 ; // 20 - - static final int writerAbortSeqRepeats = 4 ; // 4 - static final int writerCommitSeqRepeats = 4 ; // 4 - static final int writerMaxPause = 20 ; // 20 - - static final int numThreadsInPool = 4 ; // If <= 0 then use an unbounded thread pool. - private static ExecutorService execService = null ; - - private static int iteration = 0 ; - private static int numIterationsPerBlock = 100 ; - private static int colCount = 0 ; - private static int colMax = 200 ; - - // Queue treads starting - private static Semaphore startPoint ; - // Queue threads finishing. - private static CountDownLatch doneSignal ; - - /** TODO - * Ideally: better mixes of R, C and A. - * One thread, processes a list of RCA choices. - * Different mixes to different threads. - * - * Random data - */ - - public static void main(String...args) throws InterruptedException - { - String x = (MEM?"memory":"disk["+SystemTDB.fileMode()+"]") ; - - // Make colMax >= numIterationsPerBlock in detailEveryTransaction = false mode - if ( !inlineProgress ) - colMax = numIterationsPerBlock ; - - if ( logging ) - log.info("START ({}, {} iterations)", x, Iterations) ; - else - printf("START (%s, %d iterations)\n", x, Iterations) ; - - for ( iteration = 0 ; iteration < Iterations ; iteration++ ) - { - clean() ; - - execService = ( numThreadsInPool > 0 ) - ? Executors.newFixedThreadPool(numThreadsInPool) - : Executors.newCachedThreadPool() ; - - startTestIteration() ; - - try { - new T_TransSystem().manyReaderAndOneWriter() ; - } catch (TDBException ex) - { - System.err.println() ; - ex.printStackTrace(System.err) ; - System.err.println() ; - } - - // Should already be shutdown. - execService.shutdown() ; - if ( ! execService.awaitTermination(30, TimeUnit.SECONDS) ) - System.err.println("Shutdown didn't complete in time") ; - endTestIteration() ; - } - - endTest() ; - if (logging) - log.info("FINISH ({})", iteration) ; - else - println("FINISH") ; - } - - 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() - { - start() ; - 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.apache.org/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) - { - txn("X", dsg); - } - - log.debug("reader finish " + id + "/" + i) ; - dsg.end() ; - txn("R", dsg) ; - dsg = null ; - } - return null ; - } catch (RuntimeException ex) - { - System.out.flush() ; - System.err.println() ; - ex.printStackTrace(System.err) ; - if ( dsg != null ) - { - dsg.abort() ; - dsg.end() ; - txn("E", dsg) ; - dsg = null ; - } - System.exit(2) ; - return null ; - } - finally { doneSignal.countDown(); } - } - } - - public static int countWithAbort(String queryStr, DatasetGraph dsg, long abortTime) - { - int counter = 0 ; - Query query = QueryFactory.create(queryStr, Syntax.syntaxARQ) ; - try(QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.wrap(dsg))) { - qExec.setTimeout(abortTime); - ResultSet rs = qExec.execSelect() ; - for (; rs.hasNext() ; ) - { - rs.nextBinding() ; - counter++ ; - } - return counter ; - } - } - - public static int describeWithAbort(String queryStr, DatasetGraph dsg, long abortTime) - { - int counter = 0 ; - Query query = QueryFactory.create(queryStr, Syntax.syntaxARQ) ; - try(QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.wrap(dsg))) { - qExec.setTimeout(abortTime); - Model model = qExec.execDescribe(); - //ResultSet rs = qExec.execSelect() ; - for(Iterator<Statement> stmIterator = model.listStatements(); stmIterator.hasNext();) { - stmIterator.next(); - counter++; - } - return counter ; - } - } - - - static 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() - { - start() ; - - 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() ; - txn("C", dsg) ; - } - else - { - dsg.abort() ; - txn("A", dsg) ; - } - SysTxnState state = sConn.getTransMgrState() ; - log.debug(state.toString()) ; - log.debug("writer finish "+id+"/"+i) ; - Lib.sleep(20) ; - dsg.end() ; - dsg = null ; - } - return null ; - } - catch (RuntimeException ex) - { - txn("E", dsg) ; - System.err.println() ; - ex.printStackTrace(System.err) ; - System.exit(1) ; - if ( dsg != null ) - { - dsg.abort() ; - dsg.end() ; - dsg = null ; - } - - return null ; - } - finally { doneSignal.countDown(); } - } - - // return the delta. - protected int change(DatasetGraphTxn dsg, int id, int i) - { - return changeProc(dsg, id, i) ; - } - } - - public static void start() - { - if ( startPoint != null ) - { - try { startPoint.acquire() ; } - catch (InterruptedException e) { e.printStackTrace(); } - } - pause(10) ; - } - - @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 static void clean() - { - StoreConnection.release(LOC) ; - if ( ! LOC.isMem() ) - { - FileOps.clearDirectory(LOC.getDirectoryPath()) ; - // Clean because it's new. - //LOC = Location.create(ConfigTest.getTestingDirUnique()) ; - } - } - - private StoreConnection sConn ; - protected synchronized StoreConnection getStoreConnection() - { - - - StoreConnection sConn = StoreConnection.make(LOC) ; - //sConn.getTransMgr().recording(true) ; - return sConn ; - } - - public T_TransSystem() {} - - //@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. - Callable<?> procW_c = new Writer(sConn, writerCommitSeqRepeats, writerMaxPause, true) ; // Number of repeats, max pause, commit. - - // All threads start and queue on this - otherwise the thread start up as the executeor is loaded. - // That can lead to uninterstin sequences of actions. - startPoint = null ; //new Semaphore(0) ; - - int RN1 = 1 ; - int RN2 = min(1, numReaderTasks) ; - int RN3 = max(numReaderTasks - RN1 - RN2,0); - - int WC1 = numWriterTasksC/2 ; - int WC2 = 2 ; - int WC3 = numWriterTasksC - WC1 - WC2 ; - - int WA1 = numWriterTasksA/2 ; - int WA2 = numWriterTasksA - WA1 ; - - //System.out.println(RN1 + " " + RN2 + " " + RN3 + " " + WC1 + " " + WC2 + " " + WA1 + " " + WA2) ; - int N = max(RN1,0) + max(RN2,0) + max(RN3,0) + max(WC1,0) + max(WC2,0) + max(WA1,0) + max(WA2,0) ; - //System.out.println(N) ; - doneSignal = new CountDownLatch(N) ; - - // Define the query mix. - submit(execService, procW_c, WC1, "COMMIT-") ; - submit(execService, procW_a, WA1, "ABORT-") ; - submit(execService, procR, RN1, "READ-") ; - submit(execService, procW_c, WC2, "COMMIT-") ; - submit(execService, procR, RN2, "READ-") ; - submit(execService, procW_a, WA2, "ABORT-") ; - submit(execService, procR, RN3, "READ-") ; - submit(execService, procW_c, WC3, "COMMIT-") ; - - if ( startPoint != null ) - // Let them all go. - startPoint.release(4000) ; - - // Wait until all done. - try { doneSignal.await() ; } - catch (InterruptedException e) { e.printStackTrace(System.err) ; } - - try { - // This is an orderly shutdown so followed by the awaitTermination - // should wait for all threads, making the CountDownLatch unnecessary. - // CountDownLatch added as a precaution while searching for JENA-163 - // which seems to see occasional uncleared out node journal files. - execService.shutdown() ; - if ( ! execService.awaitTermination(100, TimeUnit.SECONDS) ) - System.err.println("Bad shutdown") ; - } 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) - { - Node g1 = q.getGraph() ; - int n1 = (int)Math.round(Math.random()*10000) ; - int n2 = (int)Math.round(Math.random()*10000) ; - - Node g = Quad.defaultGraphNodeGenerated ; // urn:x-arq:DefaultGraphNode - Node s = NodeFactory.createURI("S") ; - Node p = NodeFactory.createURI("P"+value) ; - // Integer - that gets inlined. - Node o = NodeFactory.createLiteral(Integer.toString(value), XSDDatatype.XSDinteger) ; - return new Quad(g,s,p,o) ; - } - - static void txn(String label, DatasetGraphTxn dsg ) - { - if ( ! inlineProgress ) - return ; - checkCol() ; - print(label) ; - //print("["+dsg.getTransaction().getTxnId()+"]") ; - colCount += label.length() ; - } - - private static void startTestIteration() - { - checkCol() ; - if ( iteration%numIterationsPerBlock == 0 ) - { - if ( colCount != 0 ) - { - println() ; - colCount = 0 ; - } - - printf("%03d: ", iteration) ; - if ( inlineProgress ) - println() ; - } - } - - private static void endTestIteration() - { - if ( ! inlineProgress ) - { - checkCol() ; - printf(".") ; - colCount += 1 ; - } - else - { - println() ; - colCount = 0 ; - } - } - - private static void checkCol() - { - if ( colCount == colMax ) - { - println() ; - colCount = 0 ; - } - } - - private static void endTest() - { - if ( colCount > 0 || iteration%numIterationsPerBlock != 0 ) - { - println() ; - colCount = 0 ; - } - println() ; - } - - private static void print(String str) - { - if ( silent ) return ; - System.out.print(str) ; - } - - private static void println(String string) - { - if ( silent ) return ; - print(string) ; - println() ; - } - - private static void println() - { - if ( silent ) return ; - printf("\n") ; - System.out.flush() ; - } - - private static void printf(String string, Object...args) - { - if ( silent ) return ; - 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 = Location.create(ConfigTest.getTestingDirDB()) ; - static final AtomicInteger gen = new AtomicInteger() ; - -}
http://git-wip-us.apache.org/repos/asf/jena/blob/edab900a/jena-tdb/src/test/java/org/apache/jena/tdb/extra/T_TransSystemMultiDatasets.java ---------------------------------------------------------------------- diff --git a/jena-tdb/src/test/java/org/apache/jena/tdb/extra/T_TransSystemMultiDatasets.java b/jena-tdb/src/test/java/org/apache/jena/tdb/extra/T_TransSystemMultiDatasets.java deleted file mode 100644 index c668a59..0000000 --- a/jena-tdb/src/test/java/org/apache/jena/tdb/extra/T_TransSystemMultiDatasets.java +++ /dev/null @@ -1,553 +0,0 @@ -/* - * 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 org.apache.jena.tdb.extra; - -import static java.lang.String.format ; -import static org.apache.jena.tdb.transaction.TransTestLib.count ; - -import java.io.File ; -import java.util.ArrayList ; -import java.util.Random ; -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.apache.jena.atlas.lib.FileOps ; -import org.apache.jena.atlas.lib.Lib ; -import org.apache.jena.atlas.lib.RandomLib ; -import org.apache.jena.datatypes.xsd.XSDDatatype ; -import org.apache.jena.graph.Node ; -import org.apache.jena.graph.NodeFactory ; -import org.apache.jena.query.ReadWrite ; -import org.apache.jena.shared.Lock ; -import org.apache.jena.sparql.core.DatasetGraph ; -import org.apache.jena.sparql.core.Quad ; -import org.apache.jena.sparql.sse.SSE ; -import org.apache.jena.tdb.ConfigTest ; -import org.apache.jena.tdb.StoreConnection ; -import org.apache.jena.tdb.TDBFactory ; -import org.apache.jena.tdb.base.block.FileMode ; -import org.apache.jena.tdb.base.file.Location ; -import org.apache.jena.tdb.sys.SystemTDB ; -import org.apache.jena.tdb.transaction.DatasetGraphTxn ; -import org.apache.jena.tdb.transaction.SysTxnState ; -import org.apache.jena.tdb.transaction.TransactionManager ; -import org.junit.AfterClass ; -import org.junit.BeforeClass ; -import org.slf4j.Logger ; -import org.slf4j.LoggerFactory ; - -/** System testing using multiple datasets of the transactions. */ -public class T_TransSystemMultiDatasets -{ - // Use this to flip between FileMode.direct and FileMode.mapped - static { SystemTDB.setFileMode(FileMode.mapped) ; } - static { org.apache.jena.atlas.logging.LogCtl.setLog4j() ; } - private static Logger log = LoggerFactory.getLogger(T_TransSystemMultiDatasets.class) ; - - static boolean MEM = false ; - static boolean USE_TRANSACTIONS = false ; - - static final int NUM_DATASETS = 3 ; - static final ArrayList<Location> LOCATIONS = new ArrayList<>() ; - - static { - for ( int i = 0; i < NUM_DATASETS; i++ ) - LOCATIONS.add(createLocation()) ; - } - - private static int count_datasets = 0 ; - static Location createLocation() { - return MEM ? Location.mem() : Location.create(ConfigTest.getTestingDirDB() + File.separator + "DB-" + ++count_datasets) ; - } - - static final int Iterations = MEM ? 1000 : 100 ; - // Output style. - static boolean inlineProgress = true ; // (! log.isDebugEnabled()) && Iterations > 20 ; - static boolean logging = ! inlineProgress ; // (! log.isDebugEnabled()) && Iterations > 20 ; - - static final int numReaderTasks = 10 ; - static final int numWriterTasksA = 10 ; - static final int numWriterTasksC = 10 ; - - static final int readerSeqRepeats = 8 ; - static final int readerMaxPause = 50 ; - - static final int writerAbortSeqRepeats = 4 ; - static final int writerCommitSeqRepeats = 4 ; - static final int writerMaxPause = 25 ; - - - public static void main(String...args) - { - if ( logging ) - log.info("START ("+ (MEM?"memory":"disk") + ", {} iterations)", Iterations) ; - else - printf("START (%s, %d iterations)\n", (MEM?"memory":"disk"), Iterations) ; - - int N = (Iterations < 10) ? 1 : Iterations / 10 ; - N = Math.min(N, 100) ; - int i ; - - for ( i = 0 ; i < Iterations ; i++ ) - { - clean() ; - - 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 T_TransSystemMultiDatasets().manyReaderAndOneWriter() ; - } - 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() - { - for ( Location location : LOCATIONS ) { - StoreConnection.release(location) ; - if ( ! location.isMem() ) - FileOps.clearDirectory(location.getDirectoryPath()) ; - } - } - - static class ReaderTx implements Callable<Object> - { - private final int repeats ; - private final int maxpause ; - private final T_TransSystemMultiDatasets tts ; - - ReaderTx(T_TransSystemMultiDatasets tts, int numSeqRepeats, int pause) - { - this.repeats = numSeqRepeats ; - this.maxpause = pause ; - this.tts = tts ; - } - - @Override - public Object call() - { - StoreConnection sConn = tts.getStoreConnection() ; - 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) ; - - int x1 = count("SELECT * { ?s ?p ?o }", dsg) ; - pause(maxpause) ; - int x2 = count("SELECT * { ?s ?p ?o }", dsg) ; - // Eclispe Kepler (3.4) bug - otherwise the dsg.end() below - // gets a warning ("The variable dsg can only be null at this location")/ - // which is wrong. - dsg.getClass() ; - if ( x1 != x2 ) - log.warn(format("READER: %s Change seen: %d/%d : id=%d: i=%d", dsg.getTransaction().getLabel(), - x1, x2, id, i)) ; - dsg.end() ; - log.debug("reader finish " + id + "/" + i) ; - dsg = null ; - } - return null ; - } catch (RuntimeException ex) - { - ex.printStackTrace(System.err) ; - if ( dsg != null ) - { - dsg.abort() ; - dsg.end() ; - dsg = null ; - } - return null ; - } - } - } - - static abstract class WriterTx implements Callable<Object> - { - private final int repeats ; - private final int maxpause ; - private final T_TransSystemMultiDatasets tts ; - private final boolean commit ; - - protected WriterTx(T_TransSystemMultiDatasets tts, int numSeqRepeats, int pause, boolean commit) - { - this.repeats = numSeqRepeats ; - this.maxpause = pause ; - this.tts = tts ; - this.commit = commit ; - } - - @Override - public Object call() - { - StoreConnection sConn = tts.getStoreConnection() ; - DatasetGraphTxn dsg = null ; - try { - int id = gen.incrementAndGet() ; - for ( int i = 0 ; i < repeats ; i++ ) - { - log.debug("writer start "+id+"/"+i) ; - dsg = sConn.begin(ReadWrite.WRITE) ; - - 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) ; - if ( dsg != null ) - { - dsg.abort() ; - dsg.end() ; - dsg = null ; - } - return null ; - } - } - - // return the delta. - protected abstract int change(DatasetGraphTxn dsg, int id, int i) ; - } - - static class Reader implements Callable<Object> - { - private final int repeats ; - private final int maxpause ; - private final T_TransSystemMultiDatasets tts ; - - Reader(T_TransSystemMultiDatasets tts, int numSeqRepeats, int pause) - { - this.repeats = numSeqRepeats ; - this.maxpause = pause ; - this.tts = tts ; - } - - @Override - public Object call() - { - DatasetGraph dsg = null ; - Lock lock = null ; - try - { - dsg = tts.getDatasetGraph() ; - lock = dsg.getLock() ; - int id = gen.incrementAndGet() ; - for (int i = 0; i < repeats; i++) - { - try { - lock.enterCriticalSection(Lock.READ) ; - log.debug("reader start " + id + "/" + i) ; - - 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", - "read-" + i, x1, x2, id, i)) ; - log.debug("reader finish " + id + "/" + i) ; - } catch (RuntimeException ex) - { - log.debug("reader error " + id + "/" + i) ; - ex.printStackTrace() ; - } finally { - lock.leaveCriticalSection() ; - } - } - return null ; - } catch (RuntimeException ex) - { - ex.printStackTrace(System.err) ; - return null ; - } - } - } - - static abstract class Writer implements Callable<Object> - { - private final int repeats ; - private final int maxpause ; - private final T_TransSystemMultiDatasets tts ; - - protected Writer(T_TransSystemMultiDatasets tts, int numSeqRepeats, int pause) - { - this.repeats = numSeqRepeats ; - this.maxpause = pause ; - this.tts = tts ; - } - - @Override - public Object call() - { - DatasetGraph dsg = null ; - Lock lock = null ; - try { - dsg = tts.getDatasetGraph() ; - lock = dsg.getLock() ; - int id = gen.incrementAndGet() ; - for ( int i = 0 ; i < repeats ; i++ ) - { - try { - lock.enterCriticalSection(Lock.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 ) - { - log.warn(format("WRITER: %s Change seen: %d + %d != %d : id=%d: i=%d", "write-" + i, x1, z, x2, id, i)) ; - return null ; - } - log.debug("writer finish "+id+"/"+i) ; - } catch (RuntimeException ex) - { - log.debug("writer error "+id+"/"+i) ; - System.err.println(ex.getMessage()) ; - ex.printStackTrace() ; - } finally { - lock.leaveCriticalSection() ; - } - } - return null ; - } - catch (RuntimeException ex) - { - ex.printStackTrace(System.err) ; - return null ; - } - } - - // return the delta. - protected abstract int change(DatasetGraph dsg, int id, int i) ; - } - - @BeforeClass - public static void beforeClass() - { - for ( Location location : LOCATIONS ) { - if ( ! location.isMem() ) - FileOps.clearDirectory(location.getDirectoryPath()) ; - } - StoreConnection.reset() ; - } - - @AfterClass - public static void afterClass() {} - - private StoreConnection sConn ; - private static Random random = new Random(System.currentTimeMillis()) ; - - protected synchronized StoreConnection getStoreConnection() - { - StoreConnection sConn = StoreConnection.make(LOCATIONS.get(random.nextInt(NUM_DATASETS))) ; - //sConn.getTransMgr().recording(true) ; - return sConn ; - } - - protected synchronized DatasetGraph getDatasetGraph() - { - DatasetGraph dsg = TDBFactory.createDatasetGraph(LOCATIONS.get(random.nextInt(NUM_DATASETS))) ; - - if ( dsg == null ) - throw new RuntimeException("DatasetGraph is null!") ; - - return dsg ; - } - - public T_TransSystemMultiDatasets() {} - - //@Test - public void manyRead() - { - final StoreConnection sConn = getStoreConnection() ; - Callable<?> proc = new ReaderTx(this, 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(); - } - } - - //@Test - public void manyReaderAndOneWriter() - { - Callable<?> procRTx = new ReaderTx(this, readerSeqRepeats, readerMaxPause) ; // Number of repeats, max pause - Callable<?> procWTx_a = new WriterTx(this, 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<?> procWTx_c = new WriterTx(this, writerCommitSeqRepeats, writerMaxPause, true) // Number of repeats, max pause, commit. - { - @Override - protected int change(DatasetGraphTxn dsg, int id, int i) - { return changeProc(dsg, id, i) ; } - } ; - - Callable<?> procR = new Reader(this, readerSeqRepeats, readerMaxPause) ; - Callable<?> procW = new Writer(this, writerCommitSeqRepeats, writerMaxPause) - { - @Override - protected int change(DatasetGraph dsg, int id, int i) - { return changeProc(dsg, id, i) ; } - } ; - - if ( USE_TRANSACTIONS ) { - submit(execService, procRTx, numReaderTasks) ; - submit(execService, procWTx_c, numWriterTasksC) ; - submit(execService, procWTx_a, numWriterTasksA) ; - } else { - submit(execService, procR, numReaderTasks) ; - submit(execService, procW, numWriterTasksC) ; - } - - try - { - execService.shutdown() ; - execService.awaitTermination(100, TimeUnit.SECONDS) ; - } catch (InterruptedException e) - { - e.printStackTrace(); - } - } - - private void submit(ExecutorService execService2, Callable<?> proc, int numTasks) - { - for ( int i = 0 ; i < numTasks ; i++ ) - execService.submit(proc) ; - } - - static int changeProc(DatasetGraph 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 = NodeFactory.createURI("S") ; - Node p = NodeFactory.createURI("P") ; - Node o = NodeFactory.createLiteral(Integer.toString(value), 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) ; - } - - private ExecutorService execService = Executors.newCachedThreadPool() ; - - 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 = Location.create(ConfigTest.getTestingDirDB()) ; - static final AtomicInteger gen = new AtomicInteger() ; - -} http://git-wip-us.apache.org/repos/asf/jena/blob/edab900a/jena-tdb/src/test/java/org/apache/jena/tdb/extra/T_TxnDeadlockTest.java ---------------------------------------------------------------------- diff --git a/jena-tdb/src/test/java/org/apache/jena/tdb/extra/T_TxnDeadlockTest.java b/jena-tdb/src/test/java/org/apache/jena/tdb/extra/T_TxnDeadlockTest.java deleted file mode 100644 index a3f4413..0000000 --- a/jena-tdb/src/test/java/org/apache/jena/tdb/extra/T_TxnDeadlockTest.java +++ /dev/null @@ -1,141 +0,0 @@ -/** - * 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 org.apache.jena.tdb.extra; - -import java.security.SecureRandom ; -import java.util.Iterator ; -import java.util.concurrent.CountDownLatch ; -import java.util.concurrent.ExecutorService ; -import java.util.concurrent.Executors ; -import java.util.concurrent.atomic.AtomicInteger ; - -import org.apache.jena.atlas.logging.LogCtl ; -import org.apache.jena.graph.Node ; -import org.apache.jena.graph.NodeFactory ; -import org.apache.jena.query.ReadWrite ; -import org.apache.jena.sparql.core.Quad ; -import org.apache.jena.tdb.StoreConnection ; -import org.apache.jena.tdb.base.file.Location ; -import org.apache.jena.tdb.transaction.DatasetGraphTxn ; -import org.apache.jena.tdb.transaction.TransactionManager ; - -public class T_TxnDeadlockTest { - - static { - LogCtl.setLog4j() ; - //Log.enable("TDB") ; - if ( false ) LogCtl.enable(TransactionManager.class) ; - //Log.enable(LockMRSW.class) ; - } - - private static final int CONCURRENT_RANDOM_OPERATIONS = 1000; - - private static final SecureRandom numberGenerator = new SecureRandom(); - - public static void main(String ... argv) - { - for(int i = 0 ; i < 1000 ; i++ ) - { - System.out.println("Loop = "+i) ; - new T_TxnDeadlockTest().test() ; - } - } - - //@Test - public void test() { - final StoreConnection storeConnection = - StoreConnection.make(Location.mem()); - - //ExecutorService executor = Executors.newCachedThreadPool() ; // Not seen blocking. - // 4 blocks maybe 1 in 4 times - // 8 blocks (quad core) 2 in 3 times. - ExecutorService executor = Executors.newFixedThreadPool(8) ; - - final AtomicInteger nbQuadruplesAdded = new AtomicInteger(); - - final CountDownLatch doneSignal = - new CountDownLatch(CONCURRENT_RANDOM_OPERATIONS); - - for (int i = 0; i < CONCURRENT_RANDOM_OPERATIONS; i++) { - executor.execute(new Runnable() { - @Override - public void run() { - try { - if (numberGenerator.nextInt(2) == 0) { - DatasetGraphTxn txnGraph = - storeConnection.begin(ReadWrite.WRITE); - txnGraph.add(new Quad( - NodeFactory.createURI("http://jena-example.org/" - + numberGenerator.nextInt()), - NodeFactory.createURI("http://jena-example.org/" - + numberGenerator.nextInt()), - NodeFactory.createURI("http://jena-example.org/" - + numberGenerator.nextInt()), - NodeFactory.createURI("http://jena-example.org/" - + numberGenerator.nextInt()))); - txnGraph.commit(); - txnGraph.end(); - nbQuadruplesAdded.incrementAndGet(); - } else { - DatasetGraphTxn txnGraph = - storeConnection.begin(ReadWrite.READ); - txnGraph.find(Node.ANY, Node.ANY, Node.ANY, Node.ANY); - //Iterator<Quad> iter = txnGraph.find(Node.ANY, Node.ANY, Node.ANY, Node.ANY); - //Iter.count(iter) ; // Consume - txnGraph.end(); - } - } finally { - doneSignal.countDown(); - } - } - }); - } - - // shutdown is orderly so sync'ing up before the shutdown is nice but not needed. - try { - doneSignal.await(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } finally { - executor.shutdown(); - } - - DatasetGraphTxn txnGraph = - storeConnection.begin(ReadWrite.READ); - Iterator<Quad> result = txnGraph.find( - Node.ANY, Node.ANY, Node.ANY, Node.ANY); - - long count = 0; - while (result.hasNext()) { - result.next(); - count++; - } - - txnGraph.end(); - - StoreConnection.release(storeConnection.getLocation()); - - //System.out.println() ; - System.out.println("FINISHED") ; - -// // This is unsafe - the quad adds may generate duplicates (ity's unlikly 4 random number reoccur but it's possible). -// Assert.assertEquals(count, nbQuadruplesAdded.get()); - } - -} http://git-wip-us.apache.org/repos/asf/jena/blob/edab900a/jena-tdb/src/test/java/org/apache/jena/tdb/store/AbstractStoreConnections.java ---------------------------------------------------------------------- diff --git a/jena-tdb/src/test/java/org/apache/jena/tdb/store/AbstractStoreConnections.java b/jena-tdb/src/test/java/org/apache/jena/tdb/store/AbstractStoreConnections.java index d4deaf3..4bae910 100644 --- a/jena-tdb/src/test/java/org/apache/jena/tdb/store/AbstractStoreConnections.java +++ b/jena-tdb/src/test/java/org/apache/jena/tdb/store/AbstractStoreConnections.java @@ -21,7 +21,7 @@ package org.apache.jena.tdb.store; import org.apache.jena.atlas.iterator.Iter ; import org.apache.jena.atlas.junit.BaseTest ; import org.apache.jena.query.Dataset ; -import org.apache.jena.query.ReadWrite ; +import org.apache.jena.query.TxnType; import org.apache.jena.rdf.model.Model ; import org.apache.jena.sparql.core.DatasetGraph ; import org.apache.jena.sparql.core.Quad ; @@ -70,7 +70,7 @@ public abstract class AbstractStoreConnections extends BaseTest // Expel. StoreConnection sConn = getStoreConnection() ; assertTrue(sConn.isValid()); - DatasetGraphTxn dsgW1 = sConn.begin(ReadWrite.WRITE) ; + DatasetGraphTxn dsgW1 = sConn.begin(TxnType.WRITE) ; dsgW1.commit() ; dsgW1.end() ; StoreConnection.release(sConn.getLocation()) ; @@ -81,8 +81,8 @@ public abstract class AbstractStoreConnections extends BaseTest public void store_1() { // Expel. StoreConnection sConn = getStoreConnection() ; - DatasetGraphTxn dsgR1 = sConn.begin(ReadWrite.READ) ; - DatasetGraphTxn dsgW1 = sConn.begin(ReadWrite.WRITE) ; + DatasetGraphTxn dsgR1 = sConn.begin(TxnType.READ) ; + DatasetGraphTxn dsgW1 = sConn.begin(TxnType.WRITE) ; dsgW1.add(q1) ; dsgW1.commit() ; dsgW1.end() ; @@ -101,7 +101,7 @@ public abstract class AbstractStoreConnections extends BaseTest public void store_2() { // Expel. StoreConnection sConn = getStoreConnection() ; - DatasetGraphTxn dsgR1 = sConn.begin(ReadWrite.READ) ; + DatasetGraphTxn dsgR1 = sConn.begin(TxnType.READ) ; StoreConnection.release(sConn.getLocation()) ; } @@ -109,15 +109,15 @@ public abstract class AbstractStoreConnections extends BaseTest public void store_3() { // Expel. StoreConnection sConn = getStoreConnection() ; - DatasetGraphTxn dsgR1 = sConn.begin(ReadWrite.WRITE) ; + DatasetGraphTxn dsgR1 = sConn.begin(TxnType.WRITE) ; StoreConnection.release(sConn.getLocation()) ; } @Test public void store_4() { StoreConnection sConn = getStoreConnection() ; - DatasetGraphTxn dsgR1 = sConn.begin(ReadWrite.READ) ; - DatasetGraphTxn dsgW1 = sConn.begin(ReadWrite.WRITE) ; + DatasetGraphTxn dsgR1 = sConn.begin(TxnType.READ) ; + DatasetGraphTxn dsgW1 = sConn.begin(TxnType.WRITE) ; dsgW1.add(q1) ; dsgW1.commit() ; dsgW1.end() ; @@ -127,12 +127,12 @@ public abstract class AbstractStoreConnections extends BaseTest sConn = null ; StoreConnection sConn2 = getStoreConnection() ; - DatasetGraphTxn dsgW2 = sConn2.begin(ReadWrite.WRITE) ; + DatasetGraphTxn dsgW2 = sConn2.begin(TxnType.WRITE) ; dsgW2.add(q2) ; dsgW2.commit() ; dsgW2.end() ; - DatasetGraphTxn dsgR2 = sConn2.begin(ReadWrite.READ) ; + DatasetGraphTxn dsgR2 = sConn2.begin(TxnType.READ) ; long x = Iter.count(dsgR2.find()) ; assertEquals(2, x) ; } @@ -160,7 +160,7 @@ public abstract class AbstractStoreConnections extends BaseTest StoreConnection sConn = getStoreConnection() ; Location loc = sConn.getLocation() ; - DatasetGraphTxn dsgTxn = sConn.begin(ReadWrite.WRITE) ; + DatasetGraphTxn dsgTxn = sConn.begin(TxnType.WRITE) ; dsgTxn.add(q1) ; assertTrue(dsgTxn.contains(q1)) ; @@ -175,7 +175,7 @@ public abstract class AbstractStoreConnections extends BaseTest DatasetGraph dsg2 = sConn.getBaseDataset() ; assertTrue(dsg2.contains(q1)) ; - DatasetGraphTxn dsgTxn2 = sConn.begin(ReadWrite.READ) ; + DatasetGraphTxn dsgTxn2 = sConn.begin(TxnType.READ) ; assertTrue(dsgTxn2.contains(q1)) ; dsgTxn2.end() ; } @@ -196,7 +196,7 @@ public abstract class AbstractStoreConnections extends BaseTest assertTrue(dsg.contains(q)) ; } - DatasetGraphTxn dsgTxn = sConn.begin(ReadWrite.WRITE) ; + DatasetGraphTxn dsgTxn = sConn.begin(TxnType.WRITE) ; if ( nonTxnData ) assertTrue(dsgTxn.contains(q)) ; dsgTxn.add(q1) ; @@ -224,7 +224,7 @@ public abstract class AbstractStoreConnections extends BaseTest assertTrue(dsg2.contains(q)) ; assertTrue(dsg2.contains(q1)) ; - DatasetGraphTxn dsgTxn2 = sConn2.begin(ReadWrite.READ) ; + DatasetGraphTxn dsgTxn2 = sConn2.begin(TxnType.READ) ; if ( nonTxnData ) assertTrue(dsgTxn2.contains(q)) ; assertTrue(dsgTxn2.contains(q1)) ; @@ -232,7 +232,7 @@ public abstract class AbstractStoreConnections extends BaseTest // Check API methods work. Dataset ds = TDBFactory.createDataset(loc) ; - ds.begin(ReadWrite.READ) ; + ds.begin(TxnType.READ) ; Model m = (q.isDefaultGraph() ? ds.getDefaultModel() : ds.getNamedModel("g")) ; assertEquals(nonTxnData ? 2 : 1, m.size()) ; ds.end() ; http://git-wip-us.apache.org/repos/asf/jena/blob/edab900a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestObjectFileTrans.java ---------------------------------------------------------------------- diff --git a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestObjectFileTrans.java b/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestObjectFileTrans.java index 0b36d13..5309391 100644 --- a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestObjectFileTrans.java +++ b/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestObjectFileTrans.java @@ -49,7 +49,7 @@ public abstract class AbstractTestObjectFileTrans extends BaseTest @Before public void setup() { - txn = new Transaction(null, 5, TxnType.WRITE, ReadWrite.WRITE, ++count, null, tm) ; + txn = new Transaction(null, 5, TxnType.WRITE, ReadWrite.WRITE, ++count, TxnType.WRITE, null, tm) ; file1 = createFile("base") ; //file2 = createFile("log") ; } http://git-wip-us.apache.org/repos/asf/jena/blob/edab900a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestObjectFileTransComplex.java ---------------------------------------------------------------------- diff --git a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestObjectFileTransComplex.java b/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestObjectFileTransComplex.java index 3e46643..5cecb5e 100644 --- a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestObjectFileTransComplex.java +++ b/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestObjectFileTransComplex.java @@ -48,7 +48,7 @@ public abstract class AbstractTestObjectFileTransComplex extends BaseTest @Before public void setup() { - txn = new Transaction(null, 5, TxnType.WRITE, ReadWrite.WRITE, ++count, null, tm) ; + txn = new Transaction(null, 5, TxnType.WRITE, ReadWrite.WRITE, ++count, TxnType.WRITE, null, tm) ; file1 = createFile("base") ; file2 = createFile("log") ; } http://git-wip-us.apache.org/repos/asf/jena/blob/edab900a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestTransSeq.java ---------------------------------------------------------------------- diff --git a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestTransSeq.java b/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestTransSeq.java index f341996..ba3fbd2 100644 --- a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestTransSeq.java +++ b/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/AbstractTestTransSeq.java @@ -162,8 +162,6 @@ public abstract class AbstractTestTransSeq extends BaseTest assertTrue(dsg.contains(q1)) ; assertTrue(dsg.contains(q2)) ; } - - @Test public void trans_readBlock_01() { @@ -180,10 +178,6 @@ public abstract class AbstractTestTransSeq extends BaseTest assertFalse(dsgR1.contains(q)) ; dsgR1.end() ; - //**** Not hitting the queue **** - // Order of tweaking counters? - // also writer and counters? - DatasetGraphTxn dsgR2 = sConn.begin(TxnType.READ) ; assertTrue(dsgR2.contains(q)) ; dsgR2.end() ; http://git-wip-us.apache.org/repos/asf/jena/blob/edab900a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransPromoteTDB.java ---------------------------------------------------------------------- diff --git a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransPromoteTDB.java b/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransPromoteTDB.java index e71d990..4027765 100644 --- a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransPromoteTDB.java +++ b/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransPromoteTDB.java @@ -18,6 +18,7 @@ package org.apache.jena.tdb.transaction ; +import org.apache.jena.sparql.JenaTransactionException; import org.apache.jena.sparql.core.DatasetGraph ; import org.apache.jena.sparql.transaction.AbstractTestTransPromote ; import org.apache.jena.tdb.TDB ; @@ -44,7 +45,7 @@ public class TestTransPromoteTDB extends AbstractTestTransPromote { } @Override - protected Class<TDBTransactionException> getTransactionExceptionClass() { - return TDBTransactionException.class ; + protected Class<JenaTransactionException> getTransactionExceptionClass() { + return JenaTransactionException.class ; } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jena/blob/edab900a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransactionTDB.java ---------------------------------------------------------------------- diff --git a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransactionTDB.java b/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransactionTDB.java index e63cf66..1a036ab 100644 --- a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransactionTDB.java +++ b/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransactionTDB.java @@ -61,7 +61,8 @@ public class TestTransactionTDB extends AbstractTestTransactionLifecycle private static Triple triple1 = SSE.parseTriple("(<s> <p> <o>)") ; - @Test public void transaction_50() { + @Test + public void transaction_50() { // This assumes you have two datasets on the same location. // That's not necessarily true for uncached memory datasets, // where you get two separate datasets so changes to one are
