Example #1
0
        public void OneKeyTenThousandCalls()
        {
            const string key   = "'gamma";
            const int    count = 10000;

            var results = Enumerable.Range(0, count).Select(index => TimeIndex.GetUnique(key)).ToArray();

            CheckOneKeyResults(results);
        }
Example #2
0
        public void DifferentKeys()
        {
            const string keyA = "'keyA";
            const string keyB = "'keyB";
            const string keyC = "'keyC";

            var resultA = TimeIndex.GetUnique(keyA);
            var resultB = TimeIndex.GetUnique(keyB);
            var resultC = TimeIndex.GetUnique(keyC);

            Assert.AreEqual(0, resultA.Index);
            Assert.AreEqual(0, resultB.Index);
            Assert.AreEqual(0, resultC.Index);
        }
Example #3
0
        public FileName GetFileName()
        {
            string    key       = String.Join("_", Segments);
            TimeIndex timeIndex = TimeIndex.GetUnique(key);

            string dateTimeText = GetDateTimeText(timeIndex.DateTime);
            string value        = dateTimeText + "__" + key;

            if (timeIndex.Index > 0)
            {
                value += "_" + timeIndex.Index;
            }

            value += ".xml";

            var fileName = new FileName(value, timeIndex.DateTime);

            return(fileName);
        }
Example #4
0
        public void OneKeyMultipleTasks()
        {
            const string key   = "'alpha";
            const int    count = 1000;

            var taskArray = Enumerable.Range(0, count).Select(index =>
                                                              new Task <TimeIndex>(() =>
            {
                var timeIndex = TimeIndex.GetUnique(key);
                Trace.WriteLine("Result = " + timeIndex + " Index = " + index.ToString("000") + " ThreadId = " + Thread.CurrentThread.ManagedThreadId);
                return(timeIndex);
            }
                                                                                   )).ToArray();

            Array.ForEach(taskArray, task => task.Start());
            Task.WaitAll(taskArray);

            var results = taskArray.Select(task => task.Result).ToArray();

            CheckOneKeyResults(results);
        }
Example #5
0
        public void OneKeyMultipleThreads()
        {
            const string key   = "'beta";
            const int    count = 1000;

            var results = new TimeIndex[count];

            var threadArray = Enumerable.Range(0, count).Select(index =>
                                                                new Thread(() =>
            {
                var timeIndex = TimeIndex.GetUnique(key);
                Trace.WriteLine("Result = " + timeIndex + " Index = " + index.ToString("000") + " ThreadId = " + Thread.CurrentThread.ManagedThreadId);
                results[index] = timeIndex;
            }
                                                                           )).ToArray();


            Array.ForEach(threadArray, thread => thread.Start());
            Array.ForEach(threadArray, thread => thread.Join());

            CheckOneKeyResults(results);
        }