public virtual void TestInitValue()
        {
            DisposableThreadLocal <object> tl = new DisposableThreadLocal <object>(() => TEST_VALUE);
            string str = (string)tl.Value;

            Assert.AreEqual(TEST_VALUE, str);
        }
        public virtual void TestDefaultValueWithoutSetting()
        {
            // LUCENE-1805: make sure default get returns null,
            // twice in a row
            DisposableThreadLocal <object> ctl = new DisposableThreadLocal <object>();

            Assert.IsNull(ctl.Get());
        }
        public virtual void TestNullValue()
        {
            // Tests that null can be set as a valid value (LUCENE-1805). this
            // previously failed in get().
            DisposableThreadLocal <object> ctl = new DisposableThreadLocal <object>();

            ctl.Set(null);
            Assert.IsNull(ctl.Get());
        }
Ejemplo n.º 4
0
            public void Register(DisposableThreadLocal <T> parent)
            {
                _parents.Add(parent.selfReference);
                int localVersion  = _localState.localVersion;
                var globalVersion = DisposableThreadLocal <T> .globalVersion;

                if (localVersion != globalVersion)
                {
                    // a thread local instance was disposed, let's check
                    // if we need to do cleanup here
                    RemoveDisposedParents();
                    _localState.localVersion = globalVersion;
                }
            }