Ejemplo n.º 1
0
        public void TestAccumulatingWithCache()
        {
            var cache =
                new UpgradedCache
                <Guid, TestClass, NoReferenceUpdatableElement <TestClass> >(true,
                                                                            Comparer <Guid> .Default, EqualityComparer <Guid> .Default,
                                                                            a => a());
            var acc = new Accumulator <Guid, TestClass>(
                cache.Push,
                cache.HasActualValue,
                k => cache.RetrieveByFunc(k, o => new TestClass {
                Test = k.ToString()
            }),
                k => k.ToDictionary(k2 => k2, k2 => new TestClass {
                Test = k2.ToString()
            }));
            var count = 100000;
            var keys  = Enumerable.Range(0, count).Select(_ => Guid.NewGuid()).ToArray();

            var t1 = Get(acc, keys.Take(count / 3));

            var res1 = t1.ContinueWith(tt =>
            {
                GC.Collect(2, GCCollectionMode.Forced);
                return(Get2(tt.Result));
            });
            var t2 = t1.ContinueWith(tt2 => Get(acc, keys.Skip(count / 3).Take(count / 3))
                                     .ContinueWith(t =>
            {
                GC.Collect
                    (2, GCCollectionMode.Forced);
                return(Get2(t.Result));
            }));

            var res3 = Get(acc, keys.Skip(count / 3 * 2).ToArray())
                       .ContinueWith(t =>
            {
                GC.Collect(2, GCCollectionMode.Forced);
                return(Get2(t.Result));
            });

            Assert.AreEqual(res1.Result.Count(k => k != null), count / 3);
            Assert.AreEqual(t2.Result.Result.Count(k => k != null), count / 3);
            Assert.AreEqual(res3.Result.Count(k => k != null), count - count / 3 * 2);
        }
Ejemplo n.º 2
0
        public void TestAccumulatingWithCache()
        {
            var cache =
                new UpgradedCache
                    <Guid, TestClass, NoReferenceUpdatableElement<TestClass>>(true,
                    Comparer<Guid>.Default,  EqualityComparer<Guid>.Default,
                                                                a => a());
            var acc = new Accumulator<Guid, TestClass>(
                cache.Push, 
                cache.HasActualValue,
                k => cache.RetrieveByFunc(k, o => new TestClass {Test = k.ToString()}),
                k => k.ToDictionary(k2 => k2, k2 => new TestClass {Test = k2.ToString()}));
            var count = 100000;
            var keys = Enumerable.Range(0, count).Select(_ => Guid.NewGuid()).ToArray();

            var t1 = Get(acc, keys.Take(count/3));

            var res1 = t1.ContinueWith(tt =>
                                           {
                                               GC.Collect(2, GCCollectionMode.Forced);
                                               return Get2(tt.Result);
                                           });
            var t2 = t1.ContinueWith(tt2 => Get(acc, keys.Skip(count/3).Take(count/3))
                                                .ContinueWith(t =>
                                                                  {
                                                                      GC.Collect
                                                                          (2,  GCCollectionMode.Forced);
                                                                      return  Get2(t.Result);
                                                                  }));

            var res3 = Get(acc, keys.Skip(count/3*2).ToArray())
                             .ContinueWith(t =>
                                  {
                                      GC.Collect(2, GCCollectionMode.Forced);
                                      return Get2(t.Result);
                                  });

            Assert.AreEqual(res1.Result.Count(k => k!=null),count/3);
            Assert.AreEqual(t2.Result.Result.Count(k => k != null), count/3);
            Assert.AreEqual(res3.Result.Count(k => k != null), count -  count / 3*2);
        }