public void testPeerObjectUpdatedToOneRelationship() throws Exception {
Master a = parentContext1.newObject(Master.class);
Master altA = parentContext1.newObject(Master.class);
Child p = parentContext1.newObject(Child.class);
p.setMaster(a);
a.setName("X");
altA.setName("Y");
parentContext1.commitChanges();
Child p1 = (Child) parentContext2.localObject(p.getObjectId(), null);
Master altA1 = (Master) parentContext2.localObject(altA.getObjectId(), null);
final ObjectContext childContext1 = parentContext1.createChildContext();
final Child p2 = (Child) childContext1.localObject(p.getObjectId(), p);
final Master altA2 = (Master) childContext1.localObject(altA.getObjectId(), altA);
Master a2 = (Master) childContext1.localObject(a.getObjectId(), a);
p1.setMaster(altA1);
assertSame(a2, p2.getMaster());
assertNotSame(altA2, p2.getMaster());
parentContext2.commitChanges();
new ThreadedTestHelper() {
@Override
protected void assertResult() throws Exception {
assertSame(altA2, p2.getMaster());
assertFalse(
"Peer data context became dirty on event processing",
childContext1.hasChanges());
}
}.assertWithTimeout(2000);