예제 #1
0
        private CorruptedMemosDbRecovery MarkFailureAndTryRecover()
        {
            BuildXLContext context;
            IConfiguration configuration;

            CreateContextAndConfiguration(out context, out configuration);

            WriteFakeMemosDb(context, configuration);

            FailureRecoveryAggregator recovery = FailureRecoveryFactory.Create(LoggingContext, context.PathTable, configuration);
            bool markFailure = recovery.TryMarkFailure(new BuildXLException(string.Empty), ExceptionRootCause.CorruptedCache);

            XAssert.IsTrue(markFailure);

            var corruptedMemosDbRecovery = new CorruptedMemosDbRecovery(context.PathTable, configuration);

            XAssert.IsTrue(corruptedMemosDbRecovery.ShouldRecover());

            CreateContextAndConfiguration(out context, out configuration);
            recovery = FailureRecoveryFactory.Create(LoggingContext, context.PathTable, configuration);

            bool tryRecover = recovery.TryRecoverIfNeeded();

            XAssert.IsTrue(tryRecover);

            corruptedMemosDbRecovery = new CorruptedMemosDbRecovery(context.PathTable, configuration);
            XAssert.IsFalse(File.Exists(GetMemosDbPath(context, configuration)));

            return(corruptedMemosDbRecovery);
        }
 public void XHWriterTest()
 {
     string tradeNumber = Guid.NewGuid().ToString(); ; // TODO: 初始化为适当的值
     string channelID = Guid.NewGuid().ToString(); ; // TODO: 初始化为适当的值
     FailureRecoveryFactory.XHWriter(tradeNumber, channelID);
    // Assert.Inconclusive("无法验证不返回值的方法。");
 }
예제 #3
0
        public void TestCatastrophicFailureRecovery()
        {
            // Run some valid module
            SetupTestData();
            RunEngine();

            // List the files in the engine cache after a valid run
            var engineCacheDirectory = Configuration.Layout.EngineCacheDirectory.ToString(Context.PathTable);
            var engineCacheFilesList = new List <string>();

            FileUtilities.EnumerateDirectoryEntries(engineCacheDirectory, (file, attributes) =>
            {
                if (!attributes.HasFlag(FileAttributes.Directory))
                {
                    engineCacheFilesList.Add(file);
                }
            });

            var recovery = FailureRecoveryFactory.Create(LoggingContext, Context.PathTable, Configuration);

            // This will trigger the recovery mechanism for unknown catastrophic errors, which is to log and remove the engine state (EngineCache folder)
            XAssert.IsTrue(recovery.TryMarkFailure(new BuildXLException("fake failure"), ExceptionRootCause.Unknown));

            // List the files in the logs directory for corrupt engine cache files
            var logsDirectory = Configuration.Logging.EngineCacheCorruptFilesLogDirectory.ToString(Context.PathTable);
            var logsFilesList = new HashSet <string>();

            FileUtilities.EnumerateDirectoryEntries(logsDirectory, (file, attributes) =>
            {
                logsFilesList.Add(file);
            });

            var childrenCount = Directory.GetFiles(engineCacheDirectory, "*", SearchOption.TopDirectoryOnly).Length;
            var expectedCount = -1;

            // File content table has a special exclusion from the removal policy for performance reasons, but it should still be copied to logs
            // (Unless the file content table doesn't exist in the engine cache, then it doesn't need to exist in the logs)
            var engineCacheFileContentTablePath = Configuration.Layout.FileContentTableFile.ToString(Context.PathTable);
            var fileContentTableFile            = Path.GetFileName(engineCacheFileContentTablePath);

            // Make sure file content table was copied to logs
            XAssert.Contains(logsFilesList, fileContentTableFile);
            expectedCount = 1;

            // Make sure file content table file exists in the engine cache directory after recovery
            XAssert.IsTrue(File.Exists(engineCacheFileContentTablePath));

            // Check to make sure the engine cache directory is empty except for maybe the file content table
            XAssert.AreEqual(expectedCount, childrenCount);

            // Check to make sure all the file from the engine cache directory ended up in the logs directory
            foreach (var file in engineCacheFilesList)
            {
                XAssert.Contains(logsFilesList, file);
            }
        }
예제 #4
0
        /// <summary>
        /// 读取交易规则及基础数据
        /// </summary>
        private static void DoBaseData()
        {
            //已经在ScheduleManger中初始化
            //MCService.CommonPara.Reset();
            //MCService.CommonPara.Initialize();

            LogHelper.WriteInfo("------------证券开市处理-DoBaseData");
            try
            {
                MCService.Reset();

                AccountManager.Instance.Reset();

                #region  old code  注释 --李健华 2010-06-09
                ////交易员工厂封装类进行重置
                //VTTradersFactory.Reset();
                //VTTradersFactory.GetStockTraders();
                //VTTradersFactory.GetFutureTraders();
                #endregion
                RealTimeMarketUtil.GetInstance().Reset();
                LocalCommonValidater.Reset();

                #region ===回推故障数据导入 Create by:李健华 Create date:2009-08-12===

                FailureRecoveryFactory.XHReaderToDB();

                #endregion ===回推故障数据导入 End===

                var rescueManager = RescueManager.Instance;

                LogHelper.WriteInfo("------------完成证券开市处理-DoBaseData");
            }
            catch (Exception ex)
            {
                LogHelper.WriteError(ex.ToString(), ex);
                LogHelper.WriteInfo("------------证券开市处理失败-DoBaseData");
            }
        }
