clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1535716 - in /clerezza/trunk: rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/TcProviderTest.java rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java
Date Fri, 25 Oct 2013 12:49:16 GMT
Author: reto
Date: Fri Oct 25 12:49:15 2013
New Revision: 1535716

URL: http://svn.apache.org/r1535716
Log:
CLEREZZA-737: trying hard to delete files on windows too (using System.gc() repeatedly)

Modified:
    clerezza/trunk/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/TcProviderTest.java
    clerezza/trunk/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java

Modified: clerezza/trunk/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/TcProviderTest.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/TcProviderTest.java?rev=1535716&r1=1535715&r2=1535716&view=diff
==============================================================================
--- clerezza/trunk/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/TcProviderTest.java
(original)
+++ clerezza/trunk/rdf.core.test/src/main/java/org/apache/clerezza/rdf/core/test/TcProviderTest.java
Fri Oct 25 12:49:15 2013
@@ -72,6 +72,7 @@ public abstract class TcProviderTest {
         } catch (EntityAlreadyExistsException e) {
             assertTrue(true);
         }
+        simpleTcmProvider.deleteTripleCollection(uriRefA);
     }
 
     @Test
@@ -86,6 +87,7 @@ public abstract class TcProviderTest {
         } catch (EntityAlreadyExistsException e) {
             assertTrue(true);
         }
+        simpleTcmProvider.deleteTripleCollection(uriRefA);
     }
 
     @Test
@@ -109,6 +111,10 @@ public abstract class TcProviderTest {
         Iterator<Triple> iterator = bGraph.iterator();
         assertEquals(new TripleImpl(uriRefB, uriRefB, uriRefB), iterator.next());
         assertFalse(iterator.hasNext());
+        simpleTcmProvider.deleteTripleCollection(uriRefA);
+        simpleTcmProvider.deleteTripleCollection(uriRefA1);
+        simpleTcmProvider.deleteTripleCollection(uriRefB);
+        simpleTcmProvider.deleteTripleCollection(uriRefB1);
     }
 
     @Test
@@ -131,6 +137,11 @@ public abstract class TcProviderTest {
         Iterator<Triple> iterator = bGraph.iterator();
         assertEquals(new TripleImpl(uriRefB, uriRefB, uriRefB), iterator.next());
         assertFalse(iterator.hasNext());
+        simpleTcmProvider.deleteTripleCollection(uriRefA);
+        simpleTcmProvider.deleteTripleCollection(uriRefA1);
+        simpleTcmProvider.deleteTripleCollection(uriRefB);
+        simpleTcmProvider.deleteTripleCollection(uriRefB1);
+        
     }
 
     @Test
@@ -161,6 +172,10 @@ public abstract class TcProviderTest {
         iterator = tripleCollection2.iterator();
         assertEquals(new TripleImpl(uriRefB1, uriRefB1, uriRefB1), iterator.next());
         assertFalse(iterator.hasNext());
+        simpleTcmProvider.deleteTripleCollection(uriRefA);
+        simpleTcmProvider.deleteTripleCollection(uriRefA1);
+        simpleTcmProvider.deleteTripleCollection(uriRefB);
+        simpleTcmProvider.deleteTripleCollection(uriRefB1);
     }
 
     @Test
