lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [Lucene.Net] svn commit: r1162461 - in /incubator/lucene.net/branches/Lucene.Net_2_9_4g: src/core/ src/core/Support/ src/core/Util/ test/core/ test/core/Support/
Date Sun, 28 Aug 2011 00:27:14 GMT
Author: digy
Date: Sun Aug 28 00:27:14 2011
New Revision: 1162461

URL: http://svn.apache.org/viewvc?rev=1162461&view=rev
Log:
[LUCENENET-358] Test case added (Lucene.Net.Support.TestCloseableThreadLocal)

Added:
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Support/CloseableThreadLocalProfiler.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Support/TestCloseableThreadLocal.cs
Modified:
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Lucene.Net.csproj
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/CloseableThreadLocal-old.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/CloseableThreadLocal.cs
    incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Lucene.Net.Test.csproj

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Lucene.Net.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Lucene.Net.csproj?rev=1162461&r1=1162460&r2=1162461&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Lucene.Net.csproj (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Lucene.Net.csproj Sun Aug 28
00:27:14 2011
@@ -865,6 +865,7 @@
     <Compile Include="Support\BuildType.cs" />
     <Compile Include="Support\Character.cs" />
     <Compile Include="Support\Checksum.cs" />
+    <Compile Include="Support\CloseableThreadLocalProfiler.cs" />
     <Compile Include="Support\CollectionsHelper.cs" />
     <Compile Include="Support\Compare.cs" />
     <Compile Include="Support\CRC32.cs" />
@@ -897,7 +898,9 @@
     <Compile Include="Util\BitVector.cs">
       <SubType>Code</SubType>
     </Compile>
-    <Compile Include="Util\CloseableThreadLocal.cs" />
+    <Compile Include="Util\CloseableThreadLocal.cs">
+      <SubType>Code</SubType>
+    </Compile>
     <Compile Include="Util\Constants.cs">
       <SubType>Code</SubType>
     </Compile>

Added: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Support/CloseableThreadLocalProfiler.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Support/CloseableThreadLocalProfiler.cs?rev=1162461&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Support/CloseableThreadLocalProfiler.cs
(added)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Support/CloseableThreadLocalProfiler.cs
Sun Aug 28 00:27:14 2011
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Lucene.Net.Support
+{
+    /// <summary>
+    /// For Debuging purposes.
+    /// </summary>
+    public class CloseableThreadLocalProfiler
+    {
+        public static bool _EnableCloseableThreadLocalProfiler = false;
+        public static List<WeakReference> Instances = new List<WeakReference>();
+
+        public static bool EnableCloseableThreadLocalProfiler
+        {
+            get { return _EnableCloseableThreadLocalProfiler; }
+            set
+            {
+                _EnableCloseableThreadLocalProfiler = value;
+                lock (Instances)
+                    Instances.Clear();
+            }
+        }
+    }
+}

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/CloseableThreadLocal-old.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/CloseableThreadLocal-old.cs?rev=1162461&r1=1162460&r2=1162461&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/CloseableThreadLocal-old.cs
(original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/CloseableThreadLocal-old.cs
Sun Aug 28 00:27:14 2011
@@ -79,6 +79,16 @@ namespace Lucene.Net.Util
 		
 		public virtual void  Set(T object_Renamed)
 		{
+            //+-- For Debuging
+            if (Lucene.Net.Support.CloseableThreadLocalProfiler.EnableCloseableThreadLocalProfiler
== true)
+            {
+                lock (Lucene.Net.Support.CloseableThreadLocalProfiler.Instances)
+                {
+                    Lucene.Net.Support.CloseableThreadLocalProfiler.Instances.Add(new WeakReference(object_Renamed));
+                }
+            }
+            //+--
+
             if (slots == null)
                 slots = new Support.WeakDictionary<CloseableThreadLocal<T>, T>();
 

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/CloseableThreadLocal.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/CloseableThreadLocal.cs?rev=1162461&r1=1162460&r2=1162461&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/CloseableThreadLocal.cs
(original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Util/CloseableThreadLocal.cs
Sun Aug 28 00:27:14 2011
@@ -78,6 +78,16 @@ namespace Lucene.Net.Util
 
         public virtual void Set(T @object)
         {
+            //+-- For Debuging
+            if (Lucene.Net.Support.CloseableThreadLocalProfiler.EnableCloseableThreadLocalProfiler
== true)
+            {
+                lock (Lucene.Net.Support.CloseableThreadLocalProfiler.Instances)
+                {
+                    Lucene.Net.Support.CloseableThreadLocalProfiler.Instances.Add(new WeakReference(@object));
+                }
+            }
+            //+--
+
             t.Set(new WeakReference(@object));
 
             lock (hardRefs)

Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Lucene.Net.Test.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Lucene.Net.Test.csproj?rev=1162461&r1=1162460&r2=1162461&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Lucene.Net.Test.csproj (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Lucene.Net.Test.csproj Sun Aug
28 00:27:14 2011
@@ -418,6 +418,7 @@
       <SubType>Code</SubType>
     </Compile>
     <Compile Include="Support\CollisionTester.cs" />
+    <Compile Include="Support\TestCloseableThreadLocal.cs" />
     <Compile Include="Support\TestIDisposable.cs" />
     <Compile Include="Support\TestLRUCache.cs" />
     <Compile Include="Support\TestMediumTrust.cs" />

Added: incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Support/TestCloseableThreadLocal.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Support/TestCloseableThreadLocal.cs?rev=1162461&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Support/TestCloseableThreadLocal.cs
(added)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Support/TestCloseableThreadLocal.cs
Sun Aug 28 00:27:14 2011
@@ -0,0 +1,75 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using System.Threading;
+using System.Threading.Tasks;
+
+using Lucene.Net.Analysis;
+using Lucene.Net.Analysis.Standard;
+using Lucene.Net.Documents;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.Store;
+using NUnit.Framework;
+
+namespace Lucene.Net.Support
+{
+    [TestFixture]
+    public class TestCloseableThreadLocal
+    {
+        [Test]
+        public void TestMemLeakage()
+        {
+            Lucene.Net.Support.CloseableThreadLocalProfiler.EnableCloseableThreadLocalProfiler
= true;
+
+            int LoopCount = 100;
+            Analyzer[] analyzers = new Analyzer[LoopCount];
+            RAMDirectory[] dirs = new RAMDirectory[LoopCount];
+            IndexWriter[] indexWriters = new IndexWriter[LoopCount];
+
+            Parallel.For(0, LoopCount, (i) => {
+                analyzers[i] = new StandardAnalyzer();
+                dirs[i] = new RAMDirectory();
+                indexWriters[i] = new IndexWriter(dirs[i], analyzers[i], true);
+            });
+
+            Parallel.For(0, LoopCount, (i) =>
+            {
+                Document document = new Document();
+                document.Add(new Field("field", "some test", Field.Store.NO, Field.Index.ANALYZED));
+                indexWriters[i].AddDocument(document);
+            });
+
+            Parallel.For(0, LoopCount, (i) =>
+            {
+                analyzers[i].Close();
+                indexWriters[i].Close();
+            });
+
+            Parallel.For(0, LoopCount, (i) =>
+            {
+                IndexSearcher searcher = new IndexSearcher(dirs[i]);
+                TopDocs d = searcher.Search(new TermQuery(new Term("field", "test")), 10);
+                searcher.Close();
+            });
+
+            Parallel.For(0, LoopCount, (i) =>dirs[i].Close());
+
+            GC.Collect(GC.MaxGeneration);
+            GC.WaitForPendingFinalizers();
+
+            int aliveObjects = 0;
+            foreach (WeakReference w in Lucene.Net.Support.CloseableThreadLocalProfiler.Instances)
+            {
+                object o = w.Target;
+                if (o != null) aliveObjects++;
+            }
+
+            Lucene.Net.Support.CloseableThreadLocalProfiler.EnableCloseableThreadLocalProfiler
= true;
+
+            Assert.AreEqual(0, aliveObjects);
+        }
+    }
+}



Mime
View raw message