use of org.apache.jackrabbit.api.management.MarkEventListener in project jackrabbit by apache.
the class GarbageCollectorTest method testCloseSessionWhileRunningGc.
public void testCloseSessionWhileRunningGc() throws Exception {
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;
public void beforeScanning(Node n) throws RepositoryException {
closeTest();
}
private void closeTest() {
if (closed) {
ex[0] = new Exception("Scanning after the session is closed");
}
closed = true;
session.logout();
}
});
try {
gc.mark();
fail("Exception 'session has been closed' expected");
} catch (RepositoryException e) {
LOG.debug("Expected exception caught: " + e.getMessage());
}
if (ex[0] != null) {
throw ex[0];
}
gc.close();
}
use of org.apache.jackrabbit.api.management.MarkEventListener in project jackrabbit by apache.
the class GCConcurrentTest method testConcurrentDelete.
public void testConcurrentDelete() throws Exception {
Node root = testRootNode;
Session session = root.getSession();
final String testNodeName = "testConcurrentDelete";
node(root, testNodeName);
session.save();
DataStoreGarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
gc.setPersistenceManagerScan(false);
gc.setMarkEventListener(new MarkEventListener() {
public void beforeScanning(Node n) throws RepositoryException {
if (n.getName().equals(testNodeName)) {
n.remove();
n.getSession().save();
}
}
});
gc.mark();
gc.close();
}
use of org.apache.jackrabbit.api.management.MarkEventListener 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