JavaMonitorsTests.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 16 Jan 2013 22:06:41 +0000
branchrefactoring-vmdata
changeset 1977 526315e0a801
parent 1915 d043048afdcd
child 2069 75d40b7b986f
permissions -rw-r--r--
Fixed JavaNativeMethodImpl_OpenJDK6 class>>invoke:receiver:arguments:context:constructor:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
     1
"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
     2
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1146
diff changeset
     3
1155
vranyj1
parents: 1152
diff changeset
     4
 New code and modifications done at SWING Research Group [1]:
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1146
diff changeset
     5
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
     6
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
     7
                            SWING Research Group, Czech Technical University in Prague
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
     8
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
     9
 This software is furnished under a license and may be used
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    10
 only in accordance with the terms of that license and with the
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    11
 inclusion of the above copyright notice.   This software may not
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    12
 be provided or otherwise made available to, or used by, any
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    13
 other person.  No title to or ownership of the software is
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    14
 hereby transferred.
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    15
1155
vranyj1
parents: 1152
diff changeset
    16
 [1] Code written at SWING Research Group contains a signature
vranyj1
parents: 1152
diff changeset
    17
     of one of the above copright owners. For exact set of such code,
vranyj1
parents: 1152
diff changeset
    18
     see the differences between this version and version stx:libjava
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1146
diff changeset
    19
     as of 1.9.2010
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    20
"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    21
"{ Package: 'stx:libjava' }"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    22
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    23
TestCase subclass:#JavaMonitorsTests
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
    24
	instanceVariableNames:'result reason thisProcess assertionAccess thisProcessAccess'
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    25
	classVariableNames:''
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    26
	poolDictionaries:''
1515
f4ebf5cf3f89 - JavaClassReaderTests
vranyj1
parents: 1477
diff changeset
    27
	category:'Languages-Java-Tests'
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    28
!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    29
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    30
!JavaMonitorsTests class methodsFor:'documentation'!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    31
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    32
copyright
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    33
"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    34
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1146
diff changeset
    35
1155
vranyj1
parents: 1152
diff changeset
    36
 New code and modifications done at SWING Research Group [1]:
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1146
diff changeset
    37
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    38
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    39
                            SWING Research Group, Czech Technical University in Prague
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    40
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    41
 This software is furnished under a license and may be used
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    42
 only in accordance with the terms of that license and with the
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    43
 inclusion of the above copyright notice.   This software may not
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    44
 be provided or otherwise made available to, or used by, any
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    45
 other person.  No title to or ownership of the software is
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    46
 hereby transferred.
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    47
1155
vranyj1
parents: 1152
diff changeset
    48
 [1] Code written at SWING Research Group contains a signature
vranyj1
parents: 1152
diff changeset
    49
     of one of the above copright owners. For exact set of such code,
vranyj1
parents: 1152
diff changeset
    50
     see the differences between this version and version stx:libjava
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1146
diff changeset
    51
     as of 1.9.2010
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    52
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    53
"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    54
! !
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    55
1459
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
    56
!JavaMonitorsTests class methodsFor:'accessing'!
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
    57
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
    58
resources
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
    59
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
    60
  ^ Array 
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
    61
        with: JavaInitializedResource 
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
    62
        with: JavaLibrariesResource
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
    63
        with: JavaTestsResource
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
    64
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
    65
    "Created: / 30-03-2012 / 13:38:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
    66
! !
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
    67
1857
3be42d7af017 JavaMonitorsTests: set timeout to 5 min (Loading Groovy takes some time)
vranyj1
parents: 1832
diff changeset
    68
!JavaMonitorsTests methodsFor:'accessing'!
3be42d7af017 JavaMonitorsTests: set timeout to 5 min (Loading Groovy takes some time)
vranyj1
parents: 1832
diff changeset
    69
3be42d7af017 JavaMonitorsTests: set timeout to 5 min (Loading Groovy takes some time)
vranyj1
parents: 1832
diff changeset
    70
timeout
3be42d7af017 JavaMonitorsTests: set timeout to 5 min (Loading Groovy takes some time)
vranyj1
parents: 1832
diff changeset
    71
    ^60 * 5 "/5 min"
3be42d7af017 JavaMonitorsTests: set timeout to 5 min (Loading Groovy takes some time)
vranyj1
parents: 1832
diff changeset
    72
3be42d7af017 JavaMonitorsTests: set timeout to 5 min (Loading Groovy takes some time)
vranyj1
parents: 1832
diff changeset
    73
    "Created: / 03-12-2012 / 19:35:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
