Exemplo n.º 1
0
        public FailoverReactor(IHostReactor hostReactor, string cacheDir)
        {
            _hostReactor = hostReactor;
            _failoverDir = Path.Combine(cacheDir, FAILOVER_PATH);

            Init();
        }
Exemplo n.º 2
0
        public FailoverReactorTest()
        {
            _serviceMap = new ConcurrentDictionary <string, ServiceInfo>();
            var orderServiceInfo = new ServiceInfo();

            orderServiceInfo.Name      = "tms_order_v1";
            orderServiceInfo.GroupName = "tms";
            orderServiceInfo.Clusters  = "test";
            var orderInstance = new Instance()
            {
                InstanceId  = "1",
                Ip          = "192.168.1.50",
                Port        = 5000,
                Weight      = 1,
                ClusterName = "test",
                ServiceName = "tms_order_v1"
            };

            orderInstance.Metadata.Add("k1", "v1");
            orderServiceInfo.Hosts.Add(orderInstance);
            orderServiceInfo.LastRefTime = DateTime.Now.GetTimeStamp();

            var inquiryServiceInfo = new ServiceInfo();

            inquiryServiceInfo.Name      = "tms_inquiry_v1";
            inquiryServiceInfo.GroupName = "tms";
            inquiryServiceInfo.Clusters  = "test";
            var inquiryInstance = new Instance()
            {
                InstanceId  = "2",
                Ip          = "192.168.1.51",
                Port        = 5000,
                Weight      = 1,
                ClusterName = "test",
                ServiceName = "tms_order_v1"
            };

            inquiryInstance.Metadata.Add("k2", "v2");
            inquiryServiceInfo.Hosts.Add(inquiryInstance);
            inquiryServiceInfo.LastRefTime = DateTime.Now.GetTimeStamp();

            _serviceMap.TryAdd(orderServiceInfo.GetKey(), orderServiceInfo);
            _serviceMap.TryAdd(inquiryServiceInfo.GetKey(), inquiryServiceInfo);

            var mockHostReactor = new Mock <IHostReactor>();

            mockHostReactor.Setup(x => x.GetServiceInfoMap()).Returns(_serviceMap);

            _hostReactor = mockHostReactor.Object;
        }