use of org.apache.jackrabbit.core.gc.GarbageCollector in project jackrabbit by apache.
the class GCEventListenerTest method doTestEventListener.
private void doTestEventListener(boolean allowPmScan) throws Exception {
Node root = testRootNode;
Session session = root.getSession();
if (root.hasNode(TEST_NODE_NAME)) {
root.getNode(TEST_NODE_NAME).remove();
session.save();
}
Node test = root.addNode(TEST_NODE_NAME);
Random random = new Random();
byte[] data = new byte[10000];
for (int i = 0; i < 10; i++) {
Node n = test.addNode("x" + i);
random.nextBytes(data);
ValueFactory vf = session.getValueFactory();
n.setProperty("data", vf.createBinary(new ByteArrayInputStream(data)));
session.save();
if (i % 2 == 0) {
n.remove();
session.save();
}
}
session.save();
SessionImpl si = (SessionImpl) session;
DataStoreGarbageCollector gc = si.createDataStoreGarbageCollector();
DataStore ds = ((GarbageCollector) gc).getDataStore();
if (ds != null) {
ds.clearInUse();
boolean pmScan = gc.isPersistenceManagerScan();
gc.setPersistenceManagerScan(allowPmScan);
gotNullNode = false;
gotNode = false;
gc.setMarkEventListener(this);
gc.mark();
if (pmScan && allowPmScan) {
assertTrue("PM scan without null Node", gotNullNode);
assertFalse("PM scan, but got a real node", gotNode);
} else {
assertFalse("Not a PM scan - but got a null Node", gotNullNode);
assertTrue("Not a PM scan - without a real node", gotNode);
}
int deleted = gc.sweep();
LOG.debug("Deleted " + deleted);
assertTrue("Should delete at least one item", deleted >= 0);
gc.close();
}
}
use of org.apache.jackrabbit.core.gc.GarbageCollector in project jackrabbit by apache.
the class GCSubtreeMoveTest method test.
public void test() {
setupRepository();
GarbageCollector garbageCollector = setupGarbageCollector();
// To make sure even listener for NODE_ADDED is registered in GC.
garbageCollector.setPersistenceManagerScan(false);
assertEquals(0, getBinaryCount(garbageCollector));
setupNodes();
assertEquals(1, getBinaryCount(garbageCollector));
garbageCollector.getDataStore().clearInUse();
garbageCollector.setMarkEventListener(new MarkEventListener() {
public void beforeScanning(Node node) throws RepositoryException {
String path = node.getPath();
if (path.startsWith("/node")) {
log("Traversing: " + node.getPath());
}
if ("/node1".equals(node.getPath())) {
String from = "/node2/node3";
String to = "/node0/node3";
log("Moving " + from + " -> " + to);
sessionMover.move(from, to);
sessionMover.save();
sleepForFile();
}
}
});
try {
garbageCollector.getDataStore().clearInUse();
garbageCollector.mark();
garbageCollector.stopScan();
sleepForFile();
int numberOfDeleted = garbageCollector.sweep();
log("Number of deleted: " + numberOfDeleted);
// Binary data should still be there.
assertEquals(1, getBinaryCount(garbageCollector));
} catch (RepositoryException e) {
e.printStackTrace();
failWithException(e);
} finally {
garbageCollector.close();
}
}
Aggregations