示例#1
0
        public void GetDispatchedExpiredTest()
        {
            MdnManager target = CreateManager();

            InitMdnRecords();

            //timespan and max records set
            var mdns = target.GetExpiredDispatched(TimeSpan.FromMinutes(10), 20);

            Assert.Equal(10, mdns.Count());

            //timespan and max records set
            mdns = target.GetExpiredDispatched(TimeSpan.FromMinutes(10), 10);
            Assert.Equal(10, mdns.Count());

            //timespan and max records set
            //Nothing this old yet.
            mdns = target.GetExpiredDispatched(TimeSpan.FromMinutes(11), 10);
            Assert.Equal(0, mdns.Count());

            //timespan and max records set
            mdns = target.GetExpiredDispatched(TimeSpan.FromMinutes(10), 5);
            Assert.Equal(5, mdns.Count());

            //default expiredLimit (10 minutes) and maxResults (10)
            mdns = target.GetExpiredDispatched();
            Assert.Equal(10, mdns.Count());
        }
示例#2
0
        public void StoreTest()
        {
            MdnManager  target = CreateManager();
            ConfigStore actual = target.Store;

            Assert.Equal(target.Store, actual);
        }
示例#3
0
        public void GetProcessExpiredTest()
        {
            MdnManager target = CreateManager();

            InitMdnRecords();

            //timespan and max records set
            var mdns = target.GetExpiredProcessed(TimeSpan.FromMinutes(10), 10);

            Assert.Equal(10, mdns.Count());

            //timespan and max records set
            mdns = target.GetExpiredProcessed(TimeSpan.FromMinutes(10), 5);
            Assert.Equal(5, mdns.Count());

            //timespan and max records set
            mdns = target.GetExpiredProcessed(TimeSpan.FromMinutes(10), 40);
            Assert.Equal(20, mdns.Count());

            //timespan and max records set
            mdns = target.GetExpiredProcessed(TimeSpan.FromMinutes(11), 40);
            Assert.Equal(0, mdns.Count());

            //default maxrecords set
            mdns = target.GetExpiredProcessed(TimeSpan.FromMinutes(10));
            Assert.Equal(10, mdns.Count());

            //default expieredLimit and maxResults
            mdns = target.GetExpiredProcessed();
            Assert.Equal(10, mdns.Count());
        }
示例#4
0
        public ConfigStore(string connectString, TimeSpan timeout)
        {
            if (string.IsNullOrEmpty(connectString))
            {
                throw new ArgumentException("connectString");
            }
            if (timeout.Ticks <= 0)
            {
                throw new ArgumentException("timeout");
            }

            m_timeout = timeout;
            m_connectString = connectString;
            m_domains = new DomainManager(this);
            m_addresses = new AddressManager(this);
            m_certificates = new CertificateManager(this);
            m_anchors = new AnchorManager(this);
            m_dnsRecords = new DnsRecordManager(this);
            m_administrators = new AdministratorManager(this);
            m_properties = new PropertyManager(this);
            m_blobs = new NamedBlobManager(this);
            m_Mdns = new MdnManager(this);
            m_bundles = new BundleManager(this);
            m_certPolicies = new CertPolicyManager(this, new CertPolicyParseValidator());
            m_certPolicyGroups = new CertPolicyGroupManager(this);
        }
示例#5
0
        public void DuplicateMdnTest()
        {
            MdnManager target = CreateManager();

            InitMdnRecords();

            string messageId = Guid.NewGuid().ToString();
            Mdn    mdn       = BuildMdn("945cc145-431c-4119-a8c6-7f557e52fd7d", "*****@*****.**", "*****@*****.**", "To dispatch or not dispatch", "pRocessed");

            //Record first processed.
            Assert.Null(Record.Exception(() => target.Update(new Mdn[] { mdn })));

            //Throw duplicate processed
            Assert.Equal(ConfigStoreError.DuplicateProcessedMdn, Assert.Throws <ConfigStoreException>(() => target.Update(mdn)).Error);

            //Record first dispatched.
            mdn.Status = "disPatched";
            Assert.Null(Record.Exception(() => target.Update(mdn)));

            //Throw duplicate dispached
            Assert.Equal(ConfigStoreError.DuplicateDispatchedMdn, Assert.Throws <ConfigStoreException>(() => target.Update(mdn)).Error);

            mdn = BuildMdn(Guid.NewGuid().ToString(), "*****@*****.**", "*****@*****.**", "To dispatch or not dispatch", "fAiled");
            target.Start(new Mdn[] { mdn });

            Assert.Equal(ConfigStoreError.DuplicateFailedMdn, Assert.Throws <ConfigStoreException>(() => target.Update(mdn)).Error);
        }
