Search in sources :

Example 86 with Repository

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

the class RepositoryManager method registerRepository.

private ServiceRegistration registerRepository(BundleContext bundleContext) {
    Oak oak = new Oak(store).with(new InitialContent()).with(new VersionHook()).with(JcrConflictHandler.createJcrConflictHandler()).with(whiteboard).with(securityProvider).with(editorProvider).with(indexEditorProvider).with(indexProvider).withFailOnMissingIndexProvider().withAsyncIndexing();
    for (RepositoryInitializer initializer : initializers.getServices()) {
        oak.with(initializer);
    }
    if (commitRateLimiter != null) {
        oak.with(commitRateLimiter);
    }
    repository = new OsgiRepository(oak.createContentRepository(), whiteboard, securityProvider, observationQueueLength, commitRateLimiter, fastQueryResultSize);
    return bundleContext.registerService(Repository.class.getName(), repository, new Properties());
}
Also used : InitialContent(org.apache.jackrabbit.oak.InitialContent) Repository(javax.jcr.Repository) Oak(org.apache.jackrabbit.oak.Oak) VersionHook(org.apache.jackrabbit.oak.plugins.version.VersionHook) RepositoryInitializer(org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer) Properties(java.util.Properties)

Example 87 with Repository

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

the class AtomicCounterClusterIT method increments.

@Test
public void increments() throws Exception {
    setUpCluster(this.getClass(), mks, repos, NOT_PROVIDED);
    assertEquals("repositories and executors should match", repos.size(), executors.size());
    final String counterPath;
    final Random rnd = new Random(14);
    final AtomicLong expected = new AtomicLong(0);
    final Map<String, Exception> exceptions = Collections.synchronizedMap(new HashMap<String, Exception>());
    // setting-up the repo state
    Repository repo = repos.get(0);
    Session session = repo.login(ADMIN);
    Node counter;
    try {
        counter = session.getRootNode().addNode("counter");
        counter.addMixin(MIX_ATOMIC_COUNTER);
        session.save();
        counterPath = counter.getPath();
    } finally {
        session.logout();
    }
    // allow the cluster to align
    alignCluster(mks);
    // asserting the initial state
    assertFalse("Path to the counter node should be set", Strings.isNullOrEmpty(counterPath));
    for (Repository r : repos) {
        try {
            session = r.login(ADMIN);
            counter = session.getNode(counterPath);
            assertEquals("Nothing should have touched the `expected`", 0, expected.get());
            assertEquals("Wrong initial counter", expected.get(), counter.getProperty(PROP_COUNTER).getLong());
        } finally {
            session.logout();
        }
    }
    // number of threads per cluster node
    final int numIncrements = Integer.getInteger("oak.test.it.atomiccounter.threads", 100);
    LOG.debug("pushing {} increments per each of the {} cluster nodes for a total of {} concurrent updates", numIncrements, repos.size(), numIncrements * repos.size());
    // for each cluster node, `numIncrements` sessions pushing random increments
    long start = LOG_PERF.start("Firing the threads");
    List<ListenableFutureTask<Void>> tasks = Lists.newArrayList();
    for (Repository rep : repos) {
        final Repository r = rep;
        for (int i = 0; i < numIncrements; i++) {
            ListenableFutureTask<Void> task = ListenableFutureTask.create(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    Session s = r.login(ADMIN);
                    try {
                        try {
                            Node n = s.getNode(counterPath);
                            int increment = rnd.nextInt(10) + 1;
                            n.setProperty(PROP_INCREMENT, increment);
                            expected.addAndGet(increment);
                            s.save();
                        } finally {
                            s.logout();
                        }
                    } catch (Exception e) {
                        exceptions.put(Thread.currentThread().getName(), e);
                    }
                    return null;
                }
            });
            new Thread(task).start();
            tasks.add(task);
        }
    }
    LOG_PERF.end(start, -1, "Firing threads completed", "");
    Futures.allAsList(tasks).get();
    LOG_PERF.end(start, -1, "Futures completed", "");
    waitForTaskCompletion();
    LOG_PERF.end(start, -1, "All tasks completed", "");
    // let the time for the async process to kick in and run.
    Thread.sleep(5000);
    raiseExceptions(exceptions, LOG);
    // assert the final situation
    for (int i = 0; i < repos.size(); i++) {
        Repository r = repos.get(i);
        try {
            session = r.login(ADMIN);
            counter = session.getNode(counterPath);
            LOG.debug("Cluster node: {}, actual counter: {}, expected counter: {}", i + 1, expected.get(), counter.getProperty(PROP_COUNTER).getLong());
            assertEquals("Wrong counter on node " + (i + 1), expected.get(), counter.getProperty(PROP_COUNTER).getLong());
        } finally {
            session.logout();
        }
    }
}
Also used : Node(javax.jcr.Node) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) Repository(javax.jcr.Repository) Random(java.util.Random) ListenableFutureTask(com.google.common.util.concurrent.ListenableFutureTask) Session(javax.jcr.Session) Test(org.junit.Test)