3be42d7af017 JavaMonitorsTests: set timeout to 5 min (Loading Groovy takes some time)
vranyj1
parents: 1832
diff changeset
    74
! !
3be42d7af017 JavaMonitorsTests: set timeout to 5 min (Loading Groovy takes some time)
vranyj1
parents: 1832
diff changeset
    75
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    76
!JavaMonitorsTests methodsFor:'mh exploratory tests'!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    77
1691
826f8d7dc0df thinlocks reintegrated
vranyj1
parents: 1550
diff changeset
    78
_testAssertInAnotherThreadShouldFail
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    79
    | t |
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    80
    "i thought so"
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    81
    t := [
1459
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
    82
        self assert: false message: 'I just want it to fail'.
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
    83
        self waitForAndResumeThisProcess
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
    84
    ] newProcess.
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    85
    t resume.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    86
    self stop.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    87
    self validateResult.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    88
1691
826f8d7dc0df thinlocks reintegrated
vranyj1
parents: 1550
diff changeset
    89
    "Created: / 26-08-2012 / 19:48:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    90
!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    91
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    92
testIssSemaphoreSignalledAutomaticallyOnStop
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    93
    | t1  t2  mon |
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1155
diff changeset
    94
    mon := JavaMonitor for: self.
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    95
    t1 := [
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    96
                mon enter.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    97
                self assert: (mon isOwnedBy: t1) message: 'mon was not owned by t1 in t1'.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    98
                t1 stop.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    99
                mon exit
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   100
            ] newProcess.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   101
    t2 := [
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   102
                [ t1 isStopped ] whileFalse: [ Delay waitForMilliseconds: 100 ].
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   103
                self assert: (mon isOwnedBy: t1)
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   104
                    message: 'mon was not owned by t1 after t1 isStopped'.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   105
                t1 resume.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   106
                [ t1 isDead ] whileFalse: [ Delay waitForMilliseconds: 100. ].
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   107
                self waitForAndResumeThisProcess.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   108
            ] newProcess.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   109
    t1 resume.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   110
    t2 resume.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   111
    self stop.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   112
    self validateResult.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   113
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   114
    "Created: / 20-11-2011 / 17:28:16 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1144
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   115
!
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   116
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   117
testNotifyDoesNotMeanAcquireWithoutChecking
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   118
    "aparently it does"
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   119
    
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   120
    "| t1  t2  mon |
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   121
    mon := JavaMonitor new.
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   122
    t1 := [
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   123
                mon enter.
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   124
                t1 stop.
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   125
                self assert: (mon isOwnedBy: t1)
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   126
                    message: 'monitor was not owned by t1 after resume'.
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   127
                mon exit
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   128
            ] newProcess.
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   129
    t2 := [
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   130
                self waitForStoppingThread: t1.
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   131
                self assert: (mon isOwnedBy: t1)
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   132
                    message: 'monitor was not owned by t1 after waiting for it to stop'.
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   133
                mon enter.
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   134
                self assert: (mon isOwnedBy: t2)
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   135
                    message: 'monitor was not owned by t2 after enter'.
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   136
                mon exit.
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   137
            ] newProcess.
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   138
    t1 resume.
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   139
    t2 resume.
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   140
    self waitForWaitingThread: t2.
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   141
    mon notify.
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   142
    t1 resume.
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   143
    self waitForDyingThread: t2.
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   144
    self validateResult."
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   145
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   146
    "Created: / 20-11-2011 / 20:50:11 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   147
! !
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   148
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   149
!JavaMonitorsTests methodsFor:'multithreading testing support'!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   150
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   151
assert: aBoolean message: message 
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   152
    assertionAccess critical: [
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   153
    result ifTrue: [
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   154
        result := aBoolean.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   155
        reason := message.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   156
    ].].
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   157
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   158
    "Created: / 20-11-2011 / 18:54:44 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   159
!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   160
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   161
setUp
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   162
    result := true.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   163
    reason := 'Everything went just fine'.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   164
    thisProcess := Processor activeProcess.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   165
    assertionAccess := Semaphore forMutualExclusion.
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   166
    thisProcessAccess := Semaphore forMutualExclusion.
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   167
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   168
    "Created: / 20-11-2011 / 18:55:39 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   169
!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   170
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   171
stop
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   172
    thisProcess stop.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   173
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   174
    "Created: / 20-11-2011 / 19:07:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   175
