jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1355022 - /jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GarbageCollectorTest.java
Date Thu, 28 Jun 2012 14:26:08 GMT
Author: thomasm
Date: Thu Jun 28 14:26:07 2012
New Revision: 1355022

URL: http://svn.apache.org/viewvc?rev=1355022&view=rev
Log:
JCR-3363 DataStore garbage collection: test case GarbageCollectorTest.testGC() is too lenient

Modified:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GarbageCollectorTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GarbageCollectorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GarbageCollectorTest.java?rev=1355022&r1=1355021&r2=1355022&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GarbageCollectorTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/GarbageCollectorTest.java
Thu Jun 28 14:26:07 2012
@@ -27,6 +27,7 @@ import EDU.oswego.cs.dl.util.concurrent.
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Iterator;
+import javax.jcr.Binary;
 import javax.jcr.Credentials;
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
@@ -46,6 +47,7 @@ public class GarbageCollectorTest extend
         final Session session = getHelper().getReadWriteSession();
 
         final DataStoreGarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
+        gc.setPersistenceManagerScan(false);
         final Exception[] ex = new Exception[1];
         gc.setMarkEventListener(new MarkEventListener() {
             boolean closed;
@@ -114,6 +116,7 @@ public class GarbageCollectorTest extend
         }.start();
         assertEquals("x", sync.take());
         DataStoreGarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
+        gc.setPersistenceManagerScan(false);
         gc.mark();
         gc.sweep();
         sync.put("deleted");
@@ -137,9 +140,11 @@ public class GarbageCollectorTest extend
 
         root.addNode("node1");
         Node node2 = root.addNode("node2");
-        Node n = node2.addNode("nodeWithBlob");
+        Node n = node2.addNode("nodeWithBlob").addNode("sub");
         ValueFactory vf = session.getValueFactory();
-        n.setProperty("test", vf.createBinary(new RandomInputStream(10, 1000)));
+        Binary b = vf.createBinary(new RandomInputStream(20, 1000));
+        n.setProperty("test", b);
+        session.save();
         n = node2.addNode("nodeWithTemporaryBlob");
         n.setProperty("test", vf.createBinary(new RandomInputStream(11, 1000)));
         session.save();
@@ -148,6 +153,9 @@ public class GarbageCollectorTest extend
         session.save();
 
         GarbageCollector gc = ((SessionImpl)session).createDataStoreGarbageCollector();
+        gc.getDataStore().clearInUse();
+        gc.setPersistenceManagerScan(false);
+        gc.setMarkEventListener(this);
 
         if (gc.getDataStore() instanceof FileDataStore) {
             // make sure the file is old (access time resolution is 2 seconds)
@@ -158,13 +166,19 @@ public class GarbageCollectorTest extend
         gc.mark();
         int count = listIdentifiers(gc);
         LOG.debug("stop scanning; currently " + count + " identifiers");
-        gc.stopScan();
         LOG.debug("deleting...");
         gc.getDataStore().clearInUse();
         assertTrue(gc.sweep() > 0);
         int count2 = listIdentifiers(gc);
         assertEquals(count - 1, count2);
 
+        // verify the node was moved, and that the binary is still there
+        n = root.getNode("node1").getNode("nodeWithBlob").getNode("sub");
+        b = n.getProperty("test").getValue().getBinary();
+        InputStream in = b.getStream();
+        InputStream in2 = new RandomInputStream(20, 1000);
+        verifyInputStream(in, in2);
+
         deleteMyNodes();
 
         gc.close();
@@ -173,6 +187,8 @@ public class GarbageCollectorTest extend
     private void runGC(Session session, boolean all) throws Exception {
         GarbageCollector gc = ((SessionImpl)session).createDataStoreGarbageCollector();
         gc.setMarkEventListener(this);
+        gc.setPersistenceManagerScan(false);
+
         if (gc.getDataStore() instanceof FileDataStore) {
             // make sure the file is old (access time resolution is 2 seconds)
             Thread.sleep(2000);
@@ -219,6 +235,14 @@ public class GarbageCollectorTest extend
 
         InputStream in = n.getProperty("test").getBinary().getStream();
         InputStream in2 = new RandomInputStream(10, 1000);
+        verifyInputStream(in, in2);
+
+        deleteMyNodes();
+
+        s2.logout();
+    }
+
+    private void verifyInputStream(InputStream in, InputStream in2) throws IOException {
         while (true) {
             int a = in.read();
             int b = in2.read();
@@ -228,9 +252,6 @@ public class GarbageCollectorTest extend
             }
         }
 
-        deleteMyNodes();
-
-        s2.logout();
     }
 
     public void afterScanning(Node n) throws RepositoryException {



Mime
View raw message