public void Execute(IJobExecutionContext context) { int tryCount = 0; startJob: try { StatisticDataProcessor statisticDataProcessor = new StatisticDataProcessor(ObjectFactory.GetInstance<IRedisService>()); statisticDataProcessor.SaveStatisticData(StatisticActionType.App_PV); statisticDataProcessor.SaveStatisticData(StatisticActionType.App_Download); statisticDataProcessor.SaveStatisticData(StatisticActionType.App_Downloaded); statisticDataProcessor.SaveStatisticData(StatisticActionType.Market_31); } catch (Exception ex) { LogHelper.WriteError(string.Format("{0}\r\n{1}", ex.Message, ex.StackTrace)); if (tryCount < RETRYCOUNT) { if (tryCount == 0) { System.Threading.Thread.Sleep(60000); } else if (tryCount == 1) { System.Threading.Thread.Sleep(3600000); } else if (tryCount == 2) { System.Threading.Thread.Sleep(43200000); } tryCount++; goto startJob; } } }
public void Market31() { var redis = new RedisService(); var appstoreService = new AppStoreService(MockFileService.Object, redis, MockAppStoreUIService.Object, MockFullTextSearchService.Object,MockIMEICacheService.Object); _processor = new StatisticDataProcessor(redis); _processor.oracleRepo = MockOracleRepo.Object; var globalKey = _processor.GetKey(StatisticConsts.Market31.GLOBAL_IMEI); redis.AddItemToSet(globalKey, "0"); //var globalIMEIList = new List<string> { "0" }; // the exist imei is 0 only appstoreService.MarketStatistic(MarketStatisticType.Market31, DateTime.Now.AddDays(-1), GetMobileParam("N1", "F1", "0")); appstoreService.MarketStatistic(MarketStatisticType.Market31, DateTime.Now.AddDays(-1), GetMobileParam("N1", "F1", "1")); appstoreService.MarketStatistic(MarketStatisticType.Market31, DateTime.Now.AddDays(-1), GetMobileParam("N2", "F1", "2")); appstoreService.MarketStatistic(MarketStatisticType.Market31, DateTime.Now.AddDays(-1), GetMobileParam("N1", "F2", "3")); appstoreService.MarketStatistic(MarketStatisticType.Market31, DateTime.Now.AddDays(-1), GetMobileParam("N2", "F2", "4")); //setup oracle MockOracleRepo.Setup(x => x.Find<Market31StatisticSummary>(It.IsAny<Expression<Func<Market31StatisticSummary, bool>>>())).Returns(default(IList<Market31StatisticSummary>)); MockOracleRepo.Setup(x => x.Find<Market31ActiveUserUVStatistic>(It.IsAny<Expression<Func<Market31ActiveUserUVStatistic, bool>>>())).Returns(default(IList<Market31ActiveUserUVStatistic>)); MockOracleRepo.Setup(x => x.Find<Market31AddUserUVStatistic>(It.IsAny<Expression<Func<Market31AddUserUVStatistic, bool>>>())).Returns(default(IList<Market31AddUserUVStatistic>)); MockOracleRepo.Setup(x => x.Find<Market31PVStatistic>(It.IsAny<Expression<Func<Market31PVStatistic, bool>>>())).Returns(default(IList<Market31PVStatistic>)); MockOracleRepo.Setup(x => x.Add<Market31StatisticSummary>(It.IsAny<Market31StatisticSummary>())); MockOracleRepo.Setup(x => x.Add<Market31AddUserUVStatistic>(It.IsAny<Market31AddUserUVStatistic>())); MockOracleRepo.Setup(x => x.Add<Market31ActiveUserUVStatistic>(It.IsAny<Market31ActiveUserUVStatistic>())); MockOracleRepo.Setup(x => x.Add<Market31PVStatistic>(It.IsAny<Market31PVStatistic>())); _processor.SaveStatisticData(StatisticActionType.Market_31); // verify MockOracleRepo.Verify(x => x.Add<Market31StatisticSummary>(It.IsAny<Market31StatisticSummary>()), Times.Exactly(2)); MockOracleRepo.Verify(x => x.Add<Market31AddUserUVStatistic>(It.IsAny<Market31AddUserUVStatistic>()), Times.Exactly(4)); MockOracleRepo.Verify(x => x.Add<Market31ActiveUserUVStatistic>(It.IsAny<Market31ActiveUserUVStatistic>()), Times.Exactly(4)); MockOracleRepo.Verify(x => x.Add<Market31PVStatistic>(It.IsAny<Market31PVStatistic>()), Times.Exactly(4)); var globalIMEICount = redis.GetAllItemsFromSet(globalKey); Assert.Equal(5, globalIMEICount.Count); }