use of org.apache.jackrabbit.api.management.DataStoreGarbageCollector 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 org.apache.jackrabbit.api.management.DataStoreGarbageCollector 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 org.apache.jackrabbit.api.management.DataStoreGarbageCollector in project jackrabbit by apache.
the class DataStoreAPITest method testDataStoreGarbageCollection.
/**
* Test data store garbage collection.
*/
public void testDataStoreGarbageCollection() throws RepositoryException {
JackrabbitRepositoryFactory rf = new RepositoryFactoryImpl();
Properties prop = new Properties();
prop.setProperty("org.apache.jackrabbit.repository.home", TEST_DIR);
prop.setProperty("org.apache.jackrabbit.repository.conf", TEST_DIR + "/repository.xml");
JackrabbitRepository rep = (JackrabbitRepository) rf.getRepository(prop);
RepositoryManager rm = rf.getRepositoryManager(rep);
// need to login to start the repository
Session session = rep.login();
DataStoreGarbageCollector gc = rm.createDataStoreGarbageCollector();
try {
gc.mark();
gc.sweep();
} finally {
gc.close();
}
session.logout();
rm.stop();
}
use of org.apache.jackrabbit.api.management.DataStoreGarbageCollector in project jackrabbit by apache.
the class GCConcurrentTest method testConcurrentDelete.
public void testConcurrentDelete() throws Exception {
Node root = testRootNode;
Session session = root.getSession();
final String testNodeName = "testConcurrentDelete";
node(root, testNodeName);
session.save();
DataStoreGarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
gc.setPersistenceManagerScan(false);
gc.setMarkEventListener(new MarkEventListener() {
public void beforeScanning(Node n) throws RepositoryException {
if (n.getName().equals(testNodeName)) {
n.remove();
n.getSession().save();
}
}
});
gc.mark();
gc.close();
}
use of org.apache.jackrabbit.api.management.DataStoreGarbageCollector in project jackrabbit by apache.
the class GCEventListenerTest method doTestEventListener.
private void doTestEventListener(boolean allowPmScan) throws Exception {
Node root = testRootNode;
Session session = root.getSession();
if (root.hasNode(TEST_NODE_NAME)) {
root.getNode(TEST_NODE_NAME).remove();
session.save();
}
Node test = root.addNode(TEST_NODE_NAME);
Random random = new Random();
byte[] data = new byte[10000];
for (int i = 0; i < 10; i++) {
Node n = test.addNode("x" + i);
random.nextBytes(data);
ValueFactory vf = session.getValueFactory();
n.setProperty("data", vf.createBinary(new ByteArrayInputStream(data)));
session.save();
if (i % 2 == 0) {
n.remove();
session.save();
}
}
session.save();
SessionImpl si = (SessionImpl) session;
DataStoreGarbageCollector gc = si.createDataStoreGarbageCollector();
DataStore ds = ((GarbageCollector) gc).getDataStore();
if (ds != null) {
ds.clearInUse();
boolean pmScan = gc.isPersistenceManagerScan();
gc.setPersistenceManagerScan(allowPmScan);
gotNullNode = false;
gotNode = false;
gc.setMarkEventListener(this);
gc.mark();
if (pmScan && allowPmScan) {
assertTrue("PM scan without null Node", gotNullNode);
assertFalse("PM scan, but got a real node", gotNode);
} else {
assertFalse("Not a PM scan - but got a null Node", gotNullNode);
assertTrue("Not a PM scan - without a real node", gotNode);
}
int deleted = gc.sweep();
LOG.debug("Deleted " + deleted);
assertTrue("Should delete at least one item", deleted >= 0);
gc.close();
}
}
Aggregations