use of javax.jcr.ValueFactory in project jackrabbit by apache.
the class ItemSequenceTest method testSingletonPropertySequence.
public void testSingletonPropertySequence() throws RepositoryException {
Comparator<String> order = Rank.<String>comparableComparator();
TreeManager treeManager = new BTreeManager(testNode, 2, 4, order, true);
PropertySequence properties = ItemSequence.createPropertySequence(treeManager, errorHandler);
ValueFactory vFactory = testNode.getSession().getValueFactory();
properties.addProperty("key", vFactory.createValue("key_"));
assertTrue(properties.hasItem("key"));
Iterator<Property> propertyIt = properties.iterator();
assertTrue(propertyIt.hasNext());
assertEquals("key", propertyIt.next().getName());
assertFalse(propertyIt.hasNext());
properties.removeProperty("key");
assertEmpty(properties);
}
use of javax.jcr.ValueFactory 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.ValueFactory in project jackrabbit by apache.
the class GCConcurrentTest method testGC.
public void testGC() throws Exception {
Node root = testRootNode;
Session session = root.getSession();
GCThread gc = new GCThread(session);
Thread gcThread = new Thread(gc, "Datastore Garbage Collector");
int len = 10 * getTestScale();
boolean started = false;
for (int i = 0; i < len; i++) {
if (!started && i > 5 + len / 100) {
started = true;
gcThread.start();
}
Node n = node(root, "test" + i);
ValueFactory vf = session.getValueFactory();
n.setProperty("data", vf.createBinary(randomInputStream(i)));
session.save();
LOG.debug("saved: " + i);
}
Thread.sleep(10);
for (int i = 0; i < len; i++) {
Node n = root.getNode("test" + i);
Property p = n.getProperty("data");
InputStream in = p.getBinary().getStream();
InputStream expected = randomInputStream(i);
checkStreams(expected, in);
n.remove();
LOG.debug("removed: " + i);
session.save();
}
Thread.sleep(10);
gc.setStop(true);
Thread.sleep(10);
gcThread.join();
gc.throwException();
}
use of javax.jcr.ValueFactory in project jackrabbit by apache.
the class CopyValueTest method doTestCopy.
private void doTestCopy(int length) throws Exception {
Node root = superuser.getRootNode();
if (root.hasNode("testCopy")) {
root.getNode("testCopy").remove();
superuser.save();
}
Node testRoot = root.addNode("testCopy");
Node n = testRoot.addNode("a");
superuser.save();
byte[] data = new byte[length + 1];
ValueFactory vf = superuser.getValueFactory();
n.setProperty("data", vf.createBinary(new ByteArrayInputStream(data)));
superuser.save();
data = new byte[length];
n.setProperty("data", vf.createBinary(new ByteArrayInputStream(data)));
Property p = testRoot.getNode("a").getProperty("data");
assertEquals(length, p.getLength());
superuser.getWorkspace().copy("/testCopy/a", "/testCopy/b");
assertEquals(length, p.getLength());
p = testRoot.getNode("b").getProperty("data");
assertEquals(length + 1, p.getLength());
testRoot.remove();
superuser.save();
}
use of javax.jcr.ValueFactory in project jackrabbit by apache.
the class TestTwoGetStreams method testContentIdentity.
/**
* Test the JackrabbitValue.getContentIdentity feature.
*/
public void testContentIdentity() throws Exception {
Node root = superuser.getRootNode();
ValueFactory vf = superuser.getValueFactory();
long time = System.currentTimeMillis();
root.setProperty("p1", vf.createBinary(new RandomInputStream(1, STREAM_LENGTH)));
superuser.save();
long saveOne = System.currentTimeMillis() - time;
root.setProperty("p2", vf.createBinary(new RandomInputStream(1, STREAM_LENGTH)));
superuser.save();
Value v1 = root.getProperty("p1").getValue();
Value v2 = root.getProperty("p2").getValue();
if (v1 instanceof JackrabbitValue && v2 instanceof JackrabbitValue) {
JackrabbitValue j1 = (JackrabbitValue) v1;
JackrabbitValue j2 = (JackrabbitValue) v2;
String id1 = j1.getContentIdentity();
String id2 = j2.getContentIdentity();
assertNotNull(id1);
assertEquals(id1, id2);
}
// copying a value should not stream the content
time = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
Value v = root.getProperty("p1").getValue();
root.setProperty("p3", v);
}
superuser.save();
time = System.currentTimeMillis() - time;
// streaming 1 MB again and again takes about 4.3 seconds
// on my computer; copying the data identifier takes about 16 ms
// here we test if copying 100 objects took less than saving 50 new objects
assertTrue("time: " + time, time < saveOne * 50);
}
Aggregations