!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   176
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   177
validateResult  
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   178
    super assert: result message: reason.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   179
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   180
    "Created: / 20-11-2011 / 18:55:17 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   181
!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   182
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   183
waitForAndResumeThisProcess
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   184
    thisProcessAccess critical: [self waitForStoppingThread: thisProcess.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   185
    thisProcess resume.]
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   186
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   187
    "Created: / 20-11-2011 / 19:17:53 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   188
!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   189
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   190
waitForDyingThread: aThread 
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   191
  
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   192
[ aThread isDead ] whileFalse: [ Delay waitForMilliseconds: 100 ].
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   193
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   194
    "Created: / 20-11-2011 / 19:27:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   195
!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   196
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   197
waitForStoppingThread: aThread
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   198
    [ aThread isStopped ] whileFalse: [ Delay waitForMilliseconds: 100 ].
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   199
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   200
    "Created: / 20-11-2011 / 19:17:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1144
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   201
!
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   202
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   203
waitForWaitingThread: aThread 
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   204
    [ aThread isWaiting ] whileFalse: [ Delay waitForMilliseconds: 100 ].
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   205
c1c59b13340e tiny changes and big discovery :)
hlopkmar
parents: 1143
diff changeset
   206
    "Created: / 20-11-2011 / 20:55:30 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   207
! !
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   208
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   209
!JavaMonitorsTests methodsFor:'tests'!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   210
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   211
testBruteForceEnter
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   212
    | mon  threads  cleanupThread |
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1155
diff changeset
   213
    mon := JavaMonitor for:self.
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   214
    threads := OrderedCollection new.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   215
    20 timesRepeat: [
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   216
        | t |
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   217
        t := [
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   218
                    200 timesRepeat: [
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   219
                        mon enter.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   220
                        self assert: (mon isOwnedBy: t)
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   221
                            message: 'monitor was not owned by t after enter'.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   222
                        Delay waitForMilliseconds: 2.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   223
                        mon exit.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   224
                        self assert: (mon isOwnedBy: t) not
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   225
                            message: 'monitor was still owned by t after exit'.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   226
                    ]
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   227
                ] newProcess.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   228
        threads add: t
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   229
    ].
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   230
    cleanupThread := [
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   231
                threads do: [:each | self waitForDyingThread: each ].
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   232
                self waitForAndResumeThisProcess.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   233
            ] newProcess.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   234
    threads do: [:each | each resume ].
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   235
    cleanupThread resume.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   236
    self stop.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   237
    self validateResult.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   238
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   239
    "Created: / 20-11-2011 / 19:37:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   240
!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   241
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   242
testOneThread
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   243
    | mon  thread |
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1155
diff changeset
   244
    mon := JavaMonitor for:self.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   245
    thread := [
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   246
                self assert: mon isAcquired not
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   247
                    message: 'monitor was acquired at the beginning'.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   248
                mon enter.
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   249
                self assert: mon isAcquired
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   250
                    message: 'monitor was not acquired after monitor enter'.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   251
                self assert: (mon isOwnedBy: Processor activeProcess)
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   252
                    message: 'somebody else owned monitor after monitor enter'.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   253
                mon release.
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   254
                self assert: mon isAcquired not
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   255
                    message: 'monitor was still acquired after monitor release'.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   256
                self assert: (mon processesEntered includes: Processor activeProcess)
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   257
                    message: 'thread was not in the processesEntered after release'.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   258
                mon acquire.
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   259
                self assert: mon isAcquired
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   260
                    message: 'monitor was not acquired after monitor acquire'.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   261
                mon exit.
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   262
                self assert: mon isAcquired not
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   263
                    message: 'monitor stayed acquired after monitor exit'.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   264
                self assert: (mon processesEntered includes: Processor activeProcess) not
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   265
                    message: 'process was still in the processesEntered after monitorExit'.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   266
                self waitForAndResumeThisProcess.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   267
            ] newProcess.
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   268
    thread resume.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   269
    self stop.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   270
    self validateResult.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   271
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   272
    "Created: / 20-11-2011 / 13:20:59 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   273
!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   274
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   275
testOneThreadMultipleTimes
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   276
    | mon  t  count |
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1155
diff changeset
   277
    mon := JavaMonitor for:self.
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   278
    count := 5.
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   279
    t := [
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   280
                count timesRepeat: [ mon enter ].
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   281
                count timesRepeat: [
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   282
                    self assert: (mon isOwnedBy: t) message: 'mon was not owned by t1'.
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   283
                    mon exit
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   284
                ].
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   285
                self waitForAndResumeThisProcess
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   286
            ] newProcess.
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   287
    t resume.
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   288
    self stop.
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   289
    self validateResult.
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   290
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   291
    "Created: / 22-11-2011 / 11:02:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   292
