private protected RaftClusterMember(ILocalMember localMember, IPEndPoint endPoint, IClientMetricsCollector?metrics)
 {
     this.localMember = localMember;
     this.metrics     = metrics;
     Endpoint         = endPoint;
     status           = new AtomicEnum <ClusterMemberStatus>(ClusterMemberStatus.Unknown);
 }
Example #2
0
 internal RaftClusterMember(IHostingContext context, Uri remoteMember, Uri resourcePath)
     : base(context.CreateHttpHandler(), true)
 {
     this.resourcePath = resourcePath;
     this.context      = context;
     status            = new AtomicEnum <ClusterMemberStatus>(ClusterMemberStatus.Unknown);
     BaseAddress       = remoteMember;
     Endpoint          = remoteMember.ToEndPoint() ?? throw new UriFormatException(ExceptionMessages.UnresolvedHostName(remoteMember.Host));
     DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(UserAgent, (GetType().Assembly.GetName().Version ?? new Version()).ToString()));
 }
Example #3
0
        public void AtomicityEnum()
        {
            var atomic = new AtomicEnum <Companies>(Companies.Value1);

            void ExchangeTask()
            {
                atomic.Value++;
            }

            Task.WaitAll(
                Task.Run(ExchangeTask),
                Task.Run(ExchangeTask));

            Assert.GreaterOrEqual(2, (int)atomic.Value);
        }
Example #4
0
        public void AtomicEnum_CompareAndSet_ThreadSafe_Test()
        {
            AtomicEnum <Warehouse> atomic = new AtomicEnum <Warehouse>(Warehouse.Sjgo);
            var casResult = new ConcurrentDictionary <int, bool>();
            var tasks     = Enumerable.Range(1, 50).Select(key =>
            {
                return(Task.Factory.StartNew(() =>
                {
                    casResult.TryAdd(key, atomic.CompareAndSet(Warehouse.Sjgo, Warehouse.Kgil));
                }));
            });

            Task.WaitAll(tasks.ToArray());
            Assert.IsTrue(casResult.Values.Count(val => val == true) == 1);
        }