jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stefan Guggisberg" <stefan.guggisb...@gmail.com>
Subject Re: Concurrent modifications
Date Wed, 23 Apr 2008 11:49:15 GMT
hi julian

On Tue, Apr 22, 2008 at 7:04 PM, Julian Reschke <julian.reschke@gmx.de> wrote:
> Hi,
>
>  I was expecting that Jackrabbit is detecting concurrent modifications to a
> node, and reject them with an InvalidItemStateException.

yes, it should (and AFAIK it does ;).

>
>  However, this test:
>
>   public void testoverlappingUpdate() throws RepositoryException,
> UnsupportedEncodingException {
>
>     String testcontent = "base version";
>
>     Session session1 = testRootNode.getSession();
>     Session session2 = super.superuser;
>
>     // create the test node
>
>     Node testnode = testRootNode.addNode("testconcurrent", "nt:file");
>     String testnodepath = testnode.getPath();
>     Node testnodec = testnode.addNode("jcr:content", "nt:resource");
>     testnodec.setProperty("jcr:data", new
> ByteArrayInputStream(testcontent.getBytes("UTF-8")));
>     testnodec.setProperty("jcr:lastModified", Calendar.getInstance());
>     testnodec.setProperty("jcr:mimeType", "text/plain");
>     session1.save();
>     session1.refresh(false);
>
>     // retrieve it through both sessions
>
>     Node n1 = (Node)session1.getItem(testnodepath);
>     assertEquals(testcontent,
> n1.getProperty("jcr:content/jcr:data").getString());
>
>     Node n2 = (Node)session2.getItem(testnodepath);
>     assertEquals(testcontent,
> n2.getProperty("jcr:content/jcr:data").getString());
>
>     // modify through session1
>
>     n1.getNode("jcr:content").setProperty("jcr:data", testcontent + ", as
> modified by session 1");
>     n1.save();
>
>     // modify through session2
>
>     n2.getNode("jcr:content").setProperty("jcr:data", testcontent + ", as
> modified by session 2");
>     n2.save();
>   }
>
>  Is this a regression?

no. it's a feature ;)  in your case session2 modifies the property
*after* session1
saved the change, i.e. session2 is already aware of the new value.

in jackrabbit changes made by one session are instantly visible
to all other sessions as soon as they're saved (i.e. committed if
transactions are supported).

the following code will trigger the InvalidItemStateException:

     n1.getNode("jcr:content").setProperty("jcr:data", testcontent +
", session 1");
     n2.getNode("jcr:content").setProperty("jcr:data", testcontent +
", session 2");
     n2.save();
     n1.save();

cheers
stefan

>
>  BR, Julian
>
>  (I'm aware that detecting this is optional, but my understanding was that
> the RI was doing this at some point of time...)
>

Mime
View raw message