Exemple #1
0
        public void Set_MultipeTasks_NoExceptions()
        {
            // Arrange
            const int numberOfItems = 100;
            var       items         = Enumerable.Range(0, numberOfItems).Select(i => SimpleObject.Create()).ToArray();
            var       cache         = cacheFactory.CreateDefault <SimpleObject>();

            // Act
            var stopwatch  = System.Diagnostics.Stopwatch.StartNew();
            var loopResult = Parallel.For(0, 20, i =>
            {
                var index = i % numberOfItems;
                var item  = items[index];
                cache.Set(new CacheItem <SimpleObject>("item-" + index, item, TimeSpan.FromSeconds(5)));
            });

            stopwatch.Stop();

            // Assert
            _output.WriteLine($"Duration: {stopwatch.Elapsed}");
            Assert.True(loopResult.IsCompleted);
        }
        public void Get_MultipeTasks_NoExceptions()
        {
            // Arrange
            const int numberOfItems = 100;
            var       cache         = cacheFactory.CreateDefault <SimpleObject>();

            Enumerable.Range(0, numberOfItems)
            .Select(i => Tuple.Create("item-" + i, SimpleObject.Create()))
            .All(_ => { cache.Set(new CacheItem <SimpleObject>(_.Item1, _.Item2, TimeSpan.FromSeconds(5))); return(true); });

            // Act
            var stopwatch  = System.Diagnostics.Stopwatch.StartNew();
            var loopResult = Parallel.For(0, 20, i =>
            {
                var index  = i % numberOfItems;
                var result = cache.Get("item-" + index);
            });

            stopwatch.Stop();

            // Assert
            Console.WriteLine("Duration:" + stopwatch.ElapsedMilliseconds);
            Assert.True(loopResult.IsCompleted);
        }