Search in sources :

Example 26 with ContentRepository

use of org.apache.jackrabbit.oak.api.ContentRepository in project jackrabbit-oak by apache.

the class ThreeWayConflictHandlerTest method deleteChangedProperty.

@Test
public void deleteChangedProperty() throws Exception {
    AtomicBoolean called = new AtomicBoolean(false);
    ThreeWayConflictHandler handler = new ErrorThreeWayConflictHandler() {

        @Override
        public Resolution deleteChangedProperty(NodeBuilder parent, PropertyState theirs, PropertyState base) {
            called.set(true);
            assertEquals("theirs", theirs.getValue(STRING));
            assertEquals("base", base.getValue(STRING));
            return Resolution.IGNORED;
        }
    };
    ContentRepository repo = newRepo(handler);
    Root root = login(repo);
    setup(root);
    Root ourRoot = login(repo);
    Root theirRoot = login(repo);
    theirRoot.getTree("/c").setProperty("p", "theirs");
    ourRoot.getTree("/c").removeProperty("p");
    theirRoot.commit();
    ourRoot.commit();
    assertTrue(called.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ThreeWayConflictHandler(org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler) Root(org.apache.jackrabbit.oak.api.Root) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 27 with ContentRepository

use of org.apache.jackrabbit.oak.api.ContentRepository in project jackrabbit-oak by apache.

the class OakTest method checkExecutorShutdown.

@Test
public void checkExecutorShutdown() throws Exception {
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
        }
    };
    Oak oak = new Oak().with(new OpenSecurityProvider());
    ContentRepository repo = oak.createContentRepository();
    WhiteboardUtils.scheduleWithFixedDelay(oak.getWhiteboard(), runnable, 1);
    ((Closeable) repo).close();
    try {
        WhiteboardUtils.scheduleWithFixedDelay(oak.getWhiteboard(), runnable, 1);
        fail("Executor should have rejected the task");
    } catch (RejectedExecutionException ignore) {
    }
    // Externally passed executor should not be shutdown upon repository close
    ScheduledExecutorService externalExecutor = Executors.newSingleThreadScheduledExecutor();
    Oak oak2 = new Oak().with(new OpenSecurityProvider()).with(externalExecutor);
    ContentRepository repo2 = oak2.createContentRepository();
    WhiteboardUtils.scheduleWithFixedDelay(oak2.getWhiteboard(), runnable, 1);
    ((Closeable) repo2).close();
    WhiteboardUtils.scheduleWithFixedDelay(oak2.getWhiteboard(), runnable, 1);
    externalExecutor.shutdown();
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Closeable(java.io.Closeable) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Test(org.junit.Test)

Example 28 with ContentRepository

use of org.apache.jackrabbit.oak.api.ContentRepository in project jackrabbit-oak by apache.

the class HttpServer method addServlets.

private void addServlets(Oak oak, String path) {
    Jcr jcr = new Jcr(oak);
    // 1 - OakServer
    ContentRepository repository = jcr.createContentRepository();
    ServletHolder holder = new ServletHolder(new OakServlet(repository));
    context.addServlet(holder, path + "/*");
    // 2 - Webdav Server on JCR repository
    final Repository jcrRepository = jcr.createRepository();
    @SuppressWarnings("serial") ServletHolder webdav = new ServletHolder(new SimpleWebdavServlet() {

        @Override
        public Repository getRepository() {
            return jcrRepository;
        }
    });
    webdav.setInitParameter(SimpleWebdavServlet.INIT_PARAM_RESOURCE_PATH_PREFIX, path + "/webdav");
    webdav.setInitParameter(AbstractWebdavServlet.INIT_PARAM_AUTHENTICATE_HEADER, "Basic realm=\"Oak\"");
    context.addServlet(webdav, path + "/webdav/*");
    // 3 - JCR Remoting Server
    @SuppressWarnings("serial") ServletHolder jcrremote = new ServletHolder(new JcrRemotingServlet() {

        @Override
        protected Repository getRepository() {
            return jcrRepository;
        }
    });
    jcrremote.setInitParameter(JCRWebdavServerServlet.INIT_PARAM_RESOURCE_PATH_PREFIX, path + "/jcrremote");
    jcrremote.setInitParameter(AbstractWebdavServlet.INIT_PARAM_AUTHENTICATE_HEADER, "Basic realm=\"Oak\"");
    context.addServlet(jcrremote, path + "/jcrremote/*");
}
Also used : Repository(javax.jcr.Repository) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) SimpleWebdavServlet(org.apache.jackrabbit.webdav.simple.SimpleWebdavServlet) Jcr(org.apache.jackrabbit.oak.jcr.Jcr) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) OakServlet(org.apache.jackrabbit.oak.http.OakServlet) JcrRemotingServlet(org.apache.jackrabbit.server.remoting.davex.JcrRemotingServlet)

Aggregations

ContentRepository (org.apache.jackrabbit.oak.api.ContentRepository)28 Test (org.junit.Test)23 Root (org.apache.jackrabbit.oak.api.Root)15 OpenSecurityProvider (org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider)12 Oak (org.apache.jackrabbit.oak.Oak)9 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 ThreeWayConflictHandler (org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler)8 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)6 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)6 Closeable (java.io.Closeable)5 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)5 InitialContent (org.apache.jackrabbit.oak.InitialContent)5 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)4 Tree (org.apache.jackrabbit.oak.api.Tree)3 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)3 TypeEditorProvider (org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider)3 HashMap (java.util.HashMap)2 Credentials (javax.jcr.Credentials)2 SimpleCredentials (javax.jcr.SimpleCredentials)2