1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.DynamicProxy
.Test
18 using System
.Threading
;
20 using NUnit
.Framework
;
22 using Castle
.DynamicProxy
.Test
.Classes
;
23 using Castle
.DynamicProxy
.Test
.Interceptors
;
27 public class MultithreadTestCase
29 private ManualResetEvent _startEvent
= new ManualResetEvent(false);
30 private ManualResetEvent _stopEvent
= new ManualResetEvent(false);
31 private SpecializedServiceClass _service
;
33 private ProxyGenerator _generator
;
38 _generator
= new ProxyGenerator();
42 public void MultithreadTest()
44 _service
= (SpecializedServiceClass
) _generator
.CreateClassProxy(
45 typeof(SpecializedServiceClass
),
46 new ResultModifiedInvocationHandler( ) );
48 const int threadCount
= 10;
50 Thread
[] threads
= new Thread
[threadCount
];
52 for(int i
= 0; i
< threadCount
; i
++)
54 threads
[i
] = new Thread(new ThreadStart(ExecuteMethodUntilSignal
));
60 Thread
.CurrentThread
.Join(1 * 2000);
65 public void ExecuteMethodUntilSignal()
67 _startEvent
.WaitOne(int.MaxValue
, false);
69 while (!_stopEvent
.WaitOne(1, false))
71 Assert
.AreEqual( 44, _service
.Sum( 20, 25 ) );
72 Assert
.AreEqual( -6, _service
.Subtract( 20, 25 ) );
73 Assert
.AreEqual( true, _service
.Valid
);