Search in sources :

Example 1 with MarkEventListener

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();
}
Also used : Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) SessionImpl(org.apache.jackrabbit.core.SessionImpl) MarkEventListener(org.apache.jackrabbit.api.management.MarkEventListener) IOException(java.io.IOException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) DataStoreGarbageCollector(org.apache.jackrabbit.api.management.DataStoreGarbageCollector)

Example 2 with MarkEventListener

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();
}
Also used : Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) SessionImpl(org.apache.jackrabbit.core.SessionImpl) MarkEventListener(org.apache.jackrabbit.api.management.MarkEventListener) Session(javax.jcr.Session) DataStoreGarbageCollector(org.apache.jackrabbit.api.management.DataStoreGarbageCollector)

Example 3 with MarkEventListener

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();
    }
}
Also used : Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) MarkEventListener(org.apache.jackrabbit.api.management.MarkEventListener) GarbageCollector(org.apache.jackrabbit.core.gc.GarbageCollector)

Aggregations

Node (javax.jcr.Node)3 RepositoryException (javax.jcr.RepositoryException)3 MarkEventListener (org.apache.jackrabbit.api.management.MarkEventListener)3 Session (javax.jcr.Session)2 DataStoreGarbageCollector (org.apache.jackrabbit.api.management.DataStoreGarbageCollector)2 SessionImpl (org.apache.jackrabbit.core.SessionImpl)2 IOException (java.io.IOException)1 GarbageCollector (org.apache.jackrabbit.core.gc.GarbageCollector)1