Search in sources :

Example 71 with Session

use of javax.jcr.Session in project jackrabbit by apache.

the class SessionScopedLockTest method testImplicitUnlock.

/**
     * Test locks are released when session logs out
     */
public void testImplicitUnlock() throws RepositoryException, NotExecutableException {
    Session other = getHelper().getReadWriteSession();
    try {
        Node testNode = (Node) other.getItem(testRootNode.getPath());
        Node lockedNode = testNode.addNode(nodeName1, testNodeType);
        other.save();
        assertLockable(lockedNode);
        Lock lock = getLockManager(other).lock(lockedNode.getPath(), isDeep(), isSessionScoped(), getTimeoutHint(), getLockOwner());
        other.logout();
        assertFalse(lock.isLive());
    } finally {
        if (other.isLive()) {
            other.logout();
        }
    }
}
Also used : Node(javax.jcr.Node) Session(javax.jcr.Session) Lock(javax.jcr.lock.Lock)

Example 72 with Session

use of javax.jcr.Session in project jackrabbit by apache.

the class SessionScopedLockTest method testImplicitUnlock2.

/**
     * Test locks are released when session logs out
     */
public void testImplicitUnlock2() throws RepositoryException, NotExecutableException {
    Session other = getHelper().getReadWriteSession();
    try {
        Node testNode = (Node) other.getItem(testRootNode.getPath());
        Node lockedNode = testNode.addNode(nodeName1, testNodeType);
        other.save();
        assertLockable(lockedNode);
        LockManager lMgr = getLockManager(other);
        Lock lock = lMgr.lock(lockedNode.getPath(), isDeep(), isSessionScoped(), getTimeoutHint(), getLockOwner());
        // access the locked noded added by another session
        testRootNode.refresh(false);
        Node n = (Node) superuser.getItem(lockedNode.getPath());
        // remove lock implicit by logout lock-holding session
        other.logout();
        // check if superuser session is properly informed about the unlock
        assertFalse(n.isLocked());
        assertFalse(n.holdsLock());
        try {
            n.getLock();
            fail("Upon logout of the session a session-scoped lock must be gone.");
        } catch (LockException e) {
        // ok
        }
    } finally {
        if (other.isLive()) {
            other.logout();
        }
    }
}
Also used : LockManager(javax.jcr.lock.LockManager) LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) Session(javax.jcr.Session) Lock(javax.jcr.lock.Lock)

Example 73 with Session

use of javax.jcr.Session in project jackrabbit-oak by apache.

the class AbstractTest method tearDown.

/**
     * Cleans up after this performance benchmark.
     *
     * @throws Exception if the benchmark can not be cleaned up
     */
public void tearDown() throws Exception {
    issueHaltChildThreads();
    this.running = false;
    for (Thread thread : threads) {
        thread.join();
    }
    if (profiler != null) {
        System.out.println(profiler.stopCollecting().getTop(5));
        profiler = null;
    }
    afterSuite();
    for (Session session : sessions) {
        if (session.isLive()) {
            session.logout();
        }
    }
    this.threads = null;
    this.sessions = null;
    this.credentials = null;
    this.repository = null;
}
Also used : Session(javax.jcr.Session)

Example 74 with Session

use of javax.jcr.Session in project jackrabbit-oak by apache.

the class AddMembersTest method afterSuite.

@Override
public void afterSuite() throws Exception {
    Session s = loginAdministrative();
    try {
        Authorizable authorizable = ((JackrabbitSession) s).getUserManager().getAuthorizable(GROUP + "0");
        if (authorizable != null) {
            Node n = s.getNode(Text.getRelativeParent(authorizable.getPath(), 1));
            n.remove();
        }
        if (!ImportBehavior.NAME_BESTEFFORT.equals(importBehavior)) {
            authorizable = ((JackrabbitSession) s).getUserManager().getAuthorizable(USER + "0");
            if (authorizable != null) {
                Node n = s.getNode(Text.getRelativeParent(authorizable.getPath(), 1));
                n.remove();
            }
        }
        s.save();
    } finally {
        s.logout();
    }
}
Also used : Node(javax.jcr.Node) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 75 with Session

use of javax.jcr.Session in project jackrabbit-oak by apache.

the class BundlingNodeTest method registerAssetNodeType.

private void registerAssetNodeType() throws ParseException, RepositoryException, IOException {
    Session session = loginWriter();
    CndImporter.registerNodeTypes(new StringReader(ASSET_NODE_TYPE_DEFN), session);
    session.logout();
}
Also used : StringReader(java.io.StringReader) Session(javax.jcr.Session)

Aggregations

Session (javax.jcr.Session)1177 Node (javax.jcr.Node)645 Test (org.junit.Test)359 RepositoryException (javax.jcr.RepositoryException)206 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)158 SimpleCredentials (javax.jcr.SimpleCredentials)86 Property (javax.jcr.Property)78 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)77 Privilege (javax.jcr.security.Privilege)76 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)64 Value (javax.jcr.Value)63 Query (javax.jcr.query.Query)58 NodeIterator (javax.jcr.NodeIterator)55 QueryManager (javax.jcr.query.QueryManager)53 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)50 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)48 AccessControlManager (javax.jcr.security.AccessControlManager)47 HashMap (java.util.HashMap)44 UserManager (org.apache.jackrabbit.api.security.user.UserManager)43 ArrayList (java.util.ArrayList)41