public void ChildContextHandle_ThreadLocal() { IContextHandle threadLocalCCH = beanContext.GetService <IContextHandle>(THREADLOCAL_CCH); IServiceContext threadLocalChildContext1 = threadLocalCCH.Start(); IServiceContext threadLocalChildContext2 = threadLocalCCH.Start(); Assert.AreSame(threadLocalChildContext1, threadLocalChildContext2); CountdownEvent countDownLatch = new CountdownEvent(1); System.Threading.ThreadPool.QueueUserWorkItem(delegate(Object state) { IServiceContext threadLocalChildContext1_2 = threadLocalCCH.Start(); IServiceContext threadLocalChildContext2_2 = threadLocalCCH.Start(); Assert.AreSame(threadLocalChildContext1_2, threadLocalChildContext2_2); Assert.AreNotSame(threadLocalChildContext1_2, threadLocalChildContext1); countDownLatch.Signal(); threadLocalCCH.Stop(); Assert.IsTrue(threadLocalChildContext1_2.IsDisposed); Assert.IsFalse(threadLocalChildContext1.IsDisposed); }, null); if (!countDownLatch.Wait(TimeSpan.FromMilliseconds(5000))) { throw new TimeoutException("Thread did not respond"); } Assert.IsFalse(threadLocalChildContext1.IsDisposed); threadLocalCCH.Stop(); Assert.IsTrue(threadLocalChildContext1.IsDisposed); }
public void ChildContextHandle_With_Factory_Singleton() { IContextHandle singletonCCH = beanContext.GetService <IContextHandle>(SINGLETON_CCH_WITH_CCF); IServiceContext childContext = singletonCCH.Start(); IList <int> testList = childContext.GetService <IList <int> >(); Assert.AreEqual(testList.Count, 2); }
public void ChildContextHandle_Singleton() { IContextHandle singletonCCH = beanContext.GetService <IContextHandle>(SINGLETON_CCH); IServiceContext singletonChildContext1 = singletonCCH.Start(); IServiceContext singletonChildContext2 = singletonCCH.Start(); Assert.AreSame(singletonChildContext1, singletonChildContext2); singletonCCH.Stop(); Assert.IsTrue(singletonChildContext1.IsDisposed); }
public void ChildContextHandle_Prototype() { IContextHandle prototypeCCH = beanContext.GetService <IContextHandle>(PROTOTYPE_CCH); IServiceContext prototypeChildContext1 = prototypeCCH.Start(); IServiceContext prototypeChildContext2 = prototypeCCH.Start(); Assert.AreNotSame(prototypeChildContext1, prototypeChildContext2); prototypeCCH.Stop(); Assert.IsTrue(prototypeChildContext1.IsDisposed); Assert.IsTrue(prototypeChildContext2.IsDisposed); }