예제 #5
0
        /// <summary>
        /// 读取交易规则及基础数据
        /// </summary>
        private static void DoBaseData()
        {
            LogHelper.WriteInfo("------------期货开市处理-DoBaseData");

            try
            {
                MCService.FuturesTradeRules.Reset();
                MCService.FuturesTradeRules.Initialize();

                #region ===回推故障数据导入 Create by:李健华 Create date:2009-08-12===

                FailureRecoveryFactory.QHReaderToDB();

                #endregion ===回推故障数据导入 End===

                LogHelper.WriteInfo("------------完成期货开市处理-DoBaseData");
            }
            catch (Exception ex)
            {
                LogHelper.WriteError(ex.ToString(), ex);
                LogHelper.WriteInfo("------------期货开市处理失败-DoBaseData");
            }
        }
 public void XHReaderToDBTest()
 {
     FailureRecoveryFactory.XHReaderToDB();
     Assert.Inconclusive("无法验证不返回值的方法。");
 }
 public void FailureRecoveryFactoryConstructorTest()
 {
     FailureRecoveryFactory target = new FailureRecoveryFactory();
     Assert.Inconclusive("TODO: 实现用来验证目标的代码");
 }
        /// <summary>
        /// 开始启动,进行初始化
        /// </summary>
        public static bool Start(ref string errMsg)
        {
            if (scheduler != null)
            {
                if (scheduler.IsStarted)
                {
                    return(true);
                }
            }

            //DaoUtil.Initialize();
            //删除正常退出标志
            //DaoUtil.DeleteNormalFlag();
            bool isConnectionOk = DaoUtil.TestConnection();

            if (!isConnectionOk)
            {
                errMsg = "无法连接数据库,请检查配置文件!";
                LogHelper.WriteDebug("ScheduleManager.Start" + errMsg);
                return(false);
            }

            stockOpenJob   = new StockOpenProcessJob();
            stockCloseJob  = new StockCloseProcessJob();
            futureOpenJob  = new FutureOpenProcessJob();
            futureCloseJob = new FutureCloseProcessJob();

            stockMelonCutting = new StockMelonCuttingJob();
            try
            {
                //启动内存表管理器
                //MemoryDataManager.Start();

                //===回推故障数据导入 Start===
                FailureRecoveryFactory.QHReaderToDB();
                FailureRecoveryFactory.XHReaderToDB();
                FailureRecoveryFactory.HKReaderToDB();
                //===回推故障数据导入 End===

                ISchedulerFactory schedFact = new StdSchedulerFactory();
                scheduler = schedFact.GetScheduler();

                MCService.CommonPara.Reset();
                MCService.CommonPara.Initialize();

                InitializeTriggers();

                LogHelper.WriteInfo("ScheduleManager.Start");
                scheduler.Start();

                DoOpenProcess();
                DoCloseProcess();

                #region 已经在DoOpenProcess中期货中有执行不再处理
                ////add 2010-03-16 添加对期货的清算判断,如果发现前一日没有清算完成则设置期货是否清算异常系统暂停交易,使用期台不能下单
                //DateTime ReckoningDateTime;
                //bool isReckoning = false;
                //isReckoning = StatusTableChecker.IsFutureReckoningFaultRecovery(out ReckoningDateTime, out errMsg);
                //if (isReckoning)
                //{
                //    IList<CM_BreedClass> list = MCService.CommonPara.GetAllBreedClass();
                //    foreach (var item in list)
                //    {
                //        if (item.BreedClassTypeID.Value == (int)GTA.VTS.Common.CommonObject.Types.BreedClassTypeEnum.CommodityFuture ||
                //            item.BreedClassTypeID.Value == (int)GTA.VTS.Common.CommonObject.Types.BreedClassTypeEnum.StockIndexFuture)
                //        {
                //            IsFutureReckoningErrorStopTrade = true;
                //            break;
                //        }
                //    }
                //}
                #endregion
                //==================

                IsStartSuccess = true;
            }
            catch (Exception ex)
            {
                LogHelper.WriteInfo("ScheduleManger start failure!");
                LogHelper.WriteError(ex.ToString(), ex);

                IsStartSuccess = false;
                return(false);
            }

            LogHelper.WriteInfo("ScheduleManger start success!");
            return(true);
        }