示例#6
0
        public void TestDispatchedTimeOutToDSNFail()
        {
            //
            // Sample data
            //
            MdnManager target = CreateManager();

            InitMdnRecords();
            CleanMessages(PickupFolder);

            //timespan and max records set
            var mdns = target.GetExpiredDispatched(TimeSpan.FromMinutes(10), 40);

            Assert.Equal(10, mdns.Count());

            MdnDispatchedTimeout dispatchedTimeout = new MdnDispatchedTimeout();

            //Execute unprocessed records over 11 minutes old.
            JobExecutionContext context = CreateDispatchedJobExecutionContext(11, 5);

            dispatchedTimeout.Execute(context);

            //Nothing was processed
            mdns = target.GetExpiredDispatched(TimeSpan.FromMinutes(10), 40);
            Assert.Equal(10, mdns.Count());

            var files = Directory.GetFiles(PickupFolder);

            Assert.Equal(0, files.Count());

            //Execute unprocessed records over 10 minutes old.
            context = CreateDispatchedJobExecutionContext(10, 5);
            dispatchedTimeout.Execute(context);

            //10 records left
            mdns = target.GetExpiredDispatched(TimeSpan.FromMinutes(10), 40);
            Assert.Equal(5, mdns.Count());

            files = Directory.GetFiles(PickupFolder);
            Assert.Equal(5, files.Count());

            //Do it again
            dispatchedTimeout.Execute(context);
            mdns = target.GetExpiredDispatched(TimeSpan.FromMinutes(10), 40);
            Assert.Equal(0, mdns.Count());

            files = Directory.GetFiles(PickupFolder);
            Assert.Equal(10, files.Count());

            foreach (var file in files)
            {
                Message loadedMessage = Message.Load(File.ReadAllText(file));
                Assert.True(loadedMessage.IsDSN());
                Assert.Equal("multipart/report", loadedMessage.ParsedContentType.MediaType);
                Assert.Equal("Rejected:To dispatch or not dispatch", loadedMessage.SubjectValue);
                var dsnActual = DSNParser.Parse(loadedMessage);
                Assert.Equal(DSNStandard.DSNAction.Failed, dsnActual.PerRecipient.First().Action);
                Assert.Equal("5.4.72", dsnActual.PerRecipient.First().Status);
            }
        }
示例#7
0
        public void CleanProcessedAndDispatched()
        {
            MdnManager target = CreateManager();

            InitMdnRecords();

            //
            // Ensure all test data is procesed or dispatched
            //
            {
                var mdns = target.GetExpiredProcessed(TimeSpan.FromMinutes(0), 100);
                foreach (var mdn in mdns)
                {
                    mdn.Status = MdnStatus.Processed;
                    target.Update(mdn);
                }

                mdns = target.GetExpiredDispatched(TimeSpan.FromMinutes(0), 100);
                foreach (var mdn in mdns)
                {
                    mdn.Status = MdnStatus.Dispatched;
                    target.Update(mdn);
                }
            }
            Assert.Equal(0, target.GetExpiredProcessed(TimeSpan.FromMinutes(0), 100).Count());
            Assert.Equal(0, target.GetExpiredDispatched(TimeSpan.FromMinutes(0), 100).Count());

            System.Threading.Thread.Sleep(1000);
            target.RemoveDispositions(TimeSpan.FromSeconds(.001), 100);
            Assert.Equal(0, target.Count());
        }
示例#8
0
        public void GetByMdnIdentifierTest()
        {
            MdnManager target = CreateManager();

            InitMdnRecords();
            Assert.Equal(61, target.Count());
            Assert.NotNull(target.Get("9C2458C2370E2C00E2E8701EE3064B6B"));
        }
