public void TestAddMergeViews() { IList <ViewSpec> specOne = SupportViewSpecFactory.MakeSpecListOne(); ViewServiceHelper.AddMergeViews(specOne); Assert.AreEqual(3, specOne.Count); IList <ViewSpec> specFour = SupportViewSpecFactory.MakeSpecListTwo(); ViewServiceHelper.AddMergeViews(specFour); Assert.AreEqual(3, specFour.Count); Assert.AreEqual("merge", specFour[2].ObjectName); Assert.AreEqual(specFour[0].ObjectParameters.Count, specFour[1].ObjectParameters.Count); }
public void SetUp() { _streamOne = new SupportStreamImpl(typeof(SupportBean), 1); _streamTwo = new SupportStreamImpl(typeof(SupportBean_A), 1); _viewService = new ViewServiceImpl(); AgentInstanceViewFactoryChainContext context = SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext(); _viewOne = _viewService.CreateViews(_streamOne, SupportViewSpecFactory.MakeFactoryListOne(_streamOne.EventType), context, false).FinalViewable; _viewTwo = _viewService.CreateViews(_streamOne, SupportViewSpecFactory.MakeFactoryListTwo(_streamOne.EventType), context, false).FinalViewable; _viewThree = _viewService.CreateViews(_streamOne, SupportViewSpecFactory.MakeFactoryListThree(_streamOne.EventType), context, false).FinalViewable; _viewFour = _viewService.CreateViews(_streamOne, SupportViewSpecFactory.MakeFactoryListFour(_streamOne.EventType), context, false).FinalViewable; _viewFive = _viewService.CreateViews(_streamTwo, SupportViewSpecFactory.MakeFactoryListFive(_streamTwo.EventType), context, false).FinalViewable; }
public void TestInstantiateChain() { SupportBeanClassView topView = new SupportBeanClassView(TEST_CLASS); IList <ViewFactory> viewFactories = SupportViewSpecFactory.MakeFactoryListOne(topView.EventType); AgentInstanceViewFactoryChainContext context = SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext(); // Check correct views created IList <View> views = ViewServiceHelper.InstantiateChain(topView, viewFactories, context); Assert.AreEqual(3, views.Count); Assert.AreEqual(typeof(LengthWindowView), views[0].GetType()); Assert.AreEqual(typeof(UnivariateStatisticsView), views[1].GetType()); Assert.AreEqual(typeof(LastElementView), views[2].GetType()); // Check that the context is set viewFactories = SupportViewSpecFactory.MakeFactoryListFive(topView.EventType); views = ViewServiceHelper.InstantiateChain(topView, viewFactories, context); TimeWindowView timeWindow = (TimeWindowView)views[0]; }
public void TestMatch() { SupportStreamImpl stream = new SupportStreamImpl(TEST_CLASS, 10); IList <ViewFactory> viewFactories = SupportViewSpecFactory.MakeFactoryListOne(stream.EventType); // No views under stream, no matches Pair <Viewable, IList <View> > result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(stream, result.First); Assert.AreEqual(3, viewFactories.Count); Assert.AreEqual(0, result.Second.Count); // One top view under the stream that doesn't match SupportBeanClassView testView = new SupportBeanClassView(TEST_CLASS); stream.AddView(new FirstElementView(null)); result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(stream, result.First); Assert.AreEqual(3, viewFactories.Count); Assert.AreEqual(0, result.Second.Count); // Another top view under the stream that doesn't matche again testView = new SupportBeanClassView(TEST_CLASS); stream.AddView(new LengthWindowView(SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext(), null, 999, null)); result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(stream, result.First); Assert.AreEqual(3, viewFactories.Count); Assert.AreEqual(0, result.Second.Count); // One top view under the stream that does actually match LengthWindowView myLengthWindowView = new LengthWindowView(SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext(), null, 1000, null); stream.AddView(myLengthWindowView); result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(myLengthWindowView, result.First); Assert.AreEqual(2, viewFactories.Count); Assert.AreEqual(1, result.Second.Count); Assert.AreEqual(myLengthWindowView, result.Second[0]); // One child view under the top view that does not match testView = new SupportBeanClassView(TEST_CLASS); viewFactories = SupportViewSpecFactory.MakeFactoryListOne(stream.EventType); EventType type = UnivariateStatisticsView.CreateEventType(SupportStatementContextFactory.MakeContext(), null, 1); UnivariateStatisticsViewFactory factory = new UnivariateStatisticsViewFactory(); factory.EventType = type; factory.FieldExpression = SupportExprNodeFactory.MakeIdentNodeBean("LongBoxed"); myLengthWindowView.AddView(new UnivariateStatisticsView(factory, SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext())); result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(1, result.Second.Count); Assert.AreEqual(myLengthWindowView, result.Second[0]); Assert.AreEqual(myLengthWindowView, result.First); Assert.AreEqual(2, viewFactories.Count); // Add child view under the top view that does match viewFactories = SupportViewSpecFactory.MakeFactoryListOne(stream.EventType); UnivariateStatisticsViewFactory factoryTwo = new UnivariateStatisticsViewFactory(); factoryTwo.EventType = type; factoryTwo.FieldExpression = SupportExprNodeFactory.MakeIdentNodeBean("IntPrimitive"); UnivariateStatisticsView myUnivarView = new UnivariateStatisticsView(factoryTwo, SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext()); myLengthWindowView.AddView(myUnivarView); result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(myUnivarView, result.First); Assert.AreEqual(1, viewFactories.Count); // Add ultimate child view under the child view that does match viewFactories = SupportViewSpecFactory.MakeFactoryListOne(stream.EventType); LastElementView lastElementView = new LastElementView(null); myUnivarView.AddView(lastElementView); result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(lastElementView, result.First); Assert.AreEqual(0, viewFactories.Count); }
public void TestEquals() { var c_0 = new[] { typeof(string) }; var s_0_0 = new[] { "\"Symbol\"" }; var s_0_1 = new[] { "\"Price\"" }; var c_1 = new[] { typeof(string), typeof(long?) }; var s_1_0 = new[] { "\"Symbol\"", "1" }; var s_1_1 = new[] { "\"Price\"", "1" }; var s_1_2 = new[] { "\"Price\"", "2" }; var s_1_3 = new[] { "\"Price\"", "1" }; var c_2 = new[] { typeof(bool?), typeof(string), typeof(long?) }; var s_2_0 = new[] { "true", "\"Symbol\"", "1" }; var s_2_1 = new[] { "true", "\"Price\"", "1" }; var s_2_2 = new[] { "true", "\"Price\"", "2" }; var s_2_3 = new[] { "false", "\"Price\"", "1" }; IDictionary <int, ViewSpec> specs = new Dictionary <int, ViewSpec>(); specs.Put(1, SupportViewSpecFactory.MakeSpec("ext", "sort", null, null)); specs.Put(2, SupportViewSpecFactory.MakeSpec("std", "sum", null, null)); specs.Put(3, SupportViewSpecFactory.MakeSpec("ext", "sort", null, null)); specs.Put(4, SupportViewSpecFactory.MakeSpec("ext", "sort", c_0, s_0_0)); specs.Put(5, SupportViewSpecFactory.MakeSpec("ext", "sort", c_0, s_0_0)); specs.Put(6, SupportViewSpecFactory.MakeSpec("ext", "sort", c_0, s_0_1)); specs.Put(7, SupportViewSpecFactory.MakeSpec("ext", "sort", c_1, s_1_0)); specs.Put(8, SupportViewSpecFactory.MakeSpec("ext", "sort", c_1, s_1_1)); specs.Put(9, SupportViewSpecFactory.MakeSpec("ext", "sort", c_1, s_1_2)); specs.Put(10, SupportViewSpecFactory.MakeSpec("ext", "sort", c_1, s_1_3)); specs.Put(11, SupportViewSpecFactory.MakeSpec("ext", "sort", c_2, s_2_0)); specs.Put(12, SupportViewSpecFactory.MakeSpec("ext", "sort", c_2, s_2_1)); specs.Put(13, SupportViewSpecFactory.MakeSpec("ext", "sort", c_2, s_2_2)); specs.Put(14, SupportViewSpecFactory.MakeSpec("ext", "sort", c_2, s_2_3)); IDictionary <int, int> matches = new Dictionary <int, int>(); matches.Put(1, 3); matches.Put(3, 1); matches.Put(4, 5); matches.Put(5, 4); matches.Put(8, 10); matches.Put(10, 8); // Compare each against each foreach (var entryOut in specs) { foreach (var entryIn in specs) { bool result = entryOut.Value.Equals(entryIn.Value); if (Equals(entryOut, entryIn)) { Assert.IsTrue(result); continue; } String message = "Comparing " + entryIn.Key + "=" + entryIn.Value + " and " + entryOut.Key + "=" + entryOut.Value; if ((matches.ContainsKey(entryOut.Key)) && (matches.Get(entryOut.Key) == entryIn.Key)) { Assert.IsTrue(result, message); } else { Assert.IsFalse(result, message); } } } }