public void CanBeReset()
        {
            var firstSnapshot = new Snapshot { Name = "first" };
            firstSnapshot.Add(new MetricData(10, DateTime.Now.AddMinutes(-2), new List<string> { "value" }));
            firstSnapshot.Add(new MetricData(11, DateTime.Now.AddMinutes(-1.5), new List<string> { "value" }));
            firstSnapshot.Add(new MetricData(15, DateTime.Now.AddMinutes(-1), new List<string> { "value" }));

            var secondSnapshot = new Snapshot { Name = "second" };
            secondSnapshot.Add(new MetricData(10, DateTime.Now.AddMinutes(-2), new List<string> { "value2" }));
            secondSnapshot.Add(new MetricData(5, DateTime.Now.AddMinutes(-1.5), new List<string> { "value2" }));
            secondSnapshot.Add(new MetricData(6, DateTime.Now.AddMinutes(-1), new List<string> { "value2" }));

            var name = "testPlotter";

            var config = new PlotterElement("id", name, ".", 0, 15, 1, "");

            var sink = new MultiPlotter(config);

            sink.ResetWith(new [] { firstSnapshot, secondSnapshot });

            var plotFile = Path.Combine(".", Path.ChangeExtension(name, "png"));

            Assert.IsTrue(File.Exists(plotFile));

            File.Delete(plotFile);
        }
        public static BuiltComponents BuildStandardSinkSet(IStandardSinkSetConfiguration simpleConfig, IEnumerable<ISnapshotProvider> source)
        {
            var sources = new List<ISnapshotProvider>();
            sources.AddRange(source);

            var bufferElement = new SinkElement(simpleConfig);
            var storeElement = new StoreElement(simpleConfig);
            var plotterElement = new PlotterElement(simpleConfig);

            var bufferConfig = new CircularDataSinkConfiguration(new[] {bufferElement});
            var storeConfig = new FileSystemDataStoreConfiguration(new[] {storeElement});
            var plotterConfig = new PlotterConfiguration(new[] {plotterElement});

            var sinks = new List<ISnapshotConsumer>();
            var buffers = CircularDataSinkBuilder.Build(bufferConfig);
            sinks.AddRange(buffers);
            sources.AddRange(buffers);
            var stores = FileSystemDataStoreBuilder.Build(storeConfig);
            sinks.AddRange(stores);
            sources.AddRange(stores);

            var multiSinks = new List<IMultipleSnapshotConsumer>();
            multiSinks.AddRange(MultiPlotterBuilder.Build(plotterConfig));

            var bufferChainElement = new ChainElement(
                simpleConfig.Id + " Buffer Chain",
                simpleConfig.Name,
                simpleConfig.Id + " Source",
                simpleConfig.Id + " Buffer",
                "");

            var sinkChainElement = new ChainElement(
                simpleConfig.Id + " Sink Chain",
                simpleConfig.Name,
                simpleConfig.Id + " Buffer",
                simpleConfig.Id + " Store",
                simpleConfig.Id + " Plotter");

            var preloadChainElement = new ChainElement(
                simpleConfig.Id + " Preload Chain",
                simpleConfig.Name,
                simpleConfig.Id + " Store",
                simpleConfig.Id + " Buffer",
                "");

            var chainConfig = new ChainConfiguration(new[] {bufferChainElement, sinkChainElement, preloadChainElement});

            var preloadScheduleElement = new ScheduleElement(simpleConfig.Id + " Preload Schedule", simpleConfig.Delay,
                                                             preloadChainElement.Id);
            var preloadScheduleConfig = new ScheduleConfiguration(new[] {preloadScheduleElement});

            var chainNames = String.Join(",", new[] {sinkChainElement.Id, bufferChainElement.Id});
            var scheduleElement = new ScheduleElement(simpleConfig.Id + " Schedule", simpleConfig.Delay, chainNames);
            var scheduleConfig = new ScheduleConfiguration(new[] {scheduleElement});

            return new BuiltComponents(sources, sinks, multiSinks, chainConfig, preloadScheduleConfig, scheduleConfig);
        }
        public void CanBeConfiguredwithConfiguration()
        {
            var name = "testPlotter";

            var config = new PlotterElement("id", name, ".", 0, 1, 1, "");

            var plotter = new MultiPlotter(config);

            Assert.IsInstanceOf<IMultipleSnapshotConsumer>(plotter);
            Assert.AreEqual(name, plotter.Name);
        }
Пример #4
0
 public MultiPlotter(PlotterElement config)
     : this(config.Id, config.Name, config.OutputDirectory, config.Min, config.Max, config.Scale, config.Areas)
 {
 }
        public void ChainBuilderCanBuildAMainAndAPlottingChain()
        {
            var snapshot = new Snapshot
                {
                    new MetricData(0.5, DateTime.Parse("12 Aug 2008"), new List<string> { "value" }),
                    new MetricData(0.8, DateTime.Parse("13 Aug 2008"), new List<string> { "value" }),
                    new MetricData(0.9, DateTime.Parse("14 Aug 2008"), new List<string> { "value" })
                };

            var configs = new List<ChainElement>
                {
                    new ChainElement("chain1", "storageChain", "testSourceId", "testBufferId,testStoreId", ""),
                    new ChainElement("chain2", "plottingChain", "testBufferId", "", "testPlotterId"),
                };                   

            var source = MockRepository.GenerateMock<ISnapshotProvider>();
            source.Expect(s => s.Snapshot()).Return(snapshot).Repeat.Any();
            source.Expect(s => s.Name).Return("testSource").Repeat.Any();
            source.Expect(s => s.Id).Return("testSourceId").Repeat.Any();

            var bufferConfig = new SinkElement("testBufferId", "testBuffer", 10, 0, 1);

            var buffer = new CircularDataSink(bufferConfig);

            var store = new FileSystemDataStore(".", "testStore", "testStoreId");

            var config = new PlotterElement("testPlotterId", "testPlotter", ".", 0, 1, 1, "");

            var plotter = new MultiPlotter(config);

            var sources = new HashSet<ISnapshotProvider> { source, buffer };

            var sinks = new HashSet<ISnapshotConsumer> { buffer, store };

            var multiSinks = new HashSet<IMultipleSnapshotConsumer> { plotter };

            var chains = ChainBuilder.Build(sources, sinks, multiSinks, configs);

            Assert.AreEqual(configs.Count, chains.Count());

            foreach(var chain in chains)
            {
                chain.Update();
            }

            var chartName = Path.Combine(@".", plotter.Name + ".png");
            var storeName = store.Name + ".am";

            Assert.IsTrue(File.Exists(chartName));
            Assert.IsTrue(File.Exists(storeName));

            File.Delete(chartName);

            File.Delete(storeName);

            source.VerifyAllExpectations();
        }
 public void Add(PlotterElement config)
 {
     BaseAdd(config, true);
 }