public virtual void TestThreadCorrectness()
        {
            const int NUM_THREADS = 4;
            const int CACHE_SIZE = 512;
            int OBJ_COUNT = 3 * CACHE_SIZE;

            DoubleBarrelLRUCache<CloneableObject, object> c = new DoubleBarrelLRUCache<CloneableObject, object>(1024);

            CloneableObject[] objs = new CloneableObject[OBJ_COUNT];
            for (int i = 0; i < OBJ_COUNT; i++)
            {
                objs[i] = new CloneableObject(new object());
            }

            CacheThread[] threads = new CacheThread[NUM_THREADS];
            DateTime endTime = DateTime.Now.AddSeconds(1);
            for (int i = 0; i < NUM_THREADS; i++)
            {
                threads[i] = new CacheThread(this, c, objs, endTime);
                threads[i].Start();
            }
            for (int i = 0; i < NUM_THREADS; i++)
            {
                threads[i].Join();
                Assert.False(threads[i].Failed);
            }
            //System.out.println("hits=" + totHit + " misses=" + totMiss);
        }
Exemple #2
0
        public virtual void TestThreadCorrectness()
        {
            const int NUM_THREADS = 4;
            const int CACHE_SIZE  = 512;
            int       OBJ_COUNT   = 3 * CACHE_SIZE;

            DoubleBarrelLRUCache <CloneableObject, object> c = new DoubleBarrelLRUCache <CloneableObject, object>(1024);

            CloneableObject[] objs = new CloneableObject[OBJ_COUNT];
            for (int i = 0; i < OBJ_COUNT; i++)
            {
                objs[i] = new CloneableObject(new object());
            }

            CacheThread[] threads = new CacheThread[NUM_THREADS];
            DateTime      endTime = DateTime.Now.AddSeconds(1);

            for (int i = 0; i < NUM_THREADS; i++)
            {
                threads[i] = new CacheThread(this, c, objs, endTime);
                threads[i].Start();
            }
            for (int i = 0; i < NUM_THREADS; i++)
            {
                threads[i].Join();
                Assert.False(threads[i].failed);
            }
            //System.out.println("hits=" + totHit + " misses=" + totMiss);
        }
Exemple #3
0
        public virtual void TestThreadCorrectness()
        {
            const int NUM_THREADS = 4;
            const int CACHE_SIZE  = 512;
            int       OBJ_COUNT   = 3 * CACHE_SIZE;

            DoubleBarrelLRUCache <CloneableObject, object> c = new DoubleBarrelLRUCache <CloneableObject, object>(1024);

            CloneableObject[] objs = new CloneableObject[OBJ_COUNT];
            for (int i = 0; i < OBJ_COUNT; i++)
            {
                objs[i] = new CloneableObject(new object());
            }

            CacheThread[] threads = new CacheThread[NUM_THREADS];
            long          endTime = (J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond) + 1000L; // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results

            for (int i = 0; i < NUM_THREADS; i++)
            {
                threads[i] = new CacheThread(this, c, objs, endTime);
                threads[i].Start();
            }
            for (int i = 0; i < NUM_THREADS; i++)
            {
                threads[i].Join();
                Assert.False(threads[i].failed);
            }
            //System.out.println("hits=" + totHit + " misses=" + totMiss);
        }
 public CacheThread(TestDoubleBarrelLRUCache outerInstance, DoubleBarrelLRUCache<CloneableObject, object> c, CloneableObject[] objs, long endTime)
 {
     this.OuterInstance = outerInstance;
     this.c = c;
     this.Objs = objs;
     this.EndTime = endTime;
 }
Exemple #5
0
        public void CopyObject_WithNullSource_ThrowsException()
        {
            // Arrange
            _obj = null;

            // Act
            _obj.CopyObject();
        }
Exemple #6
0
        public void CopyObject_WithNestedCollection_CopiesNestedCollection()
        {
            // Arrange
            var nestedObjCollection = new List <CloneableObject>();

            var nestedObjCollectionObject = new CloneableObject();

            nestedObjCollection.Add(nestedObjCollectionObject);

            _obj.PublicCollection = nestedObjCollection;
            _advObj.NestedObject  = _obj;

            // Act
            var advClone = _advObj.CopyObject();
            var nestedObjCollectionClone = advClone.NestedObject.PublicCollection;

            // Assert
            Assert.IsTrue(nestedObjCollectionClone != nestedObjCollection);
        }
Exemple #7
0
            public override void Run()
            {
                try
                {
                    long count = 0;
                    long miss  = 0;
                    long hit   = 0;
                    int  limit = objs.Length;

                    while (true)
                    {
                        CloneableObject obj = objs[(int)((count / 2) % limit)];
                        object          v   = c.Get(obj);
                        if (v == null)
                        {
                            c.Put(new CloneableObject(obj), obj);
                            miss++;
                        }
                        else
                        {
                            Assert.True(obj == v);
                            hit++;
                        }
                        if ((++count % 10000) == 0)
                        {
                            if (DateTime.Now.CompareTo(endTime) > 0)
                            {
                                break;
                            }
                        }
                    }

                    outerInstance.AddResults(miss, hit);
                }
                catch (Exception t)
                {
                    failed = true;
                    throw new Exception(t.Message, t);
                }
            }
Exemple #8
0
            public override void Run()
            {
                try
                {
                    long count = 0;
                    long miss  = 0;
                    long hit   = 0;
                    int  limit = objs.Length;

                    while (true)
                    {
                        CloneableObject obj = objs[(int)((count / 2) % limit)];
                        object          v   = c.Get(obj);
                        if (v == null)
                        {
                            c.Put(new CloneableObject(obj), obj);
                            miss++;
                        }
                        else
                        {
                            Assert.True(obj == v);
                            hit++;
                        }
                        if ((++count % 10000) == 0)
                        {
                            if (J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond > endTime) // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results
                            {
                                break;
                            }
                        }
                    }

                    outerInstance.AddResults(miss, hit);
                }
                catch (Exception t) when(t.IsThrowable())
                {
                    failed = true;
                    throw RuntimeException.Create(t);
                }
            }
Exemple #9
0
 public void Initialize()
 {
     _obj    = new CloneableObject();
     _advObj = new CloneableObjectWithNestedClass();
 }
 protected override void CloneOverride(CloneableObject clonableObject)
 {
     ((GoodCloneableObject)clonableObject).SomeProperty = SomeProperty;
 }
 protected override void CloneOverride(CloneableObject clonableObject)
 {
     // It is a good practice to call the parent's CloneOverride in case
     // some properties must be set there.
     base.CloneOverride(clonableObject);
     ((GoodCloneableObject)clonableObject).SomeProperty = SomeProperty;
 }
 protected override void CloneOverride(CloneableObject clonableObject)
 {
     // Not calling the base implementation version = bad.
     ((GoodCloneableObject)clonableObject).SomeProperty = SomeProperty;
 }