JavaThreadingTests.st
author Claus Gittinger <cg@exept.de>
Sun, 23 Feb 2020 14:03:15 +0100
branchcvs_MAIN
changeset 3997 5bb44f7e1d20
parent 3330 b14c58b2876c
permissions -rw-r--r--
#REFACTORING by exept class: Java class changed: #dumpConfigOn:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3214
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     1
"
3324
a58245c0e83a Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3214
diff changeset
     2
 COPYRIGHT (c) 1996-2015 by Claus Gittinger
3214
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     3
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     4
 New code and modifications done at SWING Research Group [1]:
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     5
3324
a58245c0e83a Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3214
diff changeset
     6
 COPYRIGHT (c) 2010-2015 by Jan Vrany, Jan Kurs and Marcel Hlopko
3214
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     7
                            SWING Research Group, Czech Technical University in Prague
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     8
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     9
 This software is furnished under a license and may be used
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    10
 only in accordance with the terms of that license and with the
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    11
 inclusion of the above copyright notice.   This software may not
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    12
 be provided or otherwise made available to, or used by, any
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    13
 other person.  No title to or ownership of the software is
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    14
 hereby transferred.
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    15
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    16
 [1] Code written at SWING Research Group contains a signature
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    17
     of one of the above copright owners. For exact set of such code,
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    18
     see the differences between this version and version stx:libjava
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    19
     as of 1.9.2010
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    20
"
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    21
"{ Package: 'stx:libjava' }"
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    22
3330
b14c58b2876c Oops, moved stray reloading-related methods from stx:libjava/experiments to stx:libjava.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
    23
"{ NameSpace: Smalltalk }"
b14c58b2876c Oops, moved stray reloading-related methods from stx:libjava/experiments to stx:libjava.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
    24
3214
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    25
TestCase subclass:#JavaThreadingTests
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    26
	instanceVariableNames:''
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    27
	classVariableNames:''
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    28
	poolDictionaries:''
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    29
	category:'Languages-Java-Tests'
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    30
!
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    31
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    32
!JavaThreadingTests class methodsFor:'documentation'!
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    33
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    34
copyright
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    35
"
3324
a58245c0e83a Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3214
diff changeset
    36
 COPYRIGHT (c) 1996-2015 by Claus Gittinger
3214
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    37
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    38
 New code and modifications done at SWING Research Group [1]:
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    39
3324
a58245c0e83a Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3214
diff changeset
    40
 COPYRIGHT (c) 2010-2015 by Jan Vrany, Jan Kurs and Marcel Hlopko
3214
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    41
                            SWING Research Group, Czech Technical University in Prague
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    42
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    43
 This software is furnished under a license and may be used
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    44
 only in accordance with the terms of that license and with the
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    45
 inclusion of the above copyright notice.   This software may not
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    46
 be provided or otherwise made available to, or used by, any
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    47
 other person.  No title to or ownership of the software is
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    48
 hereby transferred.
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    49
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    50
 [1] Code written at SWING Research Group contains a signature
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    51
     of one of the above copright owners. For exact set of such code,
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    52
     see the differences between this version and version stx:libjava
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    53
     as of 1.9.2010
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    54
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    55
"
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    56
! !
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    57
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    58
!JavaThreadingTests class methodsFor:'accessing'!
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    59
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    60
resources
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    61
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    62
  ^ Array 
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    63
        with: JavaInitializedResource 
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    64
        with: JavaLibrariesResource
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    65
        with: JavaTestsResource
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    66
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    67
    "Created: / 30-03-2012 / 13:38:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    68
! !
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    69
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    70
!JavaThreadingTests methodsFor:'tests'!
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    71
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    72
test_regression_01
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    73
    "Make sure that java.lang.Thread (& corresponding Smalltalk Process) is removed from
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    74
     Java:Threads map when thread finished (to avoid resource leak)"
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    75
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    76
    | thread threadProcess activeProcess blocker |
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    77
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    78
    blocker := Semaphore new.
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    79
    [ 
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    80
        thread := JAVA java lang Thread currentThread.
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    81
        "/ Use Java classVarAt: hack to avoud need for access methods not otherwise
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    82
        "/ required. They should be cleaned.
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    83
        threadProcess := (Java classVarAt: #Threads) at: thread.
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    84
        activeProcess := Processor activeProcess.
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    85
        blocker signal.
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    86
    ] fork.
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    87
    blocker wait.
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    88
    self assert: thread notNil.
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    89
    self assert: threadProcess notNil.
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    90
    self assert: threadProcess == activeProcess.
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    91
    "/ Give exist actions chance to run.
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    92
    Delay waitForMilliseconds: 100.
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    93
    self assert: ((Java classVarAt: #Threads) includesKey: thread) not.
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    94
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    95
    "Created: / 08-08-2014 / 09:33:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    96
! !
c38fcee7b0da Fixes bad bug in Java thread handling that caused memory/resource leak.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    97