!
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   293
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   294
testTwoThreadMultipleTimes
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   295
    | mon  t1  t2 |
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1155
diff changeset
   296
    mon := JavaMonitor for:self.
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   297
    t1 := [
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   298
                mon enter.
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   299
                mon enter.
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1155
diff changeset
   300
                self assert: (mon isOwnedBy: t1)
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1155
diff changeset
   301
                    message: 'mon was not owned by t1 after multiple enter'.
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   302
                mon exit.
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   303
                t1 stop.
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1155
diff changeset
   304
                self assert: (mon isOwnedBy: t1)
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1155
diff changeset
   305
                    message: 'mon was not owned by t1 after single exit'.
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   306
                mon exit.
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   307
                self waitForDyingThread: t2.
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   308
                self waitForAndResumeThisProcess
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   309
            ] newProcess.
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   310
    t2 := [
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   311
                self waitForStoppingThread: t1.
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1155
diff changeset
   312
                self assert: (mon isOwnedBy: t1)
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1155
diff changeset
   313
                    message: 'mon was not owned by t1 after stop'.
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   314
                t1 resume.
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   315
            ] newProcess.
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   316
    t1 resume.
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   317
    t2 resume.
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   318
    self stop.
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   319
    self assert: mon processesEntered isEmpty.
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   320
    self validateResult.
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   321
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   322
    "Created: / 22-11-2011 / 11:12:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   323
!
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   324
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   325
testTwoThreads
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   326
    "this took me a while :)"
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   327
    
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   328
    | mon  t1  t2 |
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1155
diff changeset
   329
    mon := JavaMonitor for:self.
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   330
    t1 := [
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   331
                t1 stop.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   332
                mon enter.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   333
                t2 resume.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   334
                t1 stop.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   335
                self assert: (mon processesEntered includes: t2)
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   336
                    message: 't2 was not in processesEntered after entering monitor'.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   337
                mon release.
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   338
                t1 stop.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   339
                mon acquire.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   340
                self assert: (mon isOwnedBy: t1)
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   341
                    message: 'monitor was not owned by t1 after t2 exitted it'.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   342
                mon exit.
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   343
            ] newProcess.
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   344
    t2 := [
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   345
                self waitForStoppingThread: t1.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   346
                t1 resume.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   347
                t2 stop.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   348
                self assert: mon isAcquired
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   349
                    message: 'monitor was not acquired after t1 entered it'.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   350
                self assert: (mon isOwnedBy: t1)
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   351
                    message: 'monitor was not owned by t1 after it entered it'.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   352
                t1 resume.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   353
                mon enter.
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   354
                self assert: (mon isOwnedBy: t2)
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   355
                    message: 'monitor was not owned by t2 after waiting on enter'.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   356
                mon exit.
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   357
                t1 resume.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   358
                self waitForDyingThread: t1.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   359
                self waitForAndResumeThisProcess
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   360
            ] newProcess.
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   361
    t1 resume.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   362
    t2 resume.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   363
    self stop.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   364
    self validateResult.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   365
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   366
    "Created: / 20-11-2011 / 14:51:22 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   367
! !
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   368
1459
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   369
!JavaMonitorsTests methodsFor:'tests-java'!
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   370
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   371
test_releasing_01
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   372
    "This tests call Java code in following setup:
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   373
        - a java method with handler that calls
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   374
        - a java method with finally that calls
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   375
        - a __synchronized java method with that calls
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   376
        - a java method throwing RuntimeException
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   377
1472
18de85f968bd tiny monitor test fix
hlopkmar
parents: 1461
diff changeset
   378
     When first Java method returns, all monitors should be released"
18de85f968bd tiny monitor test fix
hlopkmar
parents: 1461
diff changeset
   379
    
1459
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   380
    | javaTests |
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   381
    self assert: (JavaVM enteredMonitorsOfProcess: thisProcess) isEmptyOrNil.
1515
f4ebf5cf3f89 - JavaClassReaderTests
vranyj1
parents: 1477
diff changeset
   382
    javaTests := JAVA stx libjava tests lang MonitorTests new.
1459
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   383
    javaTests test_releasing_01.
