public void test() { Thread thread1 = new Thread() { public void run() { UnitOfWork uow = getSession().acquireUnitOfWork(); cloned = (ConcurrentPerson) uow.registerObject(person); } }; Thread thread2 = new Thread() { public void run() { getSession().refreshObject(person.address); } }; thread1.start(); thread2.start(); try { thread1.join(); thread2.join(); } catch (Exception ex) { // just an inturrupt ignore } ConcurrentAddress.RUNNING_TEST = ConcurrentAddress.NONE; if (!(cloned.getAddress().getStreet().equals("Start") && cloned.getAddress().getPostalCode().equals("H0H0H0"))) { if (!(cloned.getAddress().getStreet().equals("Corrupted") && cloned.getAddress().getPostalCode().equals("A1A1A1"))) { throw new TestErrorException("Failed to wholly clone the object"); } else { getSession().logMessage("LockOnCloneTest :-> Clone blocked on Refresh"); } } else { getSession().logMessage(" LockOnCloneTest :-> refresh blocked on clone"); } }
public void setup() { if (getSession().isDistributedSession()) { throw new TestWarningException( "Test unavailable on Remote UnitOfWork because of timing issues"); } getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); getSession().getDescriptor(ConcurrentAddress.class).getEventManager().addListener(listener); UnitOfWork uow = getSession().acquireUnitOfWork(); this.person = ConcurrentPerson.example1(); // get the UOW clone to ensure the PK will be set in the case of Isolate in UOW test model this.person = (ConcurrentPerson) uow.registerObject(this.person); uow.commit(); ConcurrentAddress.RUNNING_TEST = ConcurrentAddress.LOCK_ON_CLONE_TEST; }