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());
}
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();
}
}
}
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();
}
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);
}
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();
}
Aggregations