示例#1
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);
        }
示例#2
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));
        }
示例#3
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"
            });
        }
        public void ProcessingServer_RegisterEventBus_UnequalPipelineId()
        {
            var bus    = new EventBus(() => null, "one");
            var server = new ProcessingServer();

            Assert.Throws <Exception>(() => server.Register("two", bus));
        }
示例#5
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);
        }
示例#6
0
        public void InitializServerInHandler()
        {
            var handler = new InitialieableHandler();
            var server  = new ProcessingServer();

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

            Assert.AreSame(server, handler.Server);
        }
        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());
        }
示例#8
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));
		}
        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());
        }
示例#10
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());
		}
示例#11
0
        public void ProcessingServer_Heartbeat_RegisterFactory()
        {
            var storage = new Mock <IStorage>();

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

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

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

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

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

            // cleanup
            GlobalConfiguration.Setup(s => { });
        }