Author: reto
Date: Mon Oct 25 10:21:46 2010
New Revision: 1027030

URL: http://svn.apache.org/viewvc?rev=1027030&view=rev
Log:
CLEREZZA-340: TDB STorage provider now returns LockableMGraphs

Added:
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java
Modified:
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.integrationtest.web/pom-run.xml
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java

Modified: 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.integrationtest.web/pom-run.xml
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.integrationtest.web/pom-run.xml?rev=1027030&r1=1027029&r2=1027030&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.integrationtest.web/pom-run.xml
 (original)
+++ 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.integrationtest.web/pom-run.xml
 Mon Oct 25 10:21:46 2010
@@ -12,6 +12,9 @@
        <version>0.1-incubating-SNAPSHOT</version>
        <name>Clerezza - Web Test Framework</name>
        <description>A framework to run tests against a webserver</description>
+  <properties>
+    <org.osgi.service.http.port>8383</org.osgi.service.http.port>
+  </properties>
        <dependencies>
                <dependency>
                        <groupId>org.ops4j.pax.logging</groupId>
@@ -31,10 +34,10 @@
                        <groupId>org.apache.clerezza.ext</groupId>
                        <artifactId>javax.mail</artifactId>
                </dependency>
-               <dependency>
+               <dependency>
                        <groupId>org.apache.clerezza</groupId>
                        
<artifactId>org.apache.clerezza.integrationtest.web.performance</artifactId>
-               </dependency>
+               </dependency> 
                <dependency>
                        <groupId>org.apache.commons</groupId>
                        
<artifactId>com.springsource.org.apache.commons.httpclient</artifactId>

Modified: 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java?rev=1027030&r1=1027029&r2=1027030&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java
 (original)
+++ 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java
 Mon Oct 25 10:21:46 2010
@@ -41,6 +41,8 @@ import org.apache.clerezza.rdf.core.Trip
 import org.apache.clerezza.rdf.core.UriRef;
 import org.apache.clerezza.rdf.core.access.EntityAlreadyExistsException;
 import org.apache.clerezza.rdf.core.access.EntityUndeletableException;
+import org.apache.clerezza.rdf.core.access.LockableMGraph;
+import org.apache.clerezza.rdf.core.access.LockableMGraphWrapper;
 import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
 import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
 import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
@@ -68,17 +70,17 @@ import org.apache.felix.scr.annotations.
 @Property(name="weight", intValue=105)
 public class TdbTcProvider implements WeightedTcProvider {
 
-       @Property(intValue=600, description="Specifies the number of seconds to 
wait "
+       @Property(intValue=6, description="Specifies the number of seconds to 
wait "
        + "between synchronizations of the TDB datasets to the filesystem")
        public static final String SYNC_INTERVAL = "sync-interval";
-       private int syncInterval = 600;
+       private int syncInterval = 6;
 
        /**
         *      directory where all graphs are stored
         */
        private static final String DATA_PATH_NAME = "tdb-data/";
        private String dataPathString = DATA_PATH_NAME;
-       private Map<UriRef, MGraph> mGraphMap = new HashMap<UriRef, MGraph>();
+       private Map<UriRef, LockableMGraph> mGraphMap = new HashMap<UriRef, 
LockableMGraph>();
        private Map<UriRef, Graph> graphMap = new HashMap<UriRef, Graph>();
        private Map<File, com.hp.hpl.jena.graph.Graph> dir2JenaGraphMap =
                        new HashMap<File, com.hp.hpl.jena.graph.Graph>();
@@ -182,7 +184,7 @@ public class TdbTcProvider implements We
                        throw new EntityAlreadyExistsException(name);
                }
                tcDir.mkdirs();
-               MGraph result = new PrivilegedMGraphWrapper(getMGraph(tcDir));
+               LockableMGraph result = new 
LockableMGraphWrapper(getMGraph(tcDir));
                mGraphMap.put(name, result);
                return result;
        }
@@ -199,7 +201,7 @@ public class TdbTcProvider implements We
                        triples = new SimpleMGraph();
                }
                tcDir.mkdirs();
-               MGraph mGraph = new PrivilegedMGraphWrapper(getMGraph(tcDir));
+               MGraph mGraph = getMGraph(tcDir);
                mGraph.addAll(triples);
                Graph result = mGraph.getGraph();
                