1472
18de85f968bd tiny monitor test fix
hlopkmar
parents: 1461
diff changeset
   384
    self assert: (javaTests instVarNamed: #token) == 1101101.
1459
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   385
    self assert: (JavaVM enteredMonitorsOfProcess: thisProcess) isEmptyOrNil.
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   386
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   387
    "Created: / 07-04-2012 / 08:22:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1472
18de85f968bd tiny monitor test fix
hlopkmar
parents: 1461
diff changeset
   388
    "Modified: / 12-04-2012 / 15:11:47 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1515
f4ebf5cf3f89 - JavaClassReaderTests
vranyj1
parents: 1477
diff changeset
   389
    "Modified: / 06-07-2012 / 21:55:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1459
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   390
!
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   391
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   392
test_releasing_02
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   393
    "This tests call Java code in following setup:
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   394
        - a smalltalk method (this one) with handler for RuntimeException
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   395
        - a java method with finally that calls
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   396
        - a __synchronized java method with that calls
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   397
        - a java method throwing RuntimeException
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   398
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   399
     When first Java method returns, all monitors should be released        
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   400
    "
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   401
    | javaTests caught |
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   402
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   403
    self assert: (JavaVM enteredMonitorsOfProcess: thisProcess) isEmptyOrNil.
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   404
1515
f4ebf5cf3f89 - JavaClassReaderTests
vranyj1
parents: 1477
diff changeset
   405
    javaTests := JAVA stx libjava tests lang MonitorTests new.
1459
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   406
    caught := false.
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   407
    [
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   408
        javaTests instVarNamed: #token put: 3.
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   409
        javaTests test_releasing_01_finally.
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   410
    ] on: JAVA java lang RuntimeException do:[:ex|
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   411
        caught := true
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   412
    ].
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   413
    self assert: caught.
1477
cc9bd91382a2 - JavaExceptionTests
vranyj1
parents: 1472
diff changeset
   414
    self assert: (javaTests instVarNamed: #token) == 1003.
1459
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   415
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   416
    self assert: (JavaVM enteredMonitorsOfProcess: thisProcess) isEmptyOrNil.
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   417
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   418
    "Created: / 07-04-2012 / 08:39:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   419
!
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   420
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   421
test_releasing_03
1477
cc9bd91382a2 - JavaExceptionTests
vranyj1
parents: 1472
diff changeset
   422
    "Checks for bugs in monitor handling, there used to be a bug
cc9bd91382a2 - JavaExceptionTests
vranyj1
parents: 1472
diff changeset
   423
     that causes monitors not be entered/exited properly. This should
cc9bd91382a2 - JavaExceptionTests
vranyj1
parents: 1472
diff changeset
   424
     catch this bug if it reappears
1459
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   425
    "
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   426
    self assert: (JavaVM enteredMonitorsOfProcess: thisProcess) isEmptyOrNil.
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   427
1477
cc9bd91382a2 - JavaExceptionTests
vranyj1
parents: 1472
diff changeset
   428
    GroovyEvaluator new evaluate: '1'.
1459
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   429
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   430
    self assert: (JavaVM enteredMonitorsOfProcess: thisProcess) isEmptyOrNil.
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   431
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   432
    "Created: / 07-04-2012 / 08:42:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   433
! !
9e24f4337d78 Tests for finally
vranyj1
parents: 1194
diff changeset
   434
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   435
!JavaMonitorsTests methodsFor:'wait notify tests'!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   436
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   437
testManyThreadsWaitNotifyAll
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   438
    | mon  threads |
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1155
diff changeset
   439
    mon := JavaMonitor for:self.
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   440
    threads := OrderedCollection new.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   441
    2 timesRepeat: [
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   442
        | t |
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   443
        t := [
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   444
                    mon enter.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   445
                    self assert: (mon isOwnedBy: t)
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   446
                        message: 'thread was not owned by t after enter'.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   447
                    self waitForAndResumeThisProcess.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   448
                    'resumed thisProcess' infoPrintCR.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   449
                    mon wait.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   450
                    'notified and alive' infoPrintCR.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   451
                    self assert: (mon isOwnedBy: t)
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   452
                        message: 'thread was not owned by t after wait'.
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1155
diff changeset
   453
                    mon exit.
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   454
                    'dying' infoPrintCR.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   455
                ] newProcess.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   456
        threads add: t.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   457
    ].
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   458
    threads do: [
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   459
        :each | 
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   460
        'resuming t' infoPrintCR.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   461
        each resume
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   462
    ].
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   463
    threads do: [
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   464
        :each | 
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   465
        'stopping' infoPrintCR.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   466
        self stop
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   467
    ].
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   468
    threads do: [
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   469
        :each | 
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   470
        'waiting for waiting' infoPrintCR.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   471
        self waitForWaitingThread: each
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   472
    ].
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   473
    'sync barrier reached' infoPrintCR.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   474
    mon enter.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   475
    mon notifyAll.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   476
    'threads has been notified' infoPrintCR.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   477
    mon exit.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   478
    'monitor exitted' infoPrintCR.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   479
    threads do: [
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   480
        :each | 
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   481
        'waiting for them to die' infoPrintCR.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   482
        self waitForDyingThread: each
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   483
    ].
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   484
    self validateResult.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   485
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   486
    "Created: / 22-11-2011 / 12:27:16 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   487
!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   488
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   489
testOneThreadWaitMultipleEnters
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   490
    | mon  t |
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1155
diff changeset
   491
    mon := JavaMonitor for:self.
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   492
    t := [
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   493
                mon enter.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   494
                mon enter.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   495
                mon enter.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   496
                self waitForAndResumeThisProcess.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   497
                self assert: (mon isOwnedBy: t)
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   498
                    message: 'thread was not owned by t after enter'.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   499
                mon wait.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   500
                self assert: (mon isOwnedBy: t)
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   501
                    message: 'thread was not owned by t after wait'.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   502
                mon exit.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   503
                self assert: (mon isOwnedBy: t)
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   504
                    message: 'thread was not owned by t after wait'.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   505
                mon exit.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   506
                self assert: (mon isOwnedBy: t)
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   507
                    message: 'thread was not owned by t after wait'.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   508
                mon exit.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   509
            ] newProcess.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   510
    t resume.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   511
    self stop.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   512
    mon enter.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   513
    mon notify.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   514
    mon exit.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   515
    self waitForDyingThread: t.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   516
    self validateResult.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   517
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   518
    "Created: / 22-11-2011 / 12:55:38 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   519
!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   520
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   521
testOneThreadWaitNotify
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   522
    | mon  t |
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1155
diff changeset
   523
    mon := JavaMonitor for:self.
1550
fde50161f2b4 - more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents: 1515
diff changeset
   524
    t := nil.
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   525
    t := [
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   526
                mon enter.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   527
                self assert: (mon isOwnedBy: t)
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   528
                    message: 'thread was not owned by t after enter'.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   529
                self waitForAndResumeThisProcess.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   530
                mon wait.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   531
                self assert: (mon isOwnedBy: t)
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   532
                    message: 'thread was not owned by t after wait'.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   533
                self waitForAndResumeThisProcess
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   534
            ] newProcess.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   535
    t resume.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   536
    self stop.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   537
    mon enter.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   538
    mon notify.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   539
    mon exit.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   540
    self stop.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   541
    self validateResult.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   542
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   543
    "Created: / 22-11-2011 / 11:51:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1550
fde50161f2b4 - more finalization stuff. The only missing bit is periodical call to collectionCycle...
vranyj1
parents: 1515
diff changeset
   544
    "Modified: / 24-07-2012 / 10:48:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   545
!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   546
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   547
testOneThreadWaitTimeout
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   548
    | mon  t |
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1155
diff changeset
   549
    mon := JavaMonitor for:self.
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   550
    t := [
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   551
                mon enter.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   552
                self assert: (mon isOwnedBy: t)
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   553
                    message: 'thread was not owned by t after enter'.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   554
                
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   555
                "/notify will never come
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   556
                
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   557
                mon waitForMilliseconds: 500.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   558
                self assert: (mon isOwnedBy: t)
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   559
                    message: 'thread was not owned by t after wait'.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   560
            ] newProcess.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   561
    t resume.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   562
    self waitForDyingThread: t.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   563
    self validateResult.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   564
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   565
    "Created: / 22-11-2011 / 12:51:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   566
! !
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   567
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   568
!JavaMonitorsTests class methodsFor:'documentation'!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   569
1915
d043048afdcd just formatting
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 1857
diff changeset
   570
version_HG
d043048afdcd just formatting
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 1857
diff changeset
   571
d043048afdcd just formatting
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 1857
diff changeset
   572
    ^ '$Changeset: <not expanded> $'
d043048afdcd just formatting
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 1857
diff changeset
   573
!
d043048afdcd just formatting
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 1857
diff changeset
   574
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   575
version_SVN
1915
d043048afdcd just formatting
Marcel Hlopko <marcel.hlopko@fit.cvut.cz>
parents: 1857
diff changeset
   576
    ^ '§Id§'
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   577
! !