@@ -183,6 +198,7 @@ public abstract class TcProviderTest {
         // Check that graph is still available under uriRefC
         Graph cGraph = simpleTcmProvider.getGraph(uriRefC);
         assertNotNull(cGraph);
+        simpleTcmProvider.deleteTripleCollection(uriRefC);
     }
 
     /**
@@ -236,6 +252,7 @@ public abstract class TcProviderTest {
         }
 
         assertTrue(expThrown);
+        provider.deleteTripleCollection(graphUriRef);
     }
 
     @Test
@@ -261,6 +278,7 @@ public abstract class TcProviderTest {
         }
 
         assertTrue(expThrown);
+        provider.deleteTripleCollection(graphUriRef);
     }
 
     @Test
@@ -276,6 +294,7 @@ public abstract class TcProviderTest {
             expThrown = true;
         }
         assertTrue(expThrown);
+        provider.deleteTripleCollection(graphUriRef);
     }
 
     @Test
@@ -291,6 +310,7 @@ public abstract class TcProviderTest {
             expThrown = true;
         }
         assertTrue(expThrown);
+        provider.deleteTripleCollection(graphUriRef);
     }
 
     @Test
@@ -304,6 +324,7 @@ public abstract class TcProviderTest {
 
         assertEquals(1, graph.size());
         assertTrue(graph.contains(t1));
+        provider.deleteTripleCollection(graphUriRef);
     }
 
     @Test
@@ -364,6 +385,7 @@ public abstract class TcProviderTest {
         }
 
         assertTrue(expThrown);
+        provider.deleteTripleCollection(graphUriRef);
     }
 
 //    This tests can not pass, because equals in AbstractGraph is not implemented
@@ -427,6 +449,7 @@ public abstract class TcProviderTest {
         }
 
         assertTrue(expThrown);
+        provider.deleteTripleCollection(name2);
     }
 
 
@@ -437,6 +460,7 @@ public abstract class TcProviderTest {
                 createTestTripleCollection(createTestTriple()));
         TripleCollection tc = provider.getTriples(graphUriRef);
         assertNotNull(tc);
+        provider.deleteTripleCollection(graphUriRef);
     }
 
     @Test
@@ -447,6 +471,7 @@ public abstract class TcProviderTest {
 
         TripleCollection tc = provider.getTriples(graphUriRef);
         assertNotNull(tc);
+        provider.deleteTripleCollection(graphUriRef);
     }
 
     private Triple createTestTriple() {

Modified: clerezza/trunk/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java?rev=1535716&r1=1535715&r2=1535716&view=diff
==============================================================================
--- clerezza/trunk/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java
(original)
+++ clerezza/trunk/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java
Fri Oct 25 12:49:15 2013
@@ -34,6 +34,7 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.locks.Lock;
+import java.util.logging.Level;
 import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -50,12 +51,14 @@ import org.apache.clerezza.rdf.core.acce
 import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
 import org.apache.clerezza.rdf.core.impl.util.PrivilegedMGraphWrapper;
 import org.apache.clerezza.rdf.jena.storage.JenaGraphAdaptor;
+import org.apache.commons.io.FileDeleteStrategy;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Service;
 
 /**
- * A {@link org.apache.clerezza.rdf.core.access.WeightedTcProvider} based on Jena TDB.
+ * A {@link org.apache.clerezza.rdf.core.access.WeightedTcProvider} based on
+ * Jena TDB.
  *
  * @see <a href="http://jena.hpl.hp.com/wiki/TDB/JavaAPI">
  * TDB/JavaAPI</a>
@@ -63,13 +66,14 @@ import org.apache.felix.scr.annotations.
  * @author reto, hasan
  *
  * @scr.component immediate="true"
- * @scr.service interface="org.apache.clerezza.rdf.core.access.WeightedTcProvider"
+ * @scr.service
+ * interface="org.apache.clerezza.rdf.core.access.WeightedTcProvider"
  * @scr.property name="weight" type="Integer" value="105"
  *
  */
-@Component(metatype=true, immediate=true)
+@Component(metatype = true, immediate = true)
 @Service(WeightedTcProvider.class)