@@ -309,7 +311,7 @@ public class TdbTcProvider implements We
                synchronized(dir2Dataset) {
                        dir2Dataset.put(tcDir, dataset);
                }
-               return new JenaGraphAdaptor(jenaGraph);
+               return new PrivilegedMGraphWrapper(new 
JenaGraphAdaptor(jenaGraph));
        }
 
        private File getMGraphDir(UriRef name) {
@@ -346,7 +348,7 @@ public class TdbTcProvider implements We
                        for (String mGraphDirName : mGraphsDir.list()) {
                                try {
                                        UriRef uri = new 
UriRef(URLDecoder.decode(mGraphDirName, "utf-8"));
-                                       mGraphMap.put(uri, getMGraph(new 
File(mGraphsDir, mGraphDirName)));
+                                       mGraphMap.put(uri, new 
LockableMGraphWrapper(getMGraph(new File(mGraphsDir, mGraphDirName))));
                                } catch (UnsupportedEncodingException ex) {
                                        throw new RuntimeException("utf-8 not 
supported", ex);
                                }

Added: 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java?rev=1027030&view=auto
==============================================================================
--- 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java
 (added)
+++ 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java
 Mon Oct 25 10:21:46 2010
@@ -0,0 +1,114 @@
+package org.apache.clerezza.rdf.jena.tdb.storage;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.Assert;
+
+import org.apache.clerezza.rdf.core.BNode;
+import org.apache.clerezza.rdf.core.Literal;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.Resource;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.felix.scr.annotations.Activate;
+import org.junit.Before;
+import org.junit.Test;
+import org.wymiwyg.commons.util.Util;
+
+
+public class MultiThreadedTest {
+       
+       
+       
+       /** 
+        * how many threads to start
+        */
+       private static final int THREAD_COUNT = 100;
+       /**
+        * how many seconds to let them run
+        */
+       private static final int DELAY = 120;
+       
+       
+       private MGraph mGraph;
+       private Set<Triple> testTriples = Collections.synchronizedSet(new 
HashSet<Triple>()); 
+
+       class TestThread extends Thread {
+
+               private final int id;
+               private boolean stopRequested;
+               private int addedTripleCount = 0;
+
+               public TestThread(final int id) {
+                       this.id = id;
+                       start();
+               }
+
+               public void requestStop() {
+                       stopRequested = true;
+               }
+
+               @Override
+               public void run() {
+                       while (!stopRequested) {
+                               Literal randomLiteral = new 
PlainLiteralImpl(Util.createRandomString(22));
+                               Triple triple = new TripleImpl(new BNode(), new 
UriRef("http://example.com/property";), randomLiteral);
+                               mGraph.add(triple);
+                               addedTripleCount++;
+                               if ((addedTripleCount % 100) == 0) {
+                                       testTriples.add(triple);
+                               }
+                       }
+               }
+
+               public int getAddedTripleCount() {
+                       return addedTripleCount;
+               }
+
+       }
+
+       
+       
+       @Before
+       public void setUp() throws IOException {
+               File tempFile;
+               UriRef MGRAPHNAME = new UriRef("http://text.example.org/";);
+               TdbTcProvider tdbTcProvider;
+               tempFile = File.createTempFile("tdbtest", null);
+               tempFile.delete();
+               tempFile.mkdirs();
+               tdbTcProvider = new TdbTcProvider(tempFile);
+               tdbTcProvider.activate(null);
+               mGraph = tdbTcProvider.createMGraph(MGRAPHNAME);
+       }
+
+       @Test
+       public void perform() throws InterruptedException {
+               TestThread[] threads =  new TestThread[THREAD_COUNT];
+               for (int i = 0; i < threads.length; i++) {
+                       threads[i] = new TestThread(i);
+               }
+               Thread.sleep(DELAY*1000);
+               for (TestThread testThread : threads) {
+                       testThread.requestStop();
+               }
+               for (TestThread testThread : threads) {
+                       testThread.join();
+               }
+               int addedTriples = 0;
+               for (TestThread testThread : threads) {
+                       addedTriples += testThread.getAddedTripleCount();
+               }
+               Assert.assertEquals(addedTriples, mGraph.size());
+               for (Triple testTriple : testTriples) {
+                       Assert.assertTrue(mGraph.contains(testTriple));
+               }
+       }
+
+}


Reply via email to