author | Claus Gittinger <cg@exept.de> |
Thu, 28 Mar 2019 00:20:16 +0100 | |
changeset 2190 | df0e2fac468d |
parent 1447 | 2351db93aa5b |
child 1500 | d406a10b2965 |
permissions | -rw-r--r-- |
1447 | 1 |
"{ Package: 'stx:goodies/regression' }" |
90 | 2 |
|
95 | 3 |
"{ NameSpace: RegressionTests }" |
4 |
||
90 | 5 |
TestCase subclass:#SharedQueueTest |
6 |
instanceVariableNames:'' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
1059 | 9 |
category:'tests-Regression-Collections' |
90 | 10 |
! |
11 |
||
12 |
||
13 |
!SharedQueueTest methodsFor:'Testing'! |
|
14 |
||
15 |
test2Readers |
|
16 |
||
17 |
|q scale p1 p2 s1 s2 next1 next2| |
|
18 |
||
19 |
scale := 10000. |
|
20 |
q := SharedQueue new:10. |
|
21 |
||
22 |
s1 := ReadWriteStream on:(Array new:1000). |
|
23 |
s2 := ReadWriteStream on:(Array new:1000). |
|
24 |
||
25 |
p1 := [ |
|
1447 | 26 |
[ |
27 |
s1 nextPut:q next |
|
28 |
] loop. |
|
90 | 29 |
] fork. |
30 |
||
31 |
p2 := [ |
|
1447 | 32 |
[ |
33 |
s2 nextPut:q next |
|
34 |
] loop. |
|
90 | 35 |
] fork. |
36 |
||
37 |
1 to:1000 do:[:i| |
|
1447 | 38 |
q nextPut:i |
90 | 39 |
]. |
40 |
||
41 |
Delay waitForMilliseconds:20. |
|
42 |
||
43 |
p1 terminate. |
|
44 |
p2 terminate. |
|
45 |
||
209
eff283f4ddd5
Fix position handling (assumed 1-based positions)
Stefan Vogel <sv@exept.de>
parents:
181
diff
changeset
|
46 |
self assert:s1 position0Based + s2 position0Based == 1000. |
90 | 47 |
|
48 |
s1 reset. |
|
49 |
s2 reset. |
|
50 |
||
51 |
next1 := s1 next. |
|
52 |
next2 := s2 next. |
|
53 |
||
54 |
1 to: 1000 do:[:i| |
|
1447 | 55 |
self should:[ |
56 |
next1 == i ifTrue:[ |
|
57 |
next1 := s1 next. |
|
58 |
true. |
|
59 |
] ifFalse:[ |
|
60 |
next2 == i ifTrue:[ |
|
61 |
next2 := s2 next. |
|
62 |
true |
|
63 |
]. |
|
64 |
] |
|
65 |
] |
|
90 | 66 |
]. |
67 |
! |
|
68 |
||
69 |
test2ReadersAndWriters |
|
70 |
||
71 |
|q scale p1 p2 pw s1 s2 next1 next2 all| |
|
72 |
||
73 |
scale := 100000. |
|
74 |
q := SharedQueue new:10. |
|
75 |
||
76 |
s1 := ReadWriteStream on:(Array new:20000). |
|
77 |
s2 := ReadWriteStream on:(Array new:20000). |
|
78 |
||
79 |
p1 := [ |
|
1447 | 80 |
[ |
81 |
s1 nextPut:q next |
|
82 |
] loop. |
|
90 | 83 |
] fork. |
84 |
||
85 |
p2 := [ |
|
1447 | 86 |
[ |
87 |
s2 nextPut:q next |
|
88 |
] loop. |
|
90 | 89 |
] fork. |
90 |
||
91 |
pw := [ |
|
1447 | 92 |
1 to:10000 do:[:i| |
93 |
q nextPut:i+scale |
|
94 |
]. |
|
90 | 95 |
] fork. |
96 |
||
97 |
1 to:10000 do:[:i| |
|
1447 | 98 |
q nextPut:i |
90 | 99 |
]. |
100 |
||
101 |
pw waitUntilTerminated. |
|
102 |
Delay waitForMilliseconds:20. |
|
103 |
||
104 |
p1 terminate. |
|
105 |
p2 terminate. |
|
106 |
||
209
eff283f4ddd5
Fix position handling (assumed 1-based positions)
Stefan Vogel <sv@exept.de>
parents:
181
diff
changeset
|
107 |
self assert:s1 position0Based + s2 position0Based == 20000. |
90 | 108 |
|
109 |
s1 reset. |
|
110 |
s2 reset. |
|
111 |
||
112 |
next1 := next2 := 0. |
|
113 |
self should:[ |
|
1447 | 114 |
s1 contents conform:[:i| |
115 |
i < scale ifTrue:[ |
|
116 |
next1 < i and:[next1 := i. true] |
|
117 |
] ifFalse:[ |
|
118 |
next2 < i and:[next2 := i. true] |
|
119 |
]. |
|
120 |
]. |
|
90 | 121 |
]. |
122 |
next1 := next2 := 0. |
|
123 |
self should:[ |
|
1447 | 124 |
s2 contents conform:[:i| |
125 |
i < scale ifTrue:[ |
|
126 |
next1 < i and:[next1 := i. true] |
|
127 |
] ifFalse:[ |
|
128 |
next2 < i and:[next2 := i. true] |
|
129 |
]. |
|
130 |
]. |
|
90 | 131 |
]. |
132 |
||
133 |
s1 reset. |
|
134 |
s2 reset. |
|
135 |
||
136 |
all := SortedCollection new:20000. |
|
137 |
all addAll:s1 contents. |
|
138 |
all addAll:s2 contents. |
|
139 |
||
140 |
1 to: 10000 do:[:i| |
|
1447 | 141 |
self assert:((all at:i) == i). |
142 |
self assert:((all at:(i+10000)) == (i+scale)). |
|
90 | 143 |
]. |
144 |
! |
|
145 |
||
146 |
test2Writers |
|
147 |
||
148 |
|q scale next1 next2| |
|
149 |
||
150 |
scale := 10000. |
|
151 |
q := SharedQueue new:10. |
|
152 |
||
153 |
[ |
|
95 | 154 |
1 to:1000 do:[:i| |
155 |
q nextPut:i. |
|
156 |
]. |
|
90 | 157 |
] fork. |
158 |
[ |
|
95 | 159 |
1 to:1000 do:[:i| |
160 |
q nextPut:i+scale. |
|
161 |
]. |
|
90 | 162 |
] fork. |
163 |
||
164 |
||
165 |
next1 := 1. |
|
166 |
next2 := next1 + scale. |
|
167 |
||
168 |
2000 timesRepeat:[ |i| |
|
95 | 169 |
i := q next. |
170 |
i < scale ifTrue:[ |
|
171 |
self assert:i == next1. |
|
172 |
next1 := next1 + 1. |
|
173 |
] ifFalse:[ |
|
174 |
self assert:i == next2. |
|
175 |
next2 := next2 + 1. |
|
176 |
] |
|
90 | 177 |
]. |
178 |
||
179 |
self assert:next1 == 1001. |
|
180 |
self assert:next2 == (next1 + scale). |
|
181 |
self assert:q isEmpty |
|
182 |
! |
|
183 |
||
184 |
testBasics |
|
185 |
||
186 |
|q| |
|
187 |
||
188 |
q := SharedQueue new:5. |
|
189 |
self assert:q isEmpty. |
|
190 |
self assert:q size == 0. |
|
191 |
! |
|
192 |
||
193 |
testReaderWriter |
|
194 |
||
195 |
|q| |
|
196 |
||
197 |
q := SharedQueue new:10. |
|
198 |
||
199 |
[ |
|
95 | 200 |
1 to:1000 do:[:i| |
201 |
q nextPut:i. |
|
202 |
]. |
|
90 | 203 |
] fork. |
204 |
||
205 |
1 to: 1000 do:[:i| |
|
95 | 206 |
self assert:q next == i. |
90 | 207 |
]. |
208 |
||
209 |
self assert:q isEmpty |
|
210 |
! |
|
211 |
||
212 |
testRemoveAll |
|
213 |
||
214 |
0 to:10 do:[:i| |
|
95 | 215 |
self removeAllSize:10 fill:i. |
90 | 216 |
]. |
217 |
! ! |
|
218 |
||
219 |
!SharedQueueTest methodsFor:'helpers'! |
|
220 |
||
221 |
removeAllSize:size fill:fill |
|
222 |
||
223 |
|q| |
|
224 |
||
225 |
q := SharedQueue new:size. |
|
226 |
||
227 |
1 to:fill do:[:i| |
|
95 | 228 |
q nextPut:i. |
90 | 229 |
]. |
230 |
q removeAll. |
|
231 |
self assert:q isEmpty. |
|
232 |
! ! |
|
233 |
||
234 |
!SharedQueueTest class methodsFor:'documentation'! |
|
235 |
||
236 |
version |
|
237 |
^ '$Header$' |
|
238 |
! ! |
|
1059 | 239 |