Search in sources :

Example 86 with Session

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

the class GarbageCollectorTest method testConcurrentGC.

public void testConcurrentGC() throws Exception {
    Node root = testRootNode;
    Session session = root.getSession();
    final SynchronousChannel sync = new SynchronousChannel();
    final Node node = root.addNode("slowBlob");
    final int blobLength = 1000;
    final ValueFactory vf = session.getValueFactory();
    new Thread() {

        public void run() {
            try {
                node.setProperty("slowBlob", vf.createBinary(new InputStream() {

                    int pos;

                    public int read() throws IOException {
                        pos++;
                        if (pos < blobLength) {
                            return pos % 80 == 0 ? '\n' : '.';
                        } else if (pos == blobLength) {
                            try {
                                sync.put("x");
                                // deleted
                                sync.take();
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            return 'x';
                        }
                        return -1;
                    }
                }));
                node.getSession().save();
                sync.put("saved");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }.start();
    assertEquals("x", sync.take());
    DataStoreGarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
    gc.setPersistenceManagerScan(false);
    gc.mark();
    gc.sweep();
    sync.put("deleted");
    assertEquals("saved", sync.take());
    InputStream in = node.getProperty("slowBlob").getBinary().getStream();
    for (int pos = 1; pos < blobLength; pos++) {
        int expected = pos % 80 == 0 ? '\n' : '.';
        assertEquals(expected, in.read());
    }
    assertEquals('x', in.read());
    in.close();
    gc.close();
}
Also used : InputStream(java.io.InputStream) Node(javax.jcr.Node) ValueFactory(javax.jcr.ValueFactory) IOException(java.io.IOException) SessionImpl(org.apache.jackrabbit.core.SessionImpl) SynchronousChannel(EDU.oswego.cs.dl.util.concurrent.SynchronousChannel) IOException(java.io.IOException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) DataStoreGarbageCollector(org.apache.jackrabbit.api.management.DataStoreGarbageCollector)

Example 87 with Session

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

the class GarbageCollectorTest method beforeScanning.

public void beforeScanning(Node n) throws RepositoryException {
    if (n != null && n.getPath().equals("/testroot/node2")) {
        Session session = n.getSession();
        list(session.getRootNode());
        session.move("/testroot/node2/nodeWithBlob", "/testroot/node1/nodeWithBlob");
        session.save();
        LOG.debug("moved /testroot/node2/nodeWithBlob to /testroot/node1");
    }
}
Also used : Session(javax.jcr.Session)

Example 88 with Session

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

the class GarbageCollectorTest method testSimultaneousRunGC.

/**
     *  Test to validate that two  GC cannot run simultaneously. One 
     *  exits throwing exception.
     */
public void testSimultaneousRunGC() throws Exception {
    Node root = testRootNode;
    Session session = root.getSession();
    GCThread gct1 = new GCThread(session);
    GCThread gct2 = new GCThread(session);
    Thread gcThread1 = new Thread(gct1, "Datastore Garbage Collector 1");
    Thread gcThread2 = new Thread(gct2, "Datastore Garbage Collector 2");
    // run simultaneous GC
    gcThread1.start();
    gcThread2.start();
    Thread.sleep(100);
    gct1.setStop(true);
    gct2.setStop(true);
    // allow them to complete
    gcThread1.join();
    gcThread2.join();
    // only one should throw error
    int count = (gct1.getException() == null ? 0 : 1) + (gct2.getException() == null ? 0 : 1);
    if (count == 0) {
        fail("None of the GCs threw an exception");
    } else {
        assertEquals("Only one gc should throw an exception ", 1, count);
    }
}
Also used : Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 89 with Session

use of javax.jcr.Session 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 90 with Session

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

the class ExportImportTest method doTestExportImportLargeText.

private void doTestExportImportLargeText(char[] chars) throws RepositoryException {
    Session session = getHelper().getReadWriteSession();
    try {
        Node root = session.getRootNode();
        clean(root);
        Node test = root.addNode("testText");
        session.save();
        String s = new String(chars);
        test.setProperty("text", s);
        session.save();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        session.exportSystemView("/testText", out, false, false);
        byte[] output = out.toByteArray();
        Node test2 = root.addNode("testText2");
        Node test3 = root.addNode("testText3");
        session.save();
        session.importXML("/testText2", new ByteArrayInputStream(output), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
        session.save();
        session.getWorkspace().importXML("/testText3", new ByteArrayInputStream(output), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
        test2 = root.getNode("testText2");
        test2 = test2.getNode("testText");
        test3 = root.getNode("testText3");
        test3 = test3.getNode("testText");
        String s2 = test2.getProperty("text").getString();
        String s3 = test3.getProperty("text").getString();
        assertEquals(s.length(), s2.length());
        assertEquals(s.length(), s3.length());
        assertEquals(s, s2);
        assertEquals(s, s3);
        clean(root);
    } catch (Exception e) {
        e.printStackTrace();
        assertFalse(e.getMessage(), true);
    } finally {
        session.logout();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Node(javax.jcr.Node) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) 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