public void TestRemoveChainLeafView()
        {
            // Remove a non-leaf, expect no removals
            IList <View> removedViews = ViewServiceHelper.RemoveChainLeafView(top, child_2_2);

            Assert.AreEqual(0, removedViews.Count);
            Assert.AreEqual(2, child_2.Views.Length);

            // Remove the whole tree child-by-child
            removedViews = ViewServiceHelper.RemoveChainLeafView(top, child_2_2_2);
            Assert.AreEqual(1, removedViews.Count);
            Assert.AreEqual(child_2_2_2, removedViews[0]);
            Assert.AreEqual(2, child_2.Views.Length);

            removedViews = ViewServiceHelper.RemoveChainLeafView(top, child_2_2_1);
            Assert.AreEqual(2, removedViews.Count);
            Assert.AreEqual(child_2_2_1, removedViews[0]);
            Assert.AreEqual(child_2_2, removedViews[1]);
            Assert.AreEqual(1, child_2.Views.Length);

            removedViews = ViewServiceHelper.RemoveChainLeafView(top, child_1);
            Assert.AreEqual(1, removedViews.Count);
            Assert.AreEqual(child_1, removedViews[0]);

            removedViews = ViewServiceHelper.RemoveChainLeafView(top, child_2_1_1);
            Assert.AreEqual(3, removedViews.Count);
            Assert.AreEqual(child_2_1_1, removedViews[0]);
            Assert.AreEqual(child_2_1, removedViews[1]);
            Assert.AreEqual(child_2, removedViews[2]);

            Assert.AreEqual(0, child_2.Views.Length);
            Assert.AreEqual(0, top.Views.Length);
        }
Esempio n. 2
0
        public ViewServiceCreateResult CreateViews(
            Viewable eventStreamViewable,
            IList <ViewFactory> viewFactories,
            AgentInstanceViewFactoryChainContext viewFactoryChainContext,
            bool hasPreviousNode)
        {
            // Attempt to find existing views under the stream that match specs.
            // The viewSpecList may have been changed by this method.
            Pair <Viewable, IList <View> > resultPair;

            if (hasPreviousNode)
            {
                resultPair = new Pair <Viewable, IList <View> >(eventStreamViewable, Collections.GetEmptyList <View>());
            }
            else
            {
                resultPair = ViewServiceHelper.MatchExistingViews(eventStreamViewable, viewFactories, viewFactoryChainContext.AgentInstanceContext);
            }

            var parentViewable = resultPair.First;

            if (viewFactories.IsEmpty())
            {
                if (Log.IsDebugEnabled)
                {
                    Log.Debug(".createView No new views created, dumping stream ... " + eventStreamViewable);
                    ViewSupport.DumpChildViews("EventStream ", eventStreamViewable);
                }

                return(new ViewServiceCreateResult(parentViewable, parentViewable, Collections.GetEmptyList <View>()));   // we know its a view here since the factory list is empty
            }

            // Instantiate remaining chain of views from the remaining factories which didn't match to existing views.
            var views = ViewServiceHelper.InstantiateChain(parentViewable, viewFactories, viewFactoryChainContext);

            // Initialize any views that need initializing after the chain is complete
            foreach (var view in views)
            {
                if (view is InitializableView)
                {
                    var initView = (InitializableView)view;
                    initView.Initialize();
                }
            }

            if (Log.IsDebugEnabled)
            {
                Log.Debug(".createView New views created for stream, all views ... " + eventStreamViewable);
                ViewSupport.DumpChildViews("EventStream ", eventStreamViewable);
            }

            return(new ViewServiceCreateResult(views[views.Count - 1], views[0], views));
        }
        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 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];
        }
Esempio n. 5
0
        public void Remove(EventStream eventStream, Viewable viewToRemove)
        {
            // If the viewToRemove to remove has child viewToRemove, don't disconnect - the child ViewToRemove(s) need this
            if (viewToRemove.HasViews)
            {
                return;
            }

            if (Log.IsDebugEnabled)
            {
                Log.Debug(".remove Views before the remove of view " + viewToRemove + ", for event stream " + eventStream);
                ViewSupport.DumpChildViews("EventStream ", eventStream);
            }

            // Remove views in chain leaving only non-empty parent views to the child view to be removed
            ViewServiceHelper.RemoveChainLeafView(eventStream, viewToRemove);

            if (Log.IsDebugEnabled)
            {
                Log.Debug(".remove Views after the remove, for event stream " + eventStream);
                ViewSupport.DumpChildViews("EventStream ", eventStream);
            }
        }
Esempio n. 6
0
        public ViewFactoryChain CreateFactories(int streamNum, EventType parentEventType, ViewSpec[] viewSpecDefinitions, StreamSpecOptions options, StatementContext context, bool isSubquery, int subqueryNumber)
        {
            // Clone the view spec list to prevent parameter modification
            IList <ViewSpec> viewSpecList = new List <ViewSpec>(viewSpecDefinitions);

            // Inspect views and add merge views if required
            ViewServiceHelper.AddMergeViews(viewSpecList);

            // Instantiate factories, not making them aware of each other yet
            var viewFactories = ViewServiceHelper.InstantiateFactories(streamNum, viewSpecList, context, isSubquery, subqueryNumber);

            ViewFactory         parentViewFactory     = null;
            IList <ViewFactory> attachedViewFactories = new List <ViewFactory>();

            for (var i = 0; i < viewFactories.Count; i++)
            {
                var factoryToAttach = viewFactories[i];
                try
                {
                    factoryToAttach.Attach(parentEventType, context, parentViewFactory, attachedViewFactories);
                    attachedViewFactories.Add(viewFactories[i]);
                    parentEventType = factoryToAttach.EventType;
                }
                catch (ViewParameterException ex)
                {
                    var text = "Error attaching view to parent view";
                    if (i == 0)
                    {
                        text = "Error attaching view to event stream";
                    }
                    throw new ViewProcessingException(text + ": " + ex.Message, ex);
                }
            }

            // obtain count of data windows
            var dataWindowCount         = 0;
            var firstNonDataWindowIndex = -1;

            for (var i = 0; i < viewFactories.Count; i++)
            {
                var factory = viewFactories[i];
                if (factory is DataWindowViewFactory)
                {
                    dataWindowCount++;
                    continue;
                }
                if ((factory is GroupByViewFactoryMarker) || (factory is MergeViewFactory))
                {
                    continue;
                }
                if (firstNonDataWindowIndex == -1)
                {
                    firstNonDataWindowIndex = i;
                }
            }

            var isAllowMultipleExpiry = context.ConfigSnapshot.EngineDefaults.ViewResources.IsAllowMultipleExpiryPolicies;
            var isRetainIntersection  = options.IsRetainIntersection;
            var isRetainUnion         = options.IsRetainUnion;

            // Set the default to retain-intersection unless allow-multiple-expiry is turned on
            if ((!isAllowMultipleExpiry) && (!isRetainUnion))
            {
                isRetainIntersection = true;
            }

            // handle multiple data windows with retain union.
            // wrap view factories into the union view factory and handle a group-by, if present
            if ((isRetainUnion || isRetainIntersection) && dataWindowCount > 1)
            {
                viewFactories = GetRetainViewFactories(parentEventType, viewFactories, isRetainUnion, context);
            }

            return(new ViewFactoryChain(parentEventType, viewFactories));
        }
        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);
        }