示例#9
0
        public void AddExceptionTest()
        {
            MdnManager target = CreateManager();

            InitMdnRecords();
            string messageId = Guid.NewGuid().ToString();
            Mdn    mdn       = BuildMdn("945cc145-431c-4119-a8c6-7f557e52fd7d", "*****@*****.**", "*****@*****.**", "To dispatch or not dispatch", MdnStatus.Started);

            Assert.Contains("Cannot insert duplicate key", Assert.Throws <SqlException>(() => target.Start(new Mdn[] { mdn })).Message);
        }
示例#10
0
        /// <summary>
        ///A test for expired Mdn Dispatched Timer
        ///</summary>
        //[Fact ] May want this check to go into the timeout job.
        public void MissingAggregateMdnTest()
        {
            MdnManager target = CreateManager();

            InitMdnRecords();

            string messageId = Guid.NewGuid().ToString();
            Mdn    mdn       = BuildMdn("945cc145-431c-4119-a8c6-7f557e52fd7d", "*****@*****.**",
                                        "*****@*****.**", "To dispatch or not dispatch", "pRocessed");

            Assert.Equal(ConfigStoreError.MdnUncorrelated, Assert.Throws <ConfigStoreException>(() => target.Update(new Mdn[] { mdn })).Error);
        }
示例#11
0
        public void GetTimeoutTest()
        {
            MdnManager target = CreateManager();

            InitMdnRecords();

            //This would run often enough to keep the Mdns table peformant
            var mdns = target.GetTimedOut();

            Assert.Equal(0, mdns.Count());

            mdns = target.GetExpiredProcessed(TimeSpan.FromMinutes(10), 2);
            Assert.Equal(2, mdns.Count());

            target.TimeOut(mdns);


            mdns = target.GetTimedOut();
            Assert.Equal(2, mdns.Count());

            target.RemoveTimedOut(TimeSpan.FromSeconds(1), 100);
            mdns = target.GetTimedOut();
            Assert.Equal(0, mdns.Count());


            //
            //Two seperate updates
            //

            //Update thread one
            mdns = target.GetExpiredProcessed(TimeSpan.FromMinutes(10), 2);
            Assert.Equal(2, mdns.Count());


            target.TimeOut(mdns);


            //update thread two
            mdns = target.GetExpiredProcessed(TimeSpan.FromMinutes(10), 2);
            Assert.Equal(2, mdns.Count());

            target.TimeOut(mdns);



            mdns = target.GetTimedOut();
            Assert.Equal(4, mdns.Count());

            target.RemoveTimedOut(TimeSpan.FromSeconds(1), 100);
            mdns = target.GetTimedOut();
            Assert.Equal(0, mdns.Count());
        }
示例#12
0
        /// <summary>
        /// This method will clean, load and verify MDN records in the DB for testing purposes
        /// </summary>
        /// <param name="mgr">MdnManager instance used for controlling the Mdn records</param>
        /// <param name="db">ConfigDatabase instance used as the target storage mechanism for the records</param>
        protected void InitOldMdnRecords(MdnManager mgr, ConfigDatabase db)
        {
            mgr.RemoveAll();
            mgr.Start(db, TestOldMdns.ToArray());

            //----------------------------------------------------------------------------------------------------
            //---submit changes to db and verify existence of records
            db.SubmitChanges();
            foreach (KeyValuePair <long, KeyValuePair <int, string> > kp in TestAddressNames)
            {
                //Assert.NotNull(mgr.Get(kp.Value.Value));
            }
        }
示例#13
0
        public void AddTest()
        {
            MdnManager target = CreateManager();

            target.RemoveAll();
            Assert.Equal(0, target.Count());
            string messageId = Guid.NewGuid().ToString();
            var    mdn       = BuildMdn(messageId, "*****@*****.**", "*****@*****.**", "To dispatch or not dispatch", MdnStatus.Started);

            target.Start(new Mdn[] { mdn });
            mdn = target.Get(mdn.MdnIdentifier);
            Assert.Equal(MdnStatus.Started, mdn.Status);
            Assert.Equal("To dispatch or not dispatch", mdn.SubjectValue);
        }
示例#14
0
        public void ProcessingProcessExpiredTest()
        {
            MdnManager target = CreateManager();

            InitMdnRecords();

            //timespan and max records set
            var mdns = target.GetExpiredProcessed(TimeSpan.FromMinutes(10), 2);

            Assert.Equal(2, mdns.Count());
            target.TimeOut(mdns);
            mdns = target.GetExpiredProcessed(TimeSpan.FromMinutes(10), 20);
            Assert.Equal(18, mdns.Count());
            target.TimeOut(mdns);
            mdns = target.GetExpiredProcessed(TimeSpan.FromMinutes(10), 20);
            Assert.Equal(0, mdns.Count());
        }
