Exemple #1
0
        private static void RunDELETE(ProgramArguments arguments)
        {
            var entities = SystemStartTests.CreateTestEntities();
            var aces     = new List <StoredAce>
            {
                new StoredAce {
                    EntityId = Id("E1"), IdentityId = Id("U1"), LocalOnly = false, AllowBits = 0x0EF, DenyBits = 0x000
                },
                new StoredAce {
                    EntityId = Id("E4"), IdentityId = Id("U1"), LocalOnly = false, AllowBits = 0x000, DenyBits = 0x0FF
                }
            };
            var storage = new DatabaseStorage {
                Aces = aces, Memberships = new List <Membership>(), Entities = entities, Messages = new List <Tuple <int, DateTime, byte[]> >()
            };

            StartTheSystem(new MemoryDataProvider(storage));

            var retryCount  = 100;
            var threadCount = 6;
            var mainWatch   = Stopwatch.StartNew();

            for (var i = 0; i < retryCount; i++)
            {
                _stopped = false;

                // build the deep test enity tree
                DELETEBuildSubtree();

                var sw = Stopwatch.StartNew();

                // start permission checker loops
                var tasks = new List <Task>();

                // start a delete task for an entity in the middle
                tasks.Add(Task.Run(() =>
                {
                    Trace.WriteLine("SECDEL> Start DEL thread.");
                    Thread.Sleep(10);
                    var delWatch = Stopwatch.StartNew();
                    SecurityContextForConcurrencyTests.General.DeleteEntity(60);
                    delWatch.Stop();
                    Trace.WriteLine(string.Format("SECDEL> End DEL thread. Elapsed time: {0}", delWatch.ElapsedMilliseconds));
                    _stopped = true;
                }));

                tasks.AddRange(Enumerable.Range(1, threadCount).Select(x => Task.Run(() => DELETECheckPermission(x))).ToList());

                Task.WaitAll(tasks.ToArray());

                sw.Stop();

                Console.WriteLine("Iteration {0}. Duration: {1} sec", i, Math.Round(sw.Elapsed.TotalSeconds));
                Trace.WriteLine(string.Format("SECDEL> Iteration {0}. Duration: {1} sec", i, Math.Round(sw.Elapsed.TotalSeconds)));
            }

            mainWatch.Stop();

            Console.WriteLine("Retry count: {0}. Errors: {1}. Elapsed time: {2}", retryCount, errors, Math.Round(mainWatch.Elapsed.TotalSeconds));
            Console.WriteLine();
        }