Ejemplo n.º 1
0
        public void ProcessingServer_PipelineOptions()
        {
            var factory = new EventBusFactory();
            var server  = new ProcessingServer(factory);


            var config = new PipelineConfiguration
            {
                Id           = "test",
                InputHandler = new HandlerNode
                {
                    Type = typeof(LogInputHandler)
                },
                OutputHandlers = new List <HandlerNode>
                {
                    new HandlerNode
                    {
                        Type = typeof(ConsoleOutputHandler)
                    }
                },
                Options = new PipelineOptions
                {
                    MinProcessors   = 1,
                    MaxItemsInQueue = 100,
                    MaxProcessors   = 1
                }
            };


            server.SetupPipeline("test", config);

            var bus = factory.GetEventBus("test");

            Assert.AreSame(bus.PipelineFactory.Options, config.Options);
        }
Ejemplo n.º 2
0
        public void ProcessingServer_RegisterEventBus_UnequalPipelineId()
        {
            var bus    = new EventBus(() => null, "one");
            var server = new ProcessingServer();

            Assert.Throws <Exception>(() => server.Register("two", bus));
        }
Ejemplo n.º 3
0
        public void StaticServer_SetupPipeline_SimpleServer()
        {
            var pipelineId = new Guid("42C75D31-8679-49B4-B0EE-2B90D4C6B893").ToString();

            var server = new ProcessingServer();

            server.SetupPipeline(pipelineId, s =>
            {
                s.Register(() =>
                {
                    var pipeline = new EventPipeline();
                    pipeline.AddHandler(new ConsoleOutputHandler());

                    return(pipeline);
                });

                s.Register(new LogInputHandler());
            });


            var client = new EventDispatcher(server);

            client.Process(pipelineId, new LogMessage {
                Message = "SetupPipeline_SimpleServer"
            });
        }
Ejemplo n.º 4
0
        public void ProcessingServer_Publish_NoPipeline()
        {
            var factory = new Mock <IEventBusFactory>();
            var server  = new ProcessingServer(factory.Object);

            Assert.DoesNotThrow(() => server.Publish(new Event("pipeline", new EventData())));
        }
Ejemplo n.º 5
0
        public void ProcessingServer_Dispose_Uninitialized()
        {
            var factory = new Mock <IEventBusFactory>();
            var server  = new ProcessingServer(factory.Object);

            Assert.DoesNotThrow(() => server.Dispose());
        }
Ejemplo n.º 6
0
        public void InstanceServer_FactorySetEventBus()
        {
            var pipelineId = Guid.NewGuid().ToString();

            var factory = new EventBusFactory();

            factory.Register(pipelineId, () =>
            {
                var pipeline = new EventPipeline();
                pipeline.AddHandler(new ConsoleOutputHandler());

                return(pipeline);
            });
            factory.Register(pipelineId, new EventBus(() => null, pipelineId));

            var server = new ProcessingServer(factory);

            server.Register(pipelineId, new LogInputHandler());

            var client = new EventDispatcher(server);

            client.Process(pipelineId, new LogMessage {
                Message = "InstanceServer"
            });
        }
Ejemplo n.º 7
0
 public async Task <IActionResult> TestDisposed()
 {
     //var temp = ServiceLocator.Instance.GetService<IProcessingServer>();
     //temp.Dispose();
     ProcessingServer.Dispose();
     return(Success());
 }
Ejemplo n.º 8
0
        public Service1()
        {
            InitializeComponent();

            server = new ProcessingServer();
            server.Login();

            dataServer = new LocalStorageServer();
        }
Ejemplo n.º 9
0
        public void ProcessingServer_Dispose_RegisterFactory()
        {
            var factory = new Mock <IEventBusFactory>();
            var server  = new ProcessingServer(factory.Object);

            server.Register("pipeline", () => (EventPipeline)null);

            Assert.DoesNotThrow(() => server.Dispose());
        }
Ejemplo n.º 10
0
        private static void StartServers()
        {
            deviceServer = new ProcessingServer();
            deviceServer.Login();
            deviceServer.Start();

            dataServer = new LocalStorageServer();
            dataServer.Start();
        }
Ejemplo n.º 11
0
        public void InitializServerInHandler()
        {
            var handler = new InitialieableHandler();
            var server  = new ProcessingServer();

            server.Register(Guid.NewGuid().ToString(), handler);

            Assert.AreSame(server, handler.Server);
        }
