Esempio n. 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);
        }
Esempio n. 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));
        }
Esempio n. 3
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");
        }
Esempio n. 4
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);
        }