|
From: <hib...@li...> - 2006-05-05 12:05:15
|
Author: max...@jb...
Date: 2006-05-05 08:05:04 -0400 (Fri, 05 May 2006)
New Revision: 9891
Modified:
trunk/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java
Log:
added failureexpected test for HHH-1677
Modified: trunk/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java 2006-05-05 11:44:34 UTC (rev 9890)
+++ trunk/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java 2006-05-05 12:05:04 UTC (rev 9891)
@@ -5,6 +5,7 @@
import junit.framework.TestSuite;
import org.hibernate.Session;
+import org.hibernate.StaleObjectStateException;
import org.hibernate.Transaction;
import org.hibernate.test.TestCase;
@@ -57,6 +58,90 @@
s.close();
}
+ //TODO: also test that non-overlapping changes behavior.
+ public void testOptimisticLockDirtyDeleteFailureExpected() {
+ //HHH-1677
+
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Document doc = new Document();
+ doc.setTitle("Hibernate in Action");
+ doc.setAuthor("Bauer et al");
+ doc.setSummary("Very boring book about persistence");
+ doc.setText("blah blah yada yada yada");
+ doc.setPubDate( new PublicationDate(2004) );
+ s.save("Dirty", doc);
+ s.flush();
+ doc.setSummary("A modern classic");
+ s.flush();
+ doc.getPubDate().setMonth( new Integer(3) );
+ s.flush();
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ doc = (Document) s.get("Dirty", doc.getId());
+
+ Session other = openSession();
+ Transaction othert = other.beginTransaction();
+ Document otherDoc = (Document) other.get("Dirty", doc.getId());
+ otherDoc.setSummary( "my other summary" );
+ other.flush();
+ othert.commit();
+ other.close();
+
+ try {
+ s.delete(doc);
+ t.commit();
+ fail("Should fail since other session have update the summary");
+ } catch(StaleObjectStateException soe) {
+ // expected
+ }
+ s.close();
+ }
+
+ public void testOptimisticLockAllDeleteFailureExpected() {
+ //HHH-1677
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Document doc = new Document();
+ doc.setTitle("Hibernate in Action");
+ doc.setAuthor("Bauer et al");
+ doc.setSummary("Very boring book about persistence");
+ doc.setText("blah blah yada yada yada");
+ doc.setPubDate( new PublicationDate(2004) );
+ s.save("Dirty", doc);
+ s.flush();
+ doc.setSummary("A modern classic");
+ s.flush();
+ doc.getPubDate().setMonth( new Integer(3) );
+ s.flush();
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ doc = (Document) s.get("All", doc.getId());
+
+ Session other = openSession();
+ Transaction othert = other.beginTransaction();
+ Document otherDoc = (Document) other.get("All", doc.getId());
+ otherDoc.setSummary( "my other summary" );
+ other.flush();
+ othert.commit();
+ other.close();
+
+ try {
+ s.delete(doc);
+ t.commit();
+ fail("Should fail since other session have update the summary");
+ } catch(StaleObjectStateException soe) {
+ // expected
+ }
+ s.close();
+ }
+
protected String[] getMappings() {
return new String[] { "optlock/Document.hbm.xml" };
|