Ejemplo n.º 12
0
        public void LoadTest_HeavyWork()
        {
            // start with the warmup...
            var cnt  = 0;
            var proc = 0;

            var pipelineId = Guid.NewGuid().ToString();

            var server = new ProcessingServer();

            server.Register(pipelineId, () =>
            {
                var pipeline = new EventPipeline();
                pipeline.AddHandler(new LoadTestOuptuHandler(e =>
                {
                    proc += 1;
                    // do some heavy work
                    Thread.Sleep(100);
                }));

                return(pipeline);
            });
            server.Register(pipelineId, new InputHandler <InputItem>());



            var client = new EventDispatcher(server);

            var profiler = ProfilerSession.StartSession()
                           .SetIterations(1000)
                           .SetThreads(5)
                           .Task(() =>
            {
                lock (pipelineId)
                {
                    cnt += 1;
                }

                client.Process(pipelineId, new InputItem
                {
                    Value  = "StaticServer",
                    Name   = "test",
                    Number = cnt
                });
            }).RunSession();

            server.WaitAll(pipelineId);
            profiler.Trace();

            var monitor   = new StatisticsApi(pipelineId);
            var processed = monitor.GetMetricValue <long>(MetricType.ProcessedEvents);

            Assert.AreEqual(processed, cnt, "Processed events are not equal to sent events {0} to {1}", processed, cnt);
        }
Ejemplo n.º 13
0
		public void Setup_Register_Factory_Register_InputHandler()
		{
			var pipelineId = Guid.NewGuid().ToString();

			var handler = new SetupInputHandler();


			var server = new ProcessingServer();
			server.Register(pipelineId, handler);
			
			Assert.AreSame(handler, server.InputHandlers.Single(h => h.PipelineId == pipelineId));
		}
Ejemplo n.º 14
0
        public void PerformanceMeasures_FullProcess()
        {
            GlobalConfiguration.Setup(s => s.UseOptions(new Options
            {
                MaxItemsInQueue = 10,
                MaxProcessors   = 30
            }));

            // start with the warmup...
            var cnt = 0;

            var pipelineId = Guid.NewGuid().ToString();

            var server = new ProcessingServer();

            server.Register(pipelineId, () =>
            {
                var pipeline = new EventPipeline();
                pipeline.AddHandler(new LoadTestOuptuHandler(e => { }));

                return(pipeline);
            });
            server.Register(pipelineId, new InputHandler <InputItem>());


            var client = new EventDispatcher(server);

            var sw = new Stopwatch();

            sw.Start();

            for (var i = 0; i < 10; i++)
            {
                client.Process(pipelineId, new InputItem
                {
                    Value  = "StaticServer",
                    Name   = "test",
                    Number = i
                });
            }

            //sw.Stop();
            var time1 = sw.Elapsed;

            server.WaitAll(pipelineId);

            sw.Stop();
            var time2 = sw.Elapsed;

            Assert.Less(time1, TimeSpan.FromMilliseconds(30));
            Assert.Less(time2, TimeSpan.FromMilliseconds(600));
        }
Ejemplo n.º 15
0
        public void ProcessingServer_Dispose_RegisterEventBus()
        {
            var factory = new Mock <IEventBusFactory>();
            var server  = new ProcessingServer(factory.Object);

            var bus = new Mock <IEventBus>();

            bus.Setup(exp => exp.PipelineId).Returns("pipeline");

            server.Register("pipeline", bus.Object);

            Assert.DoesNotThrow(() => server.Dispose());
        }
Ejemplo n.º 16
0
        public void PluginManagerTests_BuildConfig()
        {
            var ctx = new ActivationContext();

            ctx.Register <IEventDataConverter, EventDataConverter>();

            var inputPlugin = _pluginMgr.GetPlugin(typeof(IInputHandler), "CustomInput");
            var input       = ctx.Resolve <IInputHandler>(inputPlugin.Type);

            var outputPlugin = _pluginMgr.GetPlugin(typeof(IOutputHandler), "ConsoleOutput");
            var output       = ctx.Resolve <IOutputHandler>(outputPlugin.Type);

            var pipelineId = Guid.NewGuid().ToString();

            var loghandler = new LogQueueHandler();

            var cnt = 0;

            var server = new ProcessingServer();

            server.SetupPipeline(pipelineId, s =>
            {
                s.Register(() =>
                {
                    var pipeline = new EventPipeline();
                    pipeline.AddHandler(output);
                    pipeline.AddHandler(loghandler);

                    cnt = cnt + 1;

                    return(pipeline);
                });

                s.Register(input);
            });


            var client = new EventDispatcher(server);

            client.Process(pipelineId, new LogMessage {
                Message = "Event1"
            });
            client.Process(pipelineId, new LogMessage {
                Message = "Event2"
            });

            server.WaitAll(pipelineId);

            //Assert.That(cnt == 1, () => $"Count is {cnt} but is expected to be 1");
            Assert.That(loghandler.Log.Count() == 2, () => $"Logcount is {loghandler.Log.Count()} but is expected to be 2");
        }
