use of javax.jcr.Session in project jackrabbit-oak by apache.
the class ConcurrentReadTest method beforeSuite.
@Override
public void beforeSuite() throws Exception {
Session session = loginWriter();
Node root = session.getRootNode().addNode(ROOT_NODE_NAME, "nt:unstructured");
for (int i = 0; i < NODE_COUNT; i++) {
Node node = root.addNode("node" + i, "nt:unstructured");
for (int j = 0; j < NODE_COUNT; j++) {
node.addNode("node" + j, "nt:unstructured");
}
session.save();
}
if (foregroundIsReader) {
foregroundTask = new Reader();
} else {
foregroundTask = new Writer();
}
for (int i = 0; i < backgroundReaderCount; i++) {
addBackgroundJob(new Reader());
}
for (int i = 0; i < backgroundWriterCount; i++) {
addBackgroundJob(new Writer());
}
}
use of javax.jcr.Session in project jackrabbit by apache.
the class GarbageCollector method scanNodes.
private void scanNodes(SessionImpl session) throws RepositoryException {
// add a listener to get 'moved' nodes
Session clonedSession = session.createSession(session.getWorkspace().getName());
listeners.add(new Listener(this, clonedSession));
// adding a link to a BLOB updates the modified date
// reading usually doesn't, but when scanning, it does
recurse(session.getRootNode(), sleepBetweenNodes);
}
use of javax.jcr.Session in project jackrabbit by apache.
the class ConcurrentQueriesWithUpdatesTest method testQueriesWithUpdates.
public void testQueriesWithUpdates() throws Exception {
final List<Exception> exceptions = Collections.synchronizedList(new ArrayList<Exception>());
final AtomicBoolean running = new AtomicBoolean(true);
// track executed queries and do updates at most at the given rate
final BlockingQueue<Object> queryExecuted = new LinkedBlockingQueue<Object>();
Thread queries = new Thread(new Runnable() {
public void run() {
try {
runTask(new Task() {
public void execute(Session session, Node test) throws RepositoryException {
QueryManager qm = session.getWorkspace().getQueryManager();
while (running.get()) {
Query q = qm.createQuery(testPath + "//element(*, nt:unstructured) order by @jcr:score descending", Query.XPATH);
NodeIterator nodes = q.execute().getNodes();
assertEquals("wrong result set size", numNodes, nodes.getSize());
queryExecuted.offer(new Object());
}
}
}, 5, testRootNode.getPath());
} catch (RepositoryException e) {
exceptions.add(e);
}
}
});
queries.start();
Thread update = new Thread(new Runnable() {
public void run() {
try {
runTask(new Task() {
public void execute(Session session, Node test) throws RepositoryException {
Random rand = new Random();
QueryManager qm = session.getWorkspace().getQueryManager();
for (int i = 0; i < NUM_UPDATES; i++) {
try {
// wait at most 10 seconds
queryExecuted.poll(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
// ignore
}
Query q = qm.createQuery(testPath + "//node" + rand.nextInt(numNodes) + " order by @jcr:score descending", Query.XPATH);
NodeIterator nodes = q.execute().getNodes();
if (nodes.hasNext()) {
Node n = nodes.nextNode();
n.setProperty("foo", "bar");
session.save();
}
}
}
}, 1, testRootNode.getPath());
} catch (RepositoryException e) {
exceptions.add(e);
}
}
});
update.start();
update.join();
running.set(false);
queries.join();
}
use of javax.jcr.Session in project jackrabbit by apache.
the class ConcurrentQueryTest method testConcurrentQueryWithDeletes.
/**
* Deletes 1000 nodes in transactions of 5 nodes while
* other threads query the workspace. Query results must always return
* a consistent view of the workspace, that is:<br/>
* <code>result.numNodes % 5 == 0</code>
*/
public void testConcurrentQueryWithDeletes() throws Exception {
// create 1000 nodes
for (int i = 0; i < 20; i++) {
Node n = testRootNode.addNode("node" + i);
for (int j = 0; j < 10; j++) {
Node n1 = n.addNode("node" + j);
for (int k = 0; k < 5; k++) {
n1.addNode("node" + k).setProperty("testprop", "foo");
}
}
testRootNode.save();
}
final List<Exception> exceptions = Collections.synchronizedList(new ArrayList<Exception>());
List<QueryWorker> readers = new ArrayList<QueryWorker>();
String query = "/jcr:root" + testRoot + "//*[@testprop = 'foo']";
for (Session s : readSessions) {
readers.add(new QueryWorker(s, query, exceptions, log));
}
Thread writer = new Thread() {
public void run() {
try {
for (int i = 0; i < 20; i++) {
Node n = testRootNode.getNode("node" + i);
for (int j = 0; j < 10; j++) {
Node n1 = n.getNode("node" + j);
for (int k = 0; k < 5; k++) {
n1.getNode("node" + k).remove();
}
testRootNode.save();
}
}
} catch (Exception e) {
exceptions.add(e);
}
}
};
// start the threads
writer.start();
for (Thread t : readers) {
t.start();
}
// wait for writer thread to finish its work
writer.join();
// request readers to finish
for (QueryWorker t : readers) {
t.finish();
t.join();
}
// fail in case of exceptions
if (!exceptions.isEmpty()) {
fail(exceptions.get(0).toString());
}
}
use of javax.jcr.Session in project jackrabbit by apache.
the class ConcurrentQueryTest method tearDown.
/**
* Logs out the sessions acquired in setUp().
*/
protected void tearDown() throws Exception {
super.tearDown();
for (Session s : readSessions) {
s.logout();
}
readSessions.clear();
}
Aggregations