public
Description:
Homepage: http://www.iserviceoriented.com
Clone URL: git://github.com/jezell/iserviceoriented.git
100644 68 lines (55 sloc) 1.618 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
 
using System.ServiceModel;
 
namespace IServiceOriented.ServiceBus.UnitTests
{
[ServiceContract]
    public interface IContract
    {
[OperationContract(IsOneWay=true, Action="PublishThis")]
        void PublishThis(string message);
    }
 
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
    public class ContractImplementation : IContract
    {
        #region IContract Members
 
        int callCount = 0;
        int publishedCount = 0;
        volatile int failCount = 0;
        int failInterval = 0;
 
 
        public void PublishThis(string message)
        {
            int value = Interlocked.Increment(ref callCount);
 
            if (value <= failCount || (failInterval != 0 && value % failInterval == 0))
            {
                throw new Exception("Fail " + value);
            }
            else
            {
                PublishedMessages[Interlocked.Increment(ref publishedCount) - 1] = message;
            }
        }
 
        public void SetFailCount(int value)
        {
            failCount = value;
            callCount = 0;
        }
 
        public void SetFailInterval(int value)
        {
            failInterval = value;
        }
 
        public int PublishedCount
        {
            get
            {
                return publishedCount;
            }
        }
 
        public const int MAX_MESSAGES = 10000;
        public string[] PublishedMessages = new string[MAX_MESSAGES];
 
        #endregion
    }
}