示例#1
0
        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);
        }