Ejemplo n.º 17
0
        public void ProcessingServer_Publish()
        {
            var bus = new Mock <IEventBus>();

            bus.Setup(exp => exp.PipelineId).Returns("pipeline");

            var factory = new Mock <IEventBusFactory>();

            factory.Setup(exp => exp.GetEventBus(It.IsAny <string>())).Returns(() => bus.Object);
            var server = new ProcessingServer(factory.Object);

            server.Publish(new Event("pipeline", new EventData()));

            bus.Verify(exp => exp.Publish(It.IsAny <Event>()), Times.Once);
        }
Ejemplo n.º 18
0
        public void PipelineBuilder_Resolver_Perfomance()
        {
            var server  = new ProcessingServer();
            var builder = new PipelineBuilder();

            builder.BuildPipeline(server, new PipelineConfiguration
            {
                Id             = "1",
                InputHandler   = new HandlerNode(typeof(PlainInputHandler)),
                OutputHandlers = new List <HandlerNode>
                {
                    new HandlerNode(typeof(PlainOutputHandler))
                }
            });

            builder.BuildPipeline(server, new PipelineConfiguration
            {
                Id             = "2",
                InputHandler   = new HandlerNode(typeof(CustomInputHandler)),
                OutputHandlers = new List <HandlerNode>
                {
                    new HandlerNode(typeof(PlainOutputHandler))
                }
            });

            //server.EventBusFactory.GetEventBus("1").Publish(new Event("1", new EventData()));
            //server.EventBusFactory.GetEventBus("2").Publish(new Event("2", new EventData()));

            var runner = new BenchmarkRunner();

            runner.SetIterations(10);

            runner.AddSession("Simple resolver",
                              ProfilerSession.StartSession()
                              .Task(() => server.Publish(new Event("1", new EventData())))
                              .SetThreads(5)
                              );
            runner.AddSession("Complex resolver",
                              ProfilerSession.StartSession()
                              .Task(() => server.Publish(new Event("2", new EventData())))
                              .SetThreads(5)
                              );

            var result = runner.RunSessions();

            result.Trace();
        }
Ejemplo n.º 19
0
        public void PerformanceMeasures_WorkersCount(string id, int maxitems, int maxprocessors, int workers, int ticks)
        {
            var server = new ProcessingServer();

            server.Register(id, () =>
            {
                var pipeline = new EventPipeline();
                pipeline.AddHandler(new LoadTestOuptuHandler(e => { }));

                return(pipeline);
            });
            server.Register(id, new InputHandler <InputItem>());

            var client = new EventDispatcher(server);

            GlobalConfiguration.Setup(s => s.UseOptions(new Options
            {
                MinProcessors   = workers,
                MaxItemsInQueue = maxitems,
                MaxProcessors   = maxprocessors
            }));

            var result = ProfilerSession.StartSession()
                         .Setup(() =>
            {
            })
                         .Task(() =>
            {
                for (var i = 0; i < 1000; i++)
                {
                    client.Process(id, new InputItem
                    {
                        Value  = "StaticServer",
                        Name   = "test",
                        Number = i
                    });
                }

                server.WaitAll(id);
            })
                         .RunSession();

            result.Trace();

            Assert.Less(result.AverageMilliseconds, ticks);
        }
Ejemplo n.º 20
0
        public void ProcessingServer_Heartbeat_NoRegistration()
        {
            var storage = new Mock <IStorage>();

            GlobalConfiguration.Setup(s => s.Register <IStorage>(storage.Object));

            var factory = new EventBusFactory();
            var server  = new ProcessingServer(factory);

            // give the hearbeat some time to execute
            Task.Delay(500).Wait();

            storage.Verify(exp => exp.Set <ServerModel>(It.IsAny <StorageKey>(), It.IsAny <ServerModel>()), Times.Never);

            // cleanup
            GlobalConfiguration.Setup(s => { });
        }
