equal
deleted
inserted
replaced
1 "{ Package: 'exept:regression' }" |
1 "{ Package: 'exept:regression' }" |
|
2 |
|
3 "{ NameSpace: RegressionTests }" |
2 |
4 |
3 TestCase subclass:#SharedQueueTest |
5 TestCase subclass:#SharedQueueTest |
4 instanceVariableNames:'' |
6 instanceVariableNames:'' |
5 classVariableNames:'' |
7 classVariableNames:'' |
6 poolDictionaries:'' |
8 poolDictionaries:'' |
19 |
21 |
20 s1 := ReadWriteStream on:(Array new:1000). |
22 s1 := ReadWriteStream on:(Array new:1000). |
21 s2 := ReadWriteStream on:(Array new:1000). |
23 s2 := ReadWriteStream on:(Array new:1000). |
22 |
24 |
23 p1 := [ |
25 p1 := [ |
24 [ |
26 [ |
25 s1 nextPut:q next |
27 s1 nextPut:q next |
26 ] loop. |
28 ] loop. |
27 ] fork. |
29 ] fork. |
28 |
30 |
29 p2 := [ |
31 p2 := [ |
30 [ |
32 [ |
31 s2 nextPut:q next |
33 s2 nextPut:q next |
32 ] loop. |
34 ] loop. |
33 ] fork. |
35 ] fork. |
34 |
36 |
35 1 to:1000 do:[:i| |
37 1 to:1000 do:[:i| |
36 q nextPut:i |
38 q nextPut:i |
37 ]. |
39 ]. |
38 |
40 |
39 Delay waitForMilliseconds:20. |
41 Delay waitForMilliseconds:20. |
40 |
42 |
41 p1 terminate. |
43 p1 terminate. |
48 |
50 |
49 next1 := s1 next. |
51 next1 := s1 next. |
50 next2 := s2 next. |
52 next2 := s2 next. |
51 |
53 |
52 1 to: 1000 do:[:i| |
54 1 to: 1000 do:[:i| |
53 self should:[ |
55 self should:[ |
54 next1 == i ifTrue:[ |
56 next1 == i ifTrue:[ |
55 next1 := s1 next. |
57 next1 := s1 next. |
56 true. |
58 true. |
57 ] ifFalse:[ |
59 ] ifFalse:[ |
58 next2 == i ifTrue:[ |
60 next2 == i ifTrue:[ |
59 next2 := s2 next. |
61 next2 := s2 next. |
60 true |
62 true |
61 ]. |
63 ]. |
62 ] |
64 ] |
63 ] |
65 ] |
64 ]. |
66 ]. |
65 ! |
67 ! |
66 |
68 |
67 test2ReadersAndWriters |
69 test2ReadersAndWriters |
68 |
70 |
73 |
75 |
74 s1 := ReadWriteStream on:(Array new:20000). |
76 s1 := ReadWriteStream on:(Array new:20000). |
75 s2 := ReadWriteStream on:(Array new:20000). |
77 s2 := ReadWriteStream on:(Array new:20000). |
76 |
78 |
77 p1 := [ |
79 p1 := [ |
78 [ |
80 [ |
79 s1 nextPut:q next |
81 s1 nextPut:q next |
80 ] loop. |
82 ] loop. |
81 ] fork. |
83 ] fork. |
82 |
84 |
83 p2 := [ |
85 p2 := [ |
84 [ |
86 [ |
85 s2 nextPut:q next |
87 s2 nextPut:q next |
86 ] loop. |
88 ] loop. |
87 ] fork. |
89 ] fork. |
88 |
90 |
89 pw := [ |
91 pw := [ |
90 1 to:10000 do:[:i| |
92 1 to:10000 do:[:i| |
91 q nextPut:i+scale |
93 q nextPut:i+scale |
92 ]. |
94 ]. |
93 ] fork. |
95 ] fork. |
94 |
96 |
95 1 to:10000 do:[:i| |
97 1 to:10000 do:[:i| |
96 q nextPut:i |
98 q nextPut:i |
97 ]. |
99 ]. |
98 |
100 |
99 pw waitUntilTerminated. |
101 pw waitUntilTerminated. |
100 Delay waitForMilliseconds:20. |
102 Delay waitForMilliseconds:20. |
101 |
103 |
107 s1 reset. |
109 s1 reset. |
108 s2 reset. |
110 s2 reset. |
109 |
111 |
110 next1 := next2 := 0. |
112 next1 := next2 := 0. |
111 self should:[ |
113 self should:[ |
112 s1 contents conform:[:i| |
114 s1 contents conform:[:i| |
113 i < scale ifTrue:[ |
115 i < scale ifTrue:[ |
114 next1 < i and:[next1 := i. true] |
116 next1 < i and:[next1 := i. true] |
115 ] ifFalse:[ |
117 ] ifFalse:[ |
116 next2 < i and:[next2 := i. true] |
118 next2 < i and:[next2 := i. true] |
117 ]. |
119 ]. |
118 ]. |
120 ]. |
119 ]. |
121 ]. |
120 next1 := next2 := 0. |
122 next1 := next2 := 0. |
121 self should:[ |
123 self should:[ |
122 s2 contents conform:[:i| |
124 s2 contents conform:[:i| |
123 i < scale ifTrue:[ |
125 i < scale ifTrue:[ |
124 next1 < i and:[next1 := i. true] |
126 next1 < i and:[next1 := i. true] |
125 ] ifFalse:[ |
127 ] ifFalse:[ |
126 next2 < i and:[next2 := i. true] |
128 next2 < i and:[next2 := i. true] |
127 ]. |
129 ]. |
128 ]. |
130 ]. |
129 ]. |
131 ]. |
130 |
132 |
131 s1 reset. |
133 s1 reset. |
132 s2 reset. |
134 s2 reset. |
133 |
135 |
134 all := SortedCollection new:20000. |
136 all := SortedCollection new:20000. |
135 all addAll:s1 contents. |
137 all addAll:s1 contents. |
136 all addAll:s2 contents. |
138 all addAll:s2 contents. |
137 |
139 |
138 1 to: 10000 do:[:i| |
140 1 to: 10000 do:[:i| |
139 self assert:((all at:i) == i). |
141 self assert:((all at:i) == i). |
140 self assert:((all at:(i+10000)) == (i+scale)). |
142 self assert:((all at:(i+10000)) == (i+scale)). |
141 ]. |
143 ]. |
142 ! |
144 ! |
143 |
145 |
144 test2Writers |
146 test2Writers |
145 |
147 |
147 |
149 |
148 scale := 10000. |
150 scale := 10000. |
149 q := SharedQueue new:10. |
151 q := SharedQueue new:10. |
150 |
152 |
151 [ |
153 [ |
152 1 to:1000 do:[:i| |
154 1 to:1000 do:[:i| |
153 q nextPut:i. |
155 q nextPut:i. |
154 ]. |
156 ]. |
155 ] fork. |
157 ] fork. |
156 [ |
158 [ |
157 1 to:1000 do:[:i| |
159 1 to:1000 do:[:i| |
158 q nextPut:i+scale. |
160 q nextPut:i+scale. |
159 ]. |
161 ]. |
160 ] fork. |
162 ] fork. |
161 |
163 |
162 |
164 |
163 next1 := 1. |
165 next1 := 1. |
164 next2 := next1 + scale. |
166 next2 := next1 + scale. |
165 |
167 |
166 2000 timesRepeat:[ |i| |
168 2000 timesRepeat:[ |i| |
167 i := q next. |
169 i := q next. |
168 i < scale ifTrue:[ |
170 i < scale ifTrue:[ |
169 self assert:i == next1. |
171 self assert:i == next1. |
170 next1 := next1 + 1. |
172 next1 := next1 + 1. |
171 ] ifFalse:[ |
173 ] ifFalse:[ |
172 self assert:i == next2. |
174 self assert:i == next2. |
173 next2 := next2 + 1. |
175 next2 := next2 + 1. |
174 ] |
176 ] |
175 ]. |
177 ]. |
176 |
178 |
177 self assert:next1 == 1001. |
179 self assert:next1 == 1001. |
178 self assert:next2 == (next1 + scale). |
180 self assert:next2 == (next1 + scale). |
179 self assert:q isEmpty |
181 self assert:q isEmpty |
193 |q| |
195 |q| |
194 |
196 |
195 q := SharedQueue new:10. |
197 q := SharedQueue new:10. |
196 |
198 |
197 [ |
199 [ |
198 1 to:1000 do:[:i| |
200 1 to:1000 do:[:i| |
199 q nextPut:i. |
201 q nextPut:i. |
200 ]. |
202 ]. |
201 ] fork. |
203 ] fork. |
202 |
204 |
203 1 to: 1000 do:[:i| |
205 1 to: 1000 do:[:i| |
204 self assert:q next == i. |
206 self assert:q next == i. |
205 ]. |
207 ]. |
206 |
208 |
207 self assert:q isEmpty |
209 self assert:q isEmpty |
208 ! |
210 ! |
209 |
211 |
210 testRemoveAll |
212 testRemoveAll |
211 |
213 |
212 0 to:10 do:[:i| |
214 0 to:10 do:[:i| |
213 self removeAllSize:10 fill:i. |
215 self removeAllSize:10 fill:i. |
214 ]. |
216 ]. |
215 ! ! |
217 ! ! |
216 |
218 |
217 !SharedQueueTest methodsFor:'helpers'! |
219 !SharedQueueTest methodsFor:'helpers'! |
218 |
220 |
221 |q| |
223 |q| |
222 |
224 |
223 q := SharedQueue new:size. |
225 q := SharedQueue new:size. |
224 |
226 |
225 1 to:fill do:[:i| |
227 1 to:fill do:[:i| |
226 q nextPut:i. |
228 q nextPut:i. |
227 ]. |
229 ]. |
228 q removeAll. |
230 q removeAll. |
229 self assert:q isEmpty. |
231 self assert:q isEmpty. |
230 ! ! |
232 ! ! |
231 |
233 |