public void TestIncorrectUse()
 {
     try {
         _myView = new ExternallyTimedWindowView(
             null,
             SupportExprNodeFactory.MakeIdentNodeBean("TheString"), null,
             new ExprTimePeriodEvalDeltaConstGivenDelta(0), null,
             SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext(_container));
     } catch (ArgumentException) {
         // Expected exception
     }
 }
Пример #2
0
        public void TestCanReuse()
        {
            EventType            parentType           = SupportEventTypeFactory.CreateBeanType(typeof(SupportBean));
            AgentInstanceContext agentInstanceContext = SupportStatementContextFactory.MakeAgentInstanceContext(_container);

            _factory.SetViewParameters(SupportStatementContextFactory.MakeViewContext(_container), TestViewSupport.ToExprListBean(new Object[] { "LongBoxed", 1000 }));
            _factory.Attach(parentType, SupportStatementContextFactory.MakeContext(_container), null, null);
            Assert.IsFalse(_factory.CanReuse(new FirstElementView(null), agentInstanceContext));
            Assert.IsFalse(_factory.CanReuse(new ExternallyTimedWindowView(_factory, SupportExprNodeFactory.MakeIdentNodeBean("LongPrimitive"), null, new ExprTimePeriodEvalDeltaConstGivenDelta(1000), null, SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext(_container)), agentInstanceContext));
            Assert.IsFalse(_factory.CanReuse(new ExternallyTimedWindowView(_factory, SupportExprNodeFactory.MakeIdentNodeBean("LongBoxed"), null, new ExprTimePeriodEvalDeltaConstGivenDelta(999), null, SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext(_container)), agentInstanceContext));
            Assert.IsTrue(_factory.CanReuse(new ExternallyTimedWindowView(_factory, SupportExprNodeFactory.MakeIdentNodeBean("LongBoxed"), null, new ExprTimePeriodEvalDeltaConstGivenDelta(1000000), null, SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext(_container)), agentInstanceContext));
        }
        public void SetUp()
        {
            _container = SupportContainer.Reset();
            // Set up timed window view and a test child view, set the time window size to 1 second
            ExprNode node = SupportExprNodeFactory.MakeIdentNodeBean("LongPrimitive");

            _myView = new ExternallyTimedWindowView(
                new ExternallyTimedWindowViewFactory(),
                node,
                node.ExprEvaluator,
                new ExprTimePeriodEvalDeltaConstGivenDelta(1000), null,
                SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext(_container));
            _childView = new SupportBeanClassView(typeof(SupportBean));
            _myView.AddView(_childView);
        }
Пример #4
0
        public static List <ExprNode> ToExprListBean(Object[] constants)
        {
            List <ExprNode> expr = new List <ExprNode>();

            for (int i = 0; i < constants.Length; i++)
            {
                if (constants[i] is String)
                {
                    expr.Add(SupportExprNodeFactory.MakeIdentNodeBean(constants[i].ToString()));
                }
                else
                {
                    expr.Add(new ExprConstantNodeImpl(constants[i]));
                }
            }
            return(expr);
        }
Пример #5
0
        private static IList <ExprNode> MakeParams(Type[] clazz, String[] values)
        {
            var parameters = new List <ExprNode>();

            if (values == null)
            {
                return(parameters);
            }

            for (int i = 0; i < values.Length; i++)
            {
                ExprNode node;
                String   value = values[i];
                if (clazz[i] == typeof(string))
                {
                    if (value.StartsWith("\""))
                    {
                        value = value.Replace("\"", "");
                        node  = new ExprConstantNodeImpl(value);
                    }
                    else
                    {
                        node = SupportExprNodeFactory.MakeIdentNodeBean(value);
                    }
                }
                else if (clazz[i] == typeof(bool?))
                {
                    node = new ExprConstantNodeImpl(bool.Parse(value));
                }
                else
                {
                    node = new ExprConstantNodeImpl(int.Parse(value));
                }
                parameters.Add(node);
            }

            return(parameters);
        }
Пример #6
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);
        }