public void CircularDataSink_ProvidesAName() { var config = new SinkElement("id", "testData", 10, float.MinValue, float.MaxValue); var sink = new CircularDataSink(config); Assert.AreEqual(config.Name, sink.Name); }
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 CircularDataSink_CanBeConfiguredWithASinkElement() { var name = "testBuffer"; var points = 1; var config = new SinkElement("id", name, points); var sink = new CircularDataSink(config); Assert.AreEqual(name, sink.Name); }
public void CircularDataSink_CanBeUpdatedWithMetricData() { var config = new SinkElement("id", "testData", 10, float.MinValue, float.MaxValue); var sink = new CircularDataSink(config); var snapshot = new Snapshot { new MetricData(10, DateTime.Now, new List<string> { "value" }) }; sink.Update(snapshot); var actual = sink.Snapshot(); Assert.AreEqual(1, actual.Count()); Assert.AreEqual(10, actual.First().Data[0]); }
public void CircularDataSink_CanProvideASnapshotOfDataAfterSomeCutoff() { var config = new SinkElement("id", "testData", 10, float.MinValue, float.MaxValue); var sink = new CircularDataSink(config); var snapshot = new Snapshot { new MetricData(10, DateTime.Parse("7 Feb 2013"), new List<string> { "value" }), new MetricData(20, DateTime.Parse("9 Feb 2013"), new List<string> { "value" }) }; sink.Update(snapshot); var actual = sink.Snapshot(DateTime.Parse("8 Feb 2013")); Assert.AreEqual(1, actual.Count()); Assert.AreEqual(20, actual.First().Data[0]); }
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 CircularDataSink_WarnsWhenStructureOfDataHasChanged() { var config = new SinkElement("id", "testData", 10, float.MinValue, float.MaxValue); var sink = new CircularDataSink(config); var snapshot = new Snapshot { new MetricData(10, DateTime.Now.AddMinutes(-1), new List<string> { "value" }) }; sink.Update(snapshot); snapshot = new Snapshot { new MetricData(10, DateTime.Now, new List<string> { "value", "some extra value" }) }; sink.Update(snapshot); }
public void CircularDataSink_IgnoreDataOlderThanMostRecentLastUpdate() { var config = new SinkElement("id", "testData", 10, float.MinValue, float.MaxValue); var sink = new CircularDataSink(config); sink.Update(new Snapshot { new MetricData( 1.0, DateTime.Now, new List<string> { "value" }), new MetricData( 2.0, DateTime.Now.AddMinutes(5), new List<string> { "value" }), new MetricData( 4.0, DateTime.Now.AddMinutes(10), new List<string> { "value" }), new MetricData( 1.0, DateTime.Now.AddMinutes(5), new List<string> { "value" }) }); var snapshot = sink.Snapshot(); var total = 0.0d; foreach (var dataPoint in snapshot) { total += dataPoint.Data[0].Value; } Assert.AreEqual(7.0d, total); }