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