Allows setting concurrency levels for ITaskScheduler
For hashing and Equals comparisons the Name is always used.
상속: IWorkGroup
예제 #1
0
 public void Create_Zero_Concurrency_Fails()
 {
     Assert.Throws<ArgumentException>(
     delegate
     {
         var test = new WorkGroup(Name, 0, 0);
         Assert.Null(test);
     });
 }
예제 #2
0
 public void Create_Null_Constructor_Fails()
 {
     Assert.Throws<ArgumentNullException>(
     delegate
     {
         var test = new WorkGroup(null, 0, 0);
         Assert.Null(test);
     });
 }
예제 #3
0
        /// <summary>
        /// Adds a new work group.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="concurrencyLevel">The concurrency level.</param>
        /// <param name="maxQueueSize">Maximum size of the queue. Work groups have a queue that is separate per queue, and is not shared with non work group items</param>
        /// <returns></returns>
        /// <exception cref="DotNetWorkQueueException">Start must be called on the scheduler before adding work groups</exception>
        public override IWorkGroup AddWorkGroup(string name, int concurrencyLevel, int maxQueueSize)
        {
            ThrowIfDisposed();

            var group = new WorkGroup(name, concurrencyLevel, maxQueueSize);

            if (_groups.ContainsKey(group))
            {
                return(_groups[group].GroupInfo);
            }

            var groupWithItem = new WorkGroupWithItem(group, _metrics.Counter(
                                                          $"work group {name}", Units.Items));

            _groups.TryAdd(group, groupWithItem);
            return(groupWithItem.GroupInfo);
        }
예제 #4
0
        /// <summary>
        /// Adds a new work group.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="concurrencyLevel">The concurrency level.</param>
        /// <param name="maxQueueSize">Maximum size of the queue. Work groups have a queue that is separate per queue, and is not shared with non work group items</param>
        /// <returns></returns>
        /// <exception cref="DotNetWorkQueueException">Start must be called on the scheduler before adding work groups</exception>
        public override IWorkGroup AddWorkGroup(string name, int concurrencyLevel, int maxQueueSize)
        {
            ThrowIfDisposed();

            if (_smartThreadPool == null)
            {
                throw new DotNetWorkQueueException("Start must be called on the scheduler before adding work groups");
            }

            var group = new WorkGroup(name, concurrencyLevel, maxQueueSize);

            if (_groups.ContainsKey(group))
            {
                return(_groups[group].GroupInfo);
            }

            var groupWithItem = new WorkGroupWithItem(group, Policy.Bulkhead(concurrencyLevel, maxQueueSize, OnBulkheadRejected), _metrics.Counter(
                                                          $"work group {name}", Units.Items));

            _groups.TryAdd(group, groupWithItem);
            return(groupWithItem.GroupInfo);
        }
예제 #5
0
        /// <summary>
        /// Adds a new work group.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="concurrencyLevel">The concurrency level.</param>
        /// <param name="maxQueueSize">Maximum size of the queue. Work groups have a queue that is separate per queue, and is not shared with non work group items</param>
        /// <returns></returns>
        /// <exception cref="DotNetWorkQueueException">Start must be called on the scheduler before adding work groups</exception>
        public override IWorkGroup AddWorkGroup(string name, int concurrencyLevel, int maxQueueSize)
        {
            ThrowIfDisposed();

            if (_smartThreadPool == null)
                throw new DotNetWorkQueueException("Start must be called on the scheduler before adding work groups");

            var group = new WorkGroup(name, concurrencyLevel, maxQueueSize);
            if (_groups.ContainsKey(group)) return _groups[group].GroupInfo;

            var startInfo = new WIGStartInfo
            {
                PostExecuteWorkItemCallback = PostExecuteWorkItemCallback
            };
            var groupWithItem = new WorkGroupWithItem(group, _smartThreadPool.CreateWorkItemsGroup(concurrencyLevel, startInfo), _metrics.Counter(
                $"work group {name}", Units.Items));
            _groups.TryAdd(group, groupWithItem);
            return groupWithItem.GroupInfo;
        }
예제 #6
0
 public void Test_NotEquals()
 {
     var test = new WorkGroup(Name, 1, 10);
     var test2 = new WorkGroup("notequal", 50, 50);
     Assert.False(test.Equals(test2));
 }
예제 #7
0
 public void Test_Equals()
 {
     var test = new WorkGroup(Name, 1, 10);
     var test2 = new WorkGroup(Name, 50, 50);
     Assert.True(test.Equals(test2));
 }
예제 #8
0
 public void Test_ToString()
 {
     var test = new WorkGroup(Name, 1, 10);
     Assert.Equal(Name, test.ToString());
 }
예제 #9
0
 public void GetSet_MaxQueueSize()
 {
     var test = new WorkGroup(Name, 1, 10);
     Assert.Equal(10, test.MaxQueueSize);
 }
예제 #10
0
 public void GetSet_Concurrency()
 {
     var test = new WorkGroup(Name, 1, 0);
     Assert.Equal(1, test.ConcurrencyLevel);
 }
예제 #11
0
 public void Test_HashCode_Equals()
 {
     var test = new WorkGroup(Name, 1, 10);
     var test2 = new WorkGroup(Name, 50, 50);
     Assert.Equal(test.GetHashCode(), test2.GetHashCode());
 }
예제 #12
0
 public void Create_Zero_Queue_Ok()
 {
    var test = new WorkGroup(Name, 1, 0);
    Assert.Equal(0, test.MaxQueueSize);
 }
예제 #13
0
 public void Test_Hash_Multi()
 {
     var tests = new Dictionary<WorkGroup, WorkGroup>(100000);
     for (var i = 0; i < 100000; i++)
     {
         var test = new WorkGroup(string.Concat(Name, i.ToString()), i+1, i);
         tests.Add(test, test);
     }
     Assert.Equal(100000, tests.Count);
 }
예제 #14
0
        public void Test_Hash()
        {
            var tests = new Dictionary<WorkGroup, WorkGroup>();
            var test = new WorkGroup(Name, 1, 10);
            var test2 = new WorkGroup("Another name", 50, 50);
   
            tests.Add(test, test);
            tests.Add(test2, test2);

            Assert.Equal(2, tests.Count);
            Assert.Equal(test, tests[test]);
            Assert.Equal(test2, tests[test2]);
            Assert.NotEqual(test, tests[test2]);
        }
예제 #15
0
        public void Test_Hash_Duplicate_Fails()
        {
            // ReSharper disable once CollectionNeverQueried.Local
            var tests = new Dictionary<WorkGroup, WorkGroup>();
            var test = new WorkGroup(Name, 1, 10);
            var test2 = new WorkGroup(Name, 50, 50);

            tests.Add(test, test);
            Assert.Throws<ArgumentException>(
           delegate
           {
               tests.Add(test2, test2);
           });
        }
예제 #16
0
 public void Test_HashCode_NotEquals()
 {
     var test = new WorkGroup(Name, 1, 10);
     var test2 = new WorkGroup("Another Name", 50, 50);
     Assert.NotEqual(test.GetHashCode(), test2.GetHashCode());
 }
예제 #17
0
 public void GetSet_Name()
 {
     var test = new WorkGroup(Name, 1, 0);
     Assert.Equal(Name, test.Name);
 }
예제 #18
0
 public void Test_Equals_Null_False()
 {
     var test = new WorkGroup(Name, 1, 10);
     Assert.False(test.Equals(null));
 }