示例#15
0
        public void UpdateStatusTest()
        {
            MdnManager target = CreateManager();

            InitMdnRecords();
            var mdn = target.Get("9C2458C2370E2C00E2E8701EE3064B6B");

            Assert.Equal(MdnStatus.Started, mdn.Status);

            mdn.Status = MdnStatus.Processed;
            target.Update(mdn);
            mdn = target.Get("0335BF2715F5607DE9FC5BF249BEF7F9");
            Assert.Equal(MdnStatus.Processed, mdn.Status);
            mdn.Status = MdnStatus.Dispatched;
            target.Update(mdn);
            mdn = target.Get("543AE91DFFDE40754BCB0A11CEEED059");
            Assert.Equal(MdnStatus.Dispatched, mdn.Status);
        }
示例#16
0
        public void UpdateDispatchedTest()
        {
            MdnManager target = CreateManager();

            InitMdnRecords();
            var mdn = target.Get("9C2458C2370E2C00E2E8701EE3064B6B");

            Assert.Equal(MdnStatus.Started, mdn.Status);

            //
            // Skip processed step is allowed.
            // An external timer will move to Timed out
            //
            mdn.Status = MdnStatus.Dispatched;
            target.Update(mdn);
            mdn = target.Get("543AE91DFFDE40754BCB0A11CEEED059");
            Assert.Equal(MdnStatus.Dispatched, mdn.Status);
        }
示例#17
0
        public void UpdateTimeoutTest()
        {
            MdnManager target = CreateManager();

            InitMdnRecords();
            var mdn = target.Get("9C2458C2370E2C00E2E8701EE3064B6B");

            Assert.Equal(MdnStatus.Started, mdn.Status);

            //
            // Skip processed step is allowed.
            // An external timer will move to Timed out
            //

            target.TimeOut(mdn);
            mdn = target.Get("68167934227A8EBF247E6AC345CC02D1");
            Assert.Equal(MdnStatus.TimedOut, mdn.Status);
        }
示例#18
0
文件: Timeout.cs 项目: DM-TOR/nhin-d
        /// <summary>
        /// Load applicatioin settings and job settings
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        protected TimeoutSettings Load(JobExecutionContext context)
        {
            try
            {
                var settings = new TimeoutSettings(context);
                m_store = new ConfigStore(settings.ConnectionString, settings.QueryTimeout);
                m_logger = Log.For(this);
                
                MDNManager = new MdnManager(new ConfigStore(settings.ConnectionString));

                return settings;
            }
            catch (Exception e)
            {
                WriteToEventLog(e);
                var je = new JobExecutionException(e);
                je.UnscheduleAllTriggers = true;
                throw je;
            }
        }
示例#19
0
        /// <summary>
        /// Load applicatioin settings and job settings
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        protected TimeoutSettings Load(JobExecutionContext context)
        {
            try
            {
                var settings = new TimeoutSettings(context);
                m_store  = new ConfigStore(settings.ConnectionString, settings.QueryTimeout);
                m_logger = Log.For(this);

                MDNManager = new MdnManager(new ConfigStore(settings.ConnectionString));

                return(settings);
            }
            catch (Exception e)
            {
                WriteToEventLog(e);
                var je = new JobExecutionException(e);
                je.UnscheduleAllTriggers = true;
                throw je;
            }
        }
示例#20
0
        public void TestTimeoutCleanup()
        {
            //
            // Sample data
            //
            MdnManager target = CreateManager();

            InitOldMdnRecords();

            CleanDispositions dispositions = new CleanDispositions();

            Assert.Equal(91, target.Count());

            //No records older than 10 days.
            JobExecutionContext context = CreateCleanTimeoutJobExecutionContext(11);

            dispositions.Execute(context);
            Assert.Equal(91, target.Count());

            //Should clean up 10 dispatched timeout and 10 processed timeout and their corresponding starts
            context = CreateCleanTimeoutJobExecutionContext(9);
            dispositions.Execute(context);
            Assert.Equal(51, target.Count());
        }