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