コード例 #1
0
        public void BatchActionDescriptorTest_BatchNameActionNameConfigurationChange()
        {
            //arrange
            var batchActionDescriptor = new BatchActionDescriptor();

            //act
            batchActionDescriptor.BatchConfiguration.Add(new KeyValuePair <string, object>(BatchConfigurationFieldName.BatchName, "batchname"));
            batchActionDescriptor.BatchConfiguration.Add(new KeyValuePair <string, object>(BatchConfigurationFieldName.BatchActionName, "actionname"));
            batchActionDescriptor.refreshBatchNameAndBatchAction();

            //assert
            Assert.Equal("batchname", batchActionDescriptor.BatchName);
            Assert.Equal("actionname", batchActionDescriptor.ActionName);
        }
コード例 #2
0
        public static DateTime GetNextExecutionDate(this BatchActionDescriptor batchActionDescriptor)
        {
            DateTime nextExecutionDate = DateTime.Now.AddSeconds(10);
            var      configItem        = batchActionDescriptor.BatchConfiguration["NextSkeduledDate"];

            if (configItem == null)
            {
                batchActionDescriptor.SetNextExecutionDate(nextExecutionDate);
            }
            else
            {
                nextExecutionDate = (DateTime)((KeyValuePair <string, object>)configItem).Value;
            }

            return(nextExecutionDate);
        }
コード例 #3
0
        public void ConfigAttributeExecutorTest_Execute()
        {
            //Arrange
            List <TypeInfo> types = new List <TypeInfo>();

            types.Add(typeof(SimplePOCOConfgigurationAttributeBatch).GetTypeInfo());
            var actionsDescriptor        = AssemblyDiscoveryActionDescription.actionDescription(types.AsEnumerable());
            BatchActionDescriptor action = actionsDescriptor.First();

            var configureAttributeExecutor = new ConfigAttributeExecutor();

            //Act
            configureAttributeExecutor.execute(ref action);

            //Assert
            Assert.Equal("BatchName", action.BatchName);
        }
コード例 #4
0
        public static void Reskedule(this BatchActionDescriptor batchActionDescriptor, DateTime currentDate)
        {
            var      skedulerToken = batchActionDescriptor.BatchConfiguration["SkedulerToken"];
            DateTime nextDate;

            if (skedulerToken == null)
            {
                var skedulerTimeSpan = batchActionDescriptor.BatchConfiguration["SkedulerTimeSpan"];
                nextDate = currentDate.Add((TimeSpan)((KeyValuePair <string, object>)skedulerTimeSpan).Value);
            }
            else
            {
                nextDate = CrontabParser.getNextDateTime((string)((KeyValuePair <string, object>)skedulerToken).Value, currentDate);
            }

            batchActionDescriptor.SetNextExecutionDate(nextDate);
        }
コード例 #5
0
        public static Task invoke(BatchActionDescriptor batchActionDescriptor, IOptions <SkedulerSettings> options, ILogger <BatchInvoker> logger)
        {
            return(Task.Run(async() =>
            {
                var client = new HttpClient();
                var baseAddress = options.Value.BaseUri;//  "http://localhost:8080/batch";
                client = new HttpClient();
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.BaseAddress = new Uri(baseAddress);

                var response = await client.GetAsync($"/batch/exec/{batchActionDescriptor.BatchName}/{batchActionDescriptor.ActionName}");
                if (!response.IsSuccessStatusCode)
                {
                    logger.LogError($"Error on calling batch : {batchActionDescriptor.BatchName} Action : {batchActionDescriptor.ActionName} on base url: {baseAddress}");
                }
            }));
        }
コード例 #6
0
        public async void BatchActionProviderTest_SimplePOCOBatchNoMethodMatch()
        {
            List <TypeInfo> types = new List <TypeInfo>();

            types.Add(typeof(SimplePOCOBatch).GetTypeInfo());

            //act
            IEnumerable <BatchActionDescriptor> actionDescriptions = new BatchActionDescriptor[0];


            var batchUrlManager = new Mock <IBatchUrlManager>(MockBehavior.Strict);

            batchUrlManager.Setup((s) => s.RequestCommand)
            .Returns(BatchUrlManagerCommand.Exec)
            .Verifiable();
            batchUrlManager.Setup((s) => s.isBatch).Returns(true).Verifiable();
            batchUrlManager.Setup((s) => s.RequestBatchName).Returns("SimplePOCO").Verifiable();
            batchUrlManager.Setup((s) => s.RequestBatchAction).Returns("method1").Verifiable();

            var context = new ContextInvoker()
            {
                ActionDescriptor = null,
                ActionName       = "method1",
                BatchName        = "SimplePOCO",
                SessionId        = Guid.NewGuid()
            };

            var applicationBatchManager = new Mock <IApplicationBatchManager>(MockBehavior.Strict);

            applicationBatchManager.Setup((s) => s.SearcByNameAndAction("SimplePOCO", "method1")).Returns(actionDescriptions).Verifiable();

            var batchInvokerProvider = new Mock <IBatchInvokerProvider>(MockBehavior.Strict);

            batchInvokerProvider.Setup((s) => s.InvokeAsync(context)).Returns(Task.FromResult((object)"method1")).Verifiable();

            BatchActionProvider batchActionProvider = new BatchActionProvider(applicationBatchManager.Object, batchInvokerProvider.Object);

            var response = await Assert.ThrowsAsync <Exception>(() => batchActionProvider.InvokeAsync(batchUrlManager.Object, context));

            Assert.Equal("No batch satisfy the search", response.Message);
        }
コード例 #7
0
        public void BatchActionDescriptorTest_BatchNameActionNamePropertyChange()
        {
            //arrange
            var batchActionDescriptor = new BatchActionDescriptor();

            //act
            batchActionDescriptor.BatchName  = "batchname";
            batchActionDescriptor.ActionName = "actionname";

            //assert
            Assert.Collection <KeyValuePair <string, object> >(batchActionDescriptor.BatchConfiguration.AsEnumerable <KeyValuePair <string, object> >(),
                                                               (p) =>
            {
                Assert.IsType <string>(p.Value);
                Assert.Equal("batchname", (string)p.Value);
            },
                                                               (p) =>
            {
                Assert.IsType <string>(p.Value);
                Assert.Equal("actionname", (string)p.Value);
            }
                                                               );
        }
コード例 #8
0
 public static void SetNextExecutionDate(this BatchActionDescriptor batchActionDescriptor, DateTime nextSkeduledDate)
 {
     batchActionDescriptor.BatchConfiguration.AddOrUpdate("NextSkeduledDate", nextSkeduledDate);
 }