}
}.assertWithTimeout(2000);
}
public void testPeerObjectUpdatedToManyRelationship() throws Exception {
Master a = parentContext1.newObject(Master.class);
a.setName("X");
Child px = parentContext1.newObject(Child.class);
px.setMaster(a);
Child py = parentContext1.newObject(Child.class);
parentContext1.commitChanges();
Child py1 = (Child) parentContext2.localObject(py.getObjectId(), py);
Master a1 = (Master) parentContext2.localObject(a.getObjectId(), a);
final ObjectContext peer2 = parentContext1.createChildContext();
final Child py2 = (Child) peer2.localObject(py.getObjectId(), py);
final Master a2 = (Master) peer2.localObject(a.getObjectId(), a);
a1.addToChildren(py1);
assertEquals(1, a2.getChildren().size());
assertFalse(a2.getChildren().contains(py2));
parentContext2.commitChangesToParent();
new ThreadedTestHelper() {
@Override
protected void assertResult() throws Exception {
assertEquals(2, a2.getChildren().size());
assertTrue(a2.getChildren().contains(py2));
assertFalse("Peer data context became dirty on event processing", peer2
.hasChanges());
}
}.assertWithTimeout(2000);