lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Digy" <digyd...@gmail.com>
Subject RE: lucene 2.3.1 tag
Date Fri, 09 Jan 2009 16:59:00 GMT
I tested the new version of WeakHashTable with the code below, with the code
in LUCENENET-106(Paches for v2.3.1.rar
<https://issues.apache.org/jira/secure/attachment/12384768/Paches+for+v2.3.1
.rar> :Form1.cs) and all Lucene.Net nunit tests. All tests pass but any
comments are also welcome.

 

DIGY.

 

 

<pre>

using System;

using System.Collections.Generic;

using System.Text;

using NUnit.Framework;

 

namespace Lucene.Net._Support

{

    [TestFixture]

    public class TestWeakHashTable

    {

        [Test]

        public void A_TestBasicOps()

        {

            SupportClass.WeakHashTable weakHashTable = new
SupportClass.WeakHashTable();

            System.Collections.Hashtable realHashTable = new
System.Collections.Hashtable();

 

            SmallObject[] so = new SmallObject[100];

 

            for (int i = 0; i < 20000; i++)

            {

                SmallObject key = new SmallObject(i);

                SmallObject value = key;

 

                so[i/200] = key;

 

                realHashTable.Add(key, value);

                weakHashTable.Add(key, value);

            }

            Assert.AreEqual(weakHashTable.Count, realHashTable.Count);

 

            System.Collections.ICollection keys =
(System.Collections.ICollection)weakHashTable.Keys;

            foreach(SmallObject key in keys)

            {

                Assert.AreEqual(((SmallObject)realHashTable[key]).i,
((SmallObject)weakHashTable[key]).i);

                Assert.IsTrue( realHashTable[key].Equals(weakHashTable[key])
);

            }

 

            System.Collections.ICollection values1 =
(System.Collections.ICollection)weakHashTable.Values;

            System.Collections.ICollection values2 =
(System.Collections.ICollection)realHashTable.Values;

            Assert.AreEqual(values1.Count, values2.Count);

 

            realHashTable.Remove(new SmallObject(10000));

            weakHashTable.Remove(new SmallObject(10000));

            Assert.AreEqual(weakHashTable.Count, 20000);

            Assert.AreEqual(realHashTable.Count, 20000);

            

            for (int i = 0; i < so.Length; i++)

            {

                realHashTable.Remove(so[i]);

                weakHashTable.Remove(so[i]);

                Assert.AreEqual(weakHashTable.Count, 20000-i-1);

                Assert.AreEqual(realHashTable.Count, 20000-i-1);

            }

 

            //After removals, compare the collections again.

            System.Collections.ICollection keys2 =
(System.Collections.ICollection)realHashTable.Keys;

            foreach (SmallObject o in keys2)

            {

                Assert.AreEqual(((SmallObject)realHashTable[o]).i,
((SmallObject)weakHashTable[o]).i);

                Assert.IsTrue(realHashTable[o].Equals(weakHashTable[o]));

            }

 

            //Test Enumerator

            long count1 = 0;

            foreach (System.Collections.DictionaryEntry so1 in
realHashTable)

            {

                count1 += ((SmallObject)so1.Value).i;

            }

 

            long count2 = 0;

            foreach (System.Collections.DictionaryEntry so2 in
weakHashTable)

            {

                count2 += ((SmallObject)so2.Value).i;

            }

            Console.WriteLine(count1 + " =?= " +  count2);

            Assert.AreEqual(count1, count2);

        }

 

        [Test]

        public void B_TestOutOfMemory()

        {

            SupportClass.WeakHashTable wht = new
SupportClass.WeakHashTable();

            for (int i = 0; i < 1024*8+32; i++)  // requested Mem. > 8GB

            {

                wht.Add(new BigObject(i), i);

            }

            GC.Collect();

            Console.WriteLine("Passed out of memory exception.");

        }

 

        int GetMemUsageInKB()

        {

            return System.Diagnostics.Process.GetCurrentProcess().WorkingSet
/ 1024;

        }

 

        [Test]

        public void C_TestMemLeakage()

        {

            SupportClass.WeakHashTable wht = new
SupportClass.WeakHashTable();

            

            int initialMemUsage = GetMemUsageInKB();

            Console.WriteLine("Initial MemUsage=" + initialMemUsage);

 

            for (int i = 0; i < 10000; i++)

            {

                wht.Add(new BigObject(i), i);

                if (i % 100 == 0)

                {

                    int mu = GetMemUsageInKB();

                    Console.WriteLine(i.ToString() + ") MemUsage=" + mu);

                }

            }

 

            GC.Collect();

            int memUsage = GetMemUsageInKB();

            if (memUsage > initialMemUsage * 2) Assert.Fail("Memory Leakage.
MemUsage=" + memUsage);

        }

    }

    

    class BigObject

    {

        public int i = 0;

        public byte[] buf = null;

        public BigObject(int i)

        {

            this.i = i;

            buf = new byte[1024 * 1024]; //1MB

        }

    }

 

    class SmallObject

    {

        public int i = 0;

        public SmallObject(int i)

        {

            this.i = i;

        }

    }

}

 

</pre>

 

-----Original Message-----
From: George Aroush [mailto:george@aroush.net] 
Sent: Friday, January 09, 2009 2:26 PM
To: lucene-net-dev@incubator.apache.org
Subject: RE: lucene 2.3.1 tag

 

I'm in the process of reviewing Doug's patch for 2.3.2 (LUCENENET-164).  I

should have it done in a week or so.  Three is also a need to review the

latest patch from DIGY for the WeakHashMap fix (LUCENENET-106).  Any

volunteers?

 

-- George

 

> -----Original Message-----

> From: TJ Kolev [mailto:tjkolev@gmail.com] 

> Sent: Thursday, January 08, 2009 3:18 PM

> To: lucene-net-dev@incubator.apache.org

> Subject: Re: lucene 2.3.1 tag

> 

> Greetings,

> 

> How close is a 2.3.2 release/tag? What tasks are left?

> 

> Thank you.

> tjk :)

> 

> On Tue, Dec 16, 2008 at 5:12 PM, Digy <digydigy@gmail.com> wrote:

> > Probably, there will be no tag for 2.3.1. But 2.3.2 is on the way. 

> > Stay tuned.

> >

> > DIGY.

> >

> > -----Original Message-----

> > From: Dotzenrod, Kevin [mailto:kdotzenrod@marketwatch.com]

> > Sent: Monday, December 15, 2008 7:57 PM

> > To: lucene-net-dev@incubator.apache.org

> > Subject: lucene 2.3.1 tag

> >

> > Any idea when there will be a tag for Lucene.net version 2.3.1.

> >

> >

> >

> > Thanks,

> >

> >

> >

> > Kevin

> >

> >

> >

> 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message