Ejemplo n.º 21
0
		public void Setup_Register_Factory_Register_OutputHandler()
		{
			var pipelineId = Guid.NewGuid().ToString();

			var handler = new SetupOutputHandler();


			var server = new ProcessingServer();
			server.Register(pipelineId, () =>
			{
				var pipeline = new EventPipeline();
				pipeline.AddHandler(handler);

				return pipeline;
			});

			Assert.AreSame(handler, GetOutputHandlers(server, pipelineId).Single());
		}
Ejemplo n.º 22
0
		public void Setup_Register_Factory_SetupPipeline_FilterDecorator()
		{
			var pipelineId = Guid.NewGuid().ToString();

			var handler = new SetupOutputHandler();

			var server = new ProcessingServer();
			server.SetupPipeline(pipelineId, c =>
			{
				c.Register(() =>
				{
					var pipeline = new EventPipeline();
					pipeline.AddHandler(handler, new[] { "Level -> dst_lvl", "Message" });

					return pipeline;
				});
			});

			Assert.IsAssignableFrom<DataFilterDecorator>(GetOutputHandlers(server, pipelineId).Single());
		}
Ejemplo n.º 23
0
		public void Setup_Register_Factory_SetupPipeline_AddFilters()
		{
			var pipelineId = Guid.NewGuid().ToString();

			var handler = new SetupOutputHandler();

			var server = new ProcessingServer();
			server.SetupPipeline(pipelineId, c =>
			{
				c.Register(() =>
				{
					var pipeline = new EventPipeline();
					pipeline.AddHandler(handler, new[] {"Level -> dst_lvl", "Message"});

					return pipeline;
				});
			});

			Assert.That(((DataFilterDecorator)GetOutputHandlers(server, pipelineId).Single()).Converter.Filters.Count() == 2);
		}
Ejemplo n.º 24
0
        public void GlobalConfiguration_UseProcessingServer_BuildPipeline_OutputHandlers()
        {
            var server = new ProcessingServer();

            GlobalConfiguration.Setup(c => c.UseProcessingServer(p =>
            {
                var config = new PipelineConfiguration
                {
                    Id             = "pipeline1",
                    OutputHandlers = new List <HandlerNode>
                    {
                        new HandlerNode(typeof(ConsoleOutputHandler))
                    },
                    InputHandler = new HandlerNode(typeof(CustomInputHandler))
                };
                p.BuildPipeline(server, config);
            }));

            var handlers = GetOutputHandlers(server, "pipeline1");

            Assert.IsInstanceOf <ConsoleOutputHandler>(handlers.Single());
        }
Ejemplo n.º 25
0
        public void GlobalConfiguration_AddService_ByType_InSetup()
        {
            GlobalConfiguration.Setup(s => { });

            var server = new ProcessingServer();

            GlobalConfiguration.Setup(c => c.UseProcessingServer(p =>
            {
                var config = new PipelineConfiguration
                {
                    Id             = "dependency_handler",
                    OutputHandlers = new List <HandlerNode>
                    {
                        new HandlerNode(typeof(DependencyHandler))
                    },
                    InputHandler = new HandlerNode("CustomInput")
                };
                p.BuildPipeline(server, config);
            }).AddService <IDependency, Dependency>()
                                      );

            Assert.IsNotNull(((DependencyHandler)GetOutputHandlers(server, "dependency_handler").Single()).Instance);
        }
Ejemplo n.º 26
0
        public void GlobalConfiguration_UseProcessingServer_BuildPipeline_Filters()
        {
            var server = new ProcessingServer();

            GlobalConfiguration.Setup(c => c.UseProcessingServer(p =>
            {
                var config = new PipelineConfiguration
                {
                    Id             = "pipeline1",
                    OutputHandlers = new List <HandlerNode>
                    {
                        new HandlerNode(typeof(ConsoleOutputHandler))
                        {
                            Filters = new List <string>
                            {
                                "Level -> lvl",
                                "Message",
                                "Id <- ${lvl}_error_${Message}"
                            }
                        }
                    },

                    InputHandler = new HandlerNode(typeof(CustomInputHandler))
                };
                p.BuildPipeline(server, config);
            }));

            var handler = GetOutputHandlers(server, "pipeline1").Single();

            Assert.IsAssignableFrom <DataFilterDecorator>(handler);

            var converter = ((DataFilterDecorator)handler).Converter;

            Assert.That(converter.Filters.Any(f => f.Key == "Level" && f.FilterType == Gaucho.Filters.FilterType.Property));
            Assert.That(converter.Filters.Any(f => f.Key == "Message" && f.FilterType == Gaucho.Filters.FilterType.Property));
            Assert.That(converter.Filters.Any(f => f.Key == "Id" && f.FilterType == Gaucho.Filters.FilterType.Formatter));
        }
