Пример #1
0
        public virtual void TestInitValue()
        {
            LightWeightThreadLocal <object> tl = new LightWeightThreadLocal <object>(_ => TEST_VALUE);
            string str = (string)tl.Get();

            Assert.AreEqual(TEST_VALUE, str);
        }
Пример #2
0
        public virtual void TestDefaultValueWithoutSetting()
        {
            // LUCENE-1805: make sure default get returns null,
            // twice in a row
            LightWeightThreadLocal <object> ctl = new LightWeightThreadLocal <object>();

            Assert.IsNull(ctl.Get());
        }
Пример #3
0
        public virtual void TestNullValue()
        {
            // Tests that null can be set as a valid value (LUCENE-1805). this
            // previously failed in get().
            LightWeightThreadLocal <object> ctl = new LightWeightThreadLocal <object>();

            ctl.Set(null);
            Assert.IsNull(ctl.Get());
        }
Пример #4
0
        private ThreadResources GetThreadResources(IState state)
        {
            ThreadResources resources = threadResources.Get(state);

            if (resources == null)
            {
                resources = new ThreadResources {
                    termEnum = Terms(state)
                };
                // Cache does not have to be thread-safe, it is only used by one thread at the same time
                threadResources.Set(resources);
            }
            return(resources);
        }