OK,
sorry for getting back to this discussion late.
I modified the test case so that the InvalidItemStateException indeed
occurs with jackrabbit-core (see attachment).
I think we have consensus that JSR-170 doesn't require a store to behave
like that; it's truly optional.
Now, with the same test and with jcr2spi (connecting to jackrabbit-core
through spi2jcr) the InvalidItemStateException is *not* thrown.
This doesn't come as a surprise, because -- as far as I understand --
JCR2SPI lacks the necessary information to do so.
It seems to me that the SPI APIshould *allow* stores to expose the same
behaviour as jackrabbit-core, and the simplest way to achieve that would
(IMHO) be to allow the SPI implementation to keep state. (*)
Feedback appreciated,
Julian
(*) Right now, when it does keep state, we see TCK failures, as JCR's
refresh() method is not delegated to the SPI SessionInfo. I think we
need to fix that.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jackrabbit.benchmark;
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import java.util.Calendar;
import javax.jcr.InvalidItemStateException;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.jackrabbit.test.AbstractJCRTest;
public class ConcurrentUpdateTest extends AbstractJCRTest {
public void testoverlappingUpdate() throws RepositoryException,
UnsupportedEncodingException {
String testcontent = "base version";
Session session1 = testRootNode.getSession();
Session session2 = helper.getReadWriteSession();
assertTrue(session1 != session2);
// 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);
Node c1 = n1.getNode("jcr:content");
Property d1 = c1.getProperty("jcr:data");
assertEquals(testcontent, d1.getString());
Node n2 = (Node)session2.getItem(testnodepath);
Node c2 = n2.getNode("jcr:content");
Property d2 = c2.getProperty("jcr:data");
assertEquals(testcontent, d2.getString());
// modify through session1
c1.setProperty("jcr:data", testcontent + ", as modified by session 1");
// modify persisted property through session 2
c2.setProperty("jcr:data", testcontent + ", as modified by session 2");
n2.save();
// now try to save session 1... should fail
try {
n1.save();
fail("expected InvalidItemStateException");
}
catch (InvalidItemStateException expected) {
//
}
}
}