-@Property(name="weight", intValue=105)
+@Property(name = "weight", intValue = 105)
 public class TdbTcProvider implements WeightedTcProvider {
 
     static {
@@ -77,35 +81,36 @@ public class TdbTcProvider implements We
         //it is only needed so that on windows the files of a dataset can be deleteds
         SystemTDB.setFileMode(FileMode.direct);
     }
-    
-    @Property(intValue=6, description="Specifies the number of seconds to wait "
-    + "between synchronizations of the TDB datasets to the filesystem")
+
+    @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 = 6;
 
     /**
-     *    directory where all graphs are stored
+     * directory where all graphs are stored
      */
     private static final String DATA_PATH_NAME = "tdb-data/";
     private String dataPathString = DATA_PATH_NAME;
     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>();
-    private Map<File, Lock> dir2Lock =
-            new HashMap<File, Lock>();
+    private Map<File, com.hp.hpl.jena.graph.Graph> dir2JenaGraphMap
+            = new HashMap<File, com.hp.hpl.jena.graph.Graph>();
+    private Map<File, Lock> dir2Lock
+            = new HashMap<File, Lock>();
     private final Map<File, Dataset> dir2Dataset = new HashMap<File, Dataset>();
     private static final Logger log = LoggerFactory.getLogger(TdbTcProvider.class);
     private int weight = 105;
-    
+
     class SyncThread extends Thread {
+
         private boolean stopRequested = false;
 
         @Override
         public void run() {
             while (!stopRequested) {
                 try {
-                    Thread.sleep(syncInterval*1000);
+                    Thread.sleep(syncInterval * 1000);
                 } catch (InterruptedException ex) {
                     interrupt();
                 }
@@ -114,7 +119,7 @@ public class TdbTcProvider implements We
                 }
             }
         }
-        
+
         public void requestStop() {
             stopRequested = true;
         }
@@ -151,7 +156,7 @@ public class TdbTcProvider implements We
         for (com.hp.hpl.jena.graph.Graph jenaGraph : dir2JenaGraphMap.values()) {
             jenaGraph.close();
         }
-        synchronized(dir2Dataset) {
+        synchronized (dir2Dataset) {
             for (Dataset dataset : dir2Dataset.values()) {
                 dataset.close();
             }
@@ -254,23 +259,38 @@ public class TdbTcProvider implements We
         if (tcDir.exists()) {
             dir2JenaGraphMap.get(tcDir).close();
             dir2JenaGraphMap.remove(tcDir);
-            synchronized(dir2Dataset) {
+            synchronized (dir2Dataset) {
                 dir2Dataset.get(tcDir).close();
                 dir2Dataset.remove(tcDir);
             }
             try {
                 delete(tcDir);
             } catch (IOException ex) {
+                for (int i = 0; i < 10; i++) {
+                    try {
+                        System.gc();
+                        delete(tcDir);
+                    } catch (IOException ex1) {
+                        try {
+                            Thread.sleep(10);
+                        } catch (InterruptedException ex2) {
+                            Thread.currentThread().interrupt();
+                        }
+                        continue;
+                    }
+                    return true;
+                }
                 throw new RuntimeException(ex);
             }
             return true;
         }
         return false;
     }
-    
+
     /**
      * Cleans the content of the specified directory recursively.
-     * @param dir  Abstract path denoting the directory to clean.
+     *
+     * @param dir Abstract path denoting the directory to clean.
      */
     private static void cleanDirectory(File dir) throws IOException {
         File[] files = dir.listFiles();
@@ -283,16 +303,17 @@ public class TdbTcProvider implements We
 
     /**
      * Deletes the specified file or directory.
-     * @param file  Abstract path denoting the file or directory to clean.
+     *
+     * @param file Abstract path denoting the file or directory to clean.
      */
     protected static void delete(File file) throws IOException {
         if (file.isDirectory()) {
             cleanDirectory(file);
         }
         //better but only in java 7
-        //Files.delete(file.toPath());
+        //java.nio.file.Files.delete(file.toPath());
         if (!file.delete()) {
-            throw new IOException("couldn't delete "+file.getAbsolutePath());
+            throw new IOException("couldn't delete " + file.getAbsolutePath());
         }
     }
 
@@ -343,7 +364,7 @@ public class TdbTcProvider implements We
         final com.hp.hpl.jena.graph.Graph jenaGraph = model.getGraph();
         dir2JenaGraphMap.put(tcDir, jenaGraph);
         //dataset.
-        synchronized(dir2Dataset) {
+        synchronized (dir2Dataset) {
             dir2Dataset.put(tcDir, dataset);
         }
         return new PrivilegedMGraphWrapper(new JenaGraphAdaptor(jenaGraph));
@@ -363,19 +384,18 @@ public class TdbTcProvider implements We
         }
     }
 
-
     private void loadGraphs() {
         File graphsDir = new File(new File(dataPathString), "graph");
         if (graphsDir.exists()) {
             for (String graphDirName : graphsDir.list()) {
                 try {
                     UriRef uri = new UriRef(URLDecoder.decode(graphDirName, "utf-8"));
-                    log.info("loading: "+graphDirName);
+                    log.info("loading: " + graphDirName);
                     graphMap.put(uri, getGraph(new File(graphsDir, graphDirName)));
                 } catch (UnsupportedEncodingException ex) {
                     throw new RuntimeException("utf-8 not supported", ex);
                 } catch (Exception e) {
-                    log.error("Could not load tdb graph in "+graphDirName, e);
+                    log.error("Could not load tdb graph in " + graphDirName, e);
                 }
             }
         }
@@ -387,7 +407,7 @@ public class TdbTcProvider implements We
             for (String mGraphDirName : mGraphsDir.list()) {
                 try {
                     UriRef uri = new UriRef(URLDecoder.decode(mGraphDirName, "utf-8"));
-                    log.info("loading: "+mGraphDirName);
+                    log.info("loading: " + mGraphDirName);
                     final File tcDir = new File(mGraphsDir, mGraphDirName);
                     final LockableMGraphWrapper lockableMGraph = new LockableMGraphWrapper(getMGraph(tcDir));
                     mGraphMap.put(uri, lockableMGraph);
@@ -395,17 +415,19 @@ public class TdbTcProvider implements We
                 } catch (UnsupportedEncodingException ex) {
                     throw new RuntimeException("utf-8 not supported", ex);
                 } catch (Exception e) {
-                    log.error("Could not load tdb graph in "+mGraphDirName, e);
+                    log.error("Could not load tdb graph in " + mGraphDirName, e);
                 }
             }
         }
     }
-    
+
     public void syncWithFileSystem() {
-        synchronized(dir2Dataset) {
-            for (Map.Entry<File,Dataset> entry : dir2Dataset.entrySet()) {
+        synchronized (dir2Dataset) {
+            for (Map.Entry<File, Dataset> entry : dir2Dataset.entrySet()) {
                 Lock l = dir2Lock.get(entry.getKey());
-                if (l == null) return;
+                if (l == null) {
+                    return;
+                }
                 l.lock();
                 try {
                     TDB.sync(entry.getValue());



Mime
View raw message