Search in sources :

Example 1 with JackrabbitValue

use of org.apache.jackrabbit.api.JackrabbitValue 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);
}
Also used : JackrabbitValue(org.apache.jackrabbit.api.JackrabbitValue) Node(javax.jcr.Node) Value(javax.jcr.Value) JackrabbitValue(org.apache.jackrabbit.api.JackrabbitValue) ValueFactory(javax.jcr.ValueFactory)

Aggregations

Node (javax.jcr.Node)1 Value (javax.jcr.Value)1 ValueFactory (javax.jcr.ValueFactory)1 JackrabbitValue (org.apache.jackrabbit.api.JackrabbitValue)1