public void testPeerObjectUpdatedToManyRelationship() throws Exception {
DataContext context = createDataContext();
Artist a = context.newObject(Artist.class);
a.setArtistName("X");
Painting px = context.newObject(Painting.class);
px.setToArtist(a);
px.setPaintingTitle("PX");
Painting py = context.newObject(Painting.class);
py.setPaintingTitle("PY");
context.commitChanges();
DataContext parentPeer = context.getParentDataDomain().createDataContext();
Painting py1 = (Painting) parentPeer.localObject(py.getObjectId(), py);
Artist a1 = (Artist) parentPeer.localObject(a.getObjectId(), a);
final ObjectContext peer2 = context.createChildContext();
final Painting py2 = (Painting) peer2.localObject(py.getObjectId(), py);
final Artist a2 = (Artist) peer2.localObject(a.getObjectId(), a);
a1.addToPaintingArray(py1);
assertEquals(1, a2.getPaintingArray().size());
assertFalse(a2.getPaintingArray().contains(py2));
parentPeer.commitChangesToParent();
new ThreadedTestHelper() {
@Override
protected void assertResult() throws Exception {
assertEquals(2, a2.getPaintingArray().size());
assertTrue(a2.getPaintingArray().contains(py2));
assertFalse("Peer data context became dirty on event processing", peer2
.hasChanges());
}
}.assertWithTimeout(2000);