*/
@Test
public void testConcurrencyFailure() throws Exception {
fact().register(Trivial.class);
Trivial triv = new Trivial("foo", 5);
final Key<Trivial> tk = ofy().save().entity(triv).now();
try {
ofy().transactNew(2, new VoidWork() {
@Override
public void vrun() {
Trivial triv1 = ofy().transactionless().load().key(tk).now();
Trivial triv2 = ofy().load().key(tk).now();
triv1.setSomeString("bar");
triv2.setSomeString("shouldn't work");
ofy().transactionless().save().entity(triv1).now();
ofy().save().entity(triv2).now();
}
});
assert false; // must throw exception
}
catch (ConcurrentModificationException ex) {}
Trivial fetched = ofy().load().key(tk).now();
// This will be fetched from the cache, and must not be the "shouldn't work"
assert fetched.getSomeString().equals("bar");
}