Ejemplo n.º 27
0
        public void ProcessingServer_UpdatePipeline()
        {
            var factory = new EventBusFactory();
            var server  = new ProcessingServer(factory);


            var config = new PipelineConfiguration
            {
                Id           = "test",
                InputHandler = new HandlerNode
                {
                    Type = typeof(LogInputHandler)
                },
                OutputHandlers = new List <HandlerNode>
                {
                    new HandlerNode
                    {
                        Type = typeof(ConsoleOutputHandler)
                    }
                }
            };


            server.SetupPipeline("test", config);

            var first  = factory.GetEventBus("test");
            var second = factory.GetEventBus("test");

            Assert.AreSame(first, second);

            // update
            server.SetupPipeline("test", config);

            var third = factory.GetEventBus("test");

            Assert.AreNotSame(first, third);
        }
Ejemplo n.º 28
0
        private IList <WorkQueue> InternalSelect(int startRowIndex, int maximumRows, out int resultCount)
        {
            resultCount = 0;

            if (maximumRows == 0)
            {
                return(new List <WorkQueue>());
            }

            if (SearchKeys != null)
            {
                IList <WorkQueue> workQueueList = new List <WorkQueue>();
                foreach (ServerEntityKey key in SearchKeys)
                {
                    workQueueList.Add(WorkQueue.Load(key));
                }

                resultCount = workQueueList.Count;

                return(workQueueList);
            }

            WebWorkQueueQueryParameters parameters = new WebWorkQueueQueryParameters
            {
                StartIndex  = startRowIndex,
                MaxRowCount = maximumRows
            };

            if (Partition != null)
            {
                parameters.ServerPartitionKey = Partition.Key;
            }

            if (!string.IsNullOrEmpty(PatientsName))
            {
                string key = PatientsName.Replace("*", "%");
                key = key.Replace("?", "_");
                parameters.PatientsName = key;
            }
            if (!string.IsNullOrEmpty(PatientId))
            {
                string key = PatientId.Replace("*", "%");
                key = key.Replace("?", "_");
                parameters.PatientID = key;
            }
            if (!string.IsNullOrEmpty(ProcessingServer))
            {
                string key = ProcessingServer.Replace("*", "%");
                key = key.Replace("?", "_");
                parameters.ProcessorID = key;
            }

            if (String.IsNullOrEmpty(ScheduledDate))
            {
                parameters.ScheduledTime = null;
            }
            else
            {
                parameters.ScheduledTime = DateTime.ParseExact(ScheduledDate, DateFormats, null);
            }

            if (TypeEnums != null && TypeEnums.Length > 0)
            {
                string types = "(";
                if (TypeEnums.Length == 1)
                {
                    types += TypeEnums[0].Enum;
                }
                else
                {
                    string separator = "";
                    foreach (WorkQueueTypeEnum typeEnum in TypeEnums)
                    {
                        types    += separator + typeEnum.Enum;
                        separator = ",";
                    }
                }

                parameters.Type = types + ")";
            }

            if (StatusEnums != null && StatusEnums.Length > 0)
            {
                string statuses = "(";
                if (StatusEnums.Length == 1)
                {
                    statuses += StatusEnums[0].Enum;
                }
                else
                {
                    string separator = "";
                    foreach (WorkQueueStatusEnum statusEnum in StatusEnums)
                    {
                        statuses += separator + statusEnum.Enum;
                        separator = ",";
                    }
                }

                parameters.Status = statuses + ")";
            }

            if (PriorityEnum != null)
            {
                parameters.Priority = PriorityEnum;
            }

            List <string>   groupOIDs = new List <string>();
            CustomPrincipal user      = Thread.CurrentPrincipal as CustomPrincipal;

            if (user != null)
            {
                if (!user.IsInRole(ClearCanvas.Enterprise.Common.AuthorityTokens.DataAccess.AllStudies))
                {
                    foreach (var oid in user.Credentials.DataAccessAuthorityGroups)
                    {
                        groupOIDs.Add(oid.ToString());
                    }

                    parameters.CheckDataAccess         = true;
                    parameters.UserAuthorityGroupGUIDs = StringUtilities.Combine(groupOIDs, ",");
                }
            }

            IList <WorkQueue> list = _searchController.FindWorkQueue(parameters);

            resultCount = parameters.ResultCount;

            return(list);
        }