src/JavaMonitorsTests.st
branchjk_new_structure
changeset 1144 c1c59b13340e
parent 1143 5e1de8c6b43e
child 1145 8728f5373a48
--- a/src/JavaMonitorsTests.st	Sun Nov 20 19:40:45 2011 +0000
+++ b/src/JavaMonitorsTests.st	Sun Nov 20 20:05:29 2011 +0000
@@ -134,6 +134,38 @@
     self validateResult.
 
     "Created: / 20-11-2011 / 17:28:16 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+testNotifyDoesNotMeanAcquireWithoutChecking
+    "aparently it does"
+    
+    "| t1  t2  mon |
+    mon := JavaMonitor new.
+    t1 := [
+                mon enter.
+                t1 stop.
+                self assert: (mon isOwnedBy: t1)
+                    message: 'monitor was not owned by t1 after resume'.
+                mon exit
+            ] newProcess.
+    t2 := [
+                self waitForStoppingThread: t1.
+                self assert: (mon isOwnedBy: t1)
+                    message: 'monitor was not owned by t1 after waiting for it to stop'.
+                mon enter.
+                self assert: (mon isOwnedBy: t2)
+                    message: 'monitor was not owned by t2 after enter'.
+                mon exit.
+            ] newProcess.
+    t1 resume.
+    t2 resume.
+    self waitForWaitingThread: t2.
+    mon notify.
+    t1 resume.
+    self waitForDyingThread: t2.
+    self validateResult."
+
+    "Created: / 20-11-2011 / 20:50:11 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
 ! !
 
 !JavaMonitorsTests methodsFor:'multithreading testing support'!
@@ -187,6 +219,12 @@
     [ aThread isStopped ] whileFalse: [ Delay waitForMilliseconds: 100 ].
 
     "Created: / 20-11-2011 / 19:17:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+waitForWaitingThread: aThread 
+    [ aThread isWaiting ] whileFalse: [ Delay waitForMilliseconds: 100 ].
+
+    "Created: / 20-11-2011 / 20:55:30 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
 ! !
 
 !JavaMonitorsTests methodsFor:'tests'!