Example 88 with Repository

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

the class ConcurrentAddNodesClusterIT method initRepository.

private static void initRepository() throws Exception {
    MongoConnection con = createConnection();
    DocumentMK mk = new DocumentMK.Builder().setMongoDB(con.getDB()).setClusterId(1).open();
    Repository repository = new Jcr(mk.getNodeStore()).createRepository();
    Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
    session.logout();
    dispose(repository);
    // closes connection as well
    mk.dispose();
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Repository(javax.jcr.Repository) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection) Session(javax.jcr.Session)

Example 89 with Repository

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

the class DocumentClusterIT method initRepository.

/**
     * initialise the repository
     * 
     * @param clazz the current class. Used for logging. Cannot be null.
     * @param repos list to which add the created repository. Cannot be null.
     * @param mks list to which add the created MK. Cannot be null.
     * @param clusterId the cluster ID to use. Must be greater than 0.
     * @param asyncDelay the async delay to set. For default use {@link #NOT_PROVIDED}
     * @throws Exception
     */
protected void initRepository(@Nonnull final Class<?> clazz, @Nonnull final List<Repository> repos, @Nonnull final List<DocumentMK> mks, final int clusterId, final int asyncDelay) throws Exception {
    DocumentMK.Builder builder = new DocumentMK.Builder();
    builder.setMongoDB(createConnection(checkNotNull(clazz)).getDB());
    if (asyncDelay != NOT_PROVIDED) {
        builder.setAsyncDelay(asyncDelay);
    }
    builder.setClusterId(clusterId);
    DocumentMK mk = builder.open();
    Jcr j = getJcr(mk.getNodeStore());
    Set<IndexEditorProvider> ieps = additionalIndexEditorProviders();
    if (ieps != null) {
        for (IndexEditorProvider p : ieps) {
            j = j.with(p);
        }
    }
    if (isAsyncIndexing()) {
        j = j.withAsyncIndexing();
    }
    Repository repository = j.createRepository();
    checkNotNull(repos).add(repository);
    checkNotNull(mks).add(mk);
}
Also used : Repository(javax.jcr.Repository) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) IndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider)

Example 90 with Repository

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

the class DocumentClusterIT method before.

@Before
public void before() throws Exception {
    dropDB(this.getClass());
    List<Repository> rs = new ArrayList<Repository>();
    List<DocumentMK> ds = new ArrayList<DocumentMK>();
    initRepository(this.getClass(), rs, ds, 1, NOT_PROVIDED);
    Repository repository = rs.get(0);
    DocumentMK mk = ds.get(0);
    Session session = repository.login(ADMIN);
    session.logout();
    dispose(repository);
    // closes connection as well
    mk.dispose();
}
Also used : Repository(javax.jcr.Repository) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) ArrayList(java.util.ArrayList) Session(javax.jcr.Session) Before(org.junit.Before)

Aggregations

Repository (javax.jcr.Repository)107 Session (javax.jcr.Session)31 RepositoryException (javax.jcr.RepositoryException)26 SimpleCredentials (javax.jcr.SimpleCredentials)15 Test (org.junit.Test)13 HashMap (java.util.HashMap)12 Node (javax.jcr.Node)12 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)10 SlingRepository (org.apache.sling.jcr.api.SlingRepository)10 JackrabbitRepository (org.apache.jackrabbit.api.JackrabbitRepository)9 Oak (org.apache.jackrabbit.oak.Oak)7 Jcr (org.apache.jackrabbit.oak.jcr.Jcr)7 IOException (java.io.IOException)6 Map (java.util.Map)6 InitialContext (javax.naming.InitialContext)6 NamingException (javax.naming.NamingException)6 ServletContext (javax.servlet.ServletContext)5 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)5 File (java.io.File)4 OutputStreamWriter (java.io.OutputStreamWriter)4