Esempio n. 1
0
        private void RunAssertionAddRemoveFilter(FilterService service)
        {
            var eventType    = SupportEventTypeFactory.CreateBeanType(typeof(SupportBean));
            var spec         = SupportFilterSpecBuilder.Build(eventType, new Object[] { "TheString", FilterOperator.EQUAL, "HELLO" });
            var filterValues = spec.GetValueSet(null, null, null);

            var callables = new Func <bool> [5];

            for (int ii = 0; ii < callables.Length; ii++)
            {
                callables[ii] =
                    () =>
                {
                    var handle = new SupportFilterHandle();
                    for (int jj = 0; jj < 10000; jj++)
                    {
                        var entry = service.Add(filterValues, handle);
                        service.Remove(handle, entry);
                    }
                    return(true);
                };
            }

            Object[] result = TryMT(callables);
            EPAssertionUtil.AssertAllBooleanTrue(result);
        }
Esempio n. 2
0
        public void SetUp()
        {
            _container   = SupportContainer.Reset();
            _lockFactory = new FilterServiceGranularLockFactoryReentrant(
                _container.Resolve <IReaderWriterLockManager>());

            var testBean = new SupportBean();

            testBean.IntPrimitive    = 50;
            testBean.DoublePrimitive = 0.5;
            testBean.TheString       = "jack";
            testBean.LongPrimitive   = 10;
            testBean.ShortPrimitive  = (short)20;

            _eventBean = SupportEventBeanFactory.CreateObject(testBean);
            _eventType = _eventBean.EventType;

            _matches = new List <FilterHandle>();

            // Allocate a couple of callbacks
            _testFilterCallback = new SupportFilterHandle[20];
            for (var i = 0; i < _testFilterCallback.Length; i++)
            {
                _testFilterCallback[i] = new SupportFilterHandle();
            }
        }
Esempio n. 3
0
        public void TestNodeMatching()
        {
            SupportBeanSimple eventObject = new SupportBeanSimple("DepositEvent_1", 1);
            EventBean         eventBean   = SupportEventBeanFactory.CreateObject(eventObject);

            FilterHandle expr = new SupportFilterHandle();

            _testNode.Add(expr);

            // Check matching without an index node
            List <FilterHandle> matches = new List <FilterHandle>();

            _testNode.MatchEvent(eventBean, matches);
            Assert.AreEqual(1, matches.Count);
            Assert.AreEqual(expr, matches[0]);
            matches.Clear();

            // Create, add and populate an index node
            FilterParamIndexBase index = new FilterParamIndexEquals(
                MakeLookupable("MyString", eventBean.EventType), ReaderWriterLockManager.CreateDefaultLock());

            _testNode.Add(index);
            index["DepositEvent_1"] = _testEvaluator;

            // Verify matcher instance stored in index is called
            _testNode.MatchEvent(eventBean, matches);

            Assert.IsTrue(_testEvaluator.GetAndResetCountInvoked() == 1);
            Assert.IsTrue(_testEvaluator.GetLastEvent() == eventBean);
            Assert.AreEqual(1, matches.Count);
            Assert.AreEqual(expr, matches[0]);
        }
Esempio n. 4
0
        public void TestEvalEvents()
        {
            for (int i = 0; i < _events.Count; i++)
            {
                var matchList = new List <FilterHandle>();
                _filterService.Evaluate(_events[i], matchList);
                foreach (FilterHandle match in matchList)
                {
                    var handle = (SupportFilterHandle)match;
                    handle.MatchFound(_events[i], null);
                }

                int[] matches = _matchesExpected[i];

                for (int j = 0; j < matches.Length; j++)
                {
                    SupportFilterHandle callback = _filterCallbacks[j];

                    if (matches[j] != callback.GetAndResetCountInvoked())
                    {
                        Log.Debug(".testEvalEvents Match failed, theEvent=" + _events[i].Underlying);
                        Log.Debug(".testEvalEvents Match failed, eventNumber=" + i + " index=" + j);
                        Assert.Fail();
                    }
                }
            }
        }
Esempio n. 5
0
        public void TestVerifyFilterSpecSet()
        {
            // Add all the above filter definitions
            foreach (var filterSpec in _testFilterSpecs)
            {
                var          filterValues = filterSpec.GetValueSet(null, null, null);
                FilterHandle callback     = new SupportFilterHandle();
                _filterCallbacks.Add(callback);
                _pathsAddedTo.Add(IndexTreeBuilder.Add(filterValues, callback, _topNode, _lockFactory)[0]);
            }

            // None of the not-matching events should cause any match
            foreach (var theEvent in _unmatchedEvents)
            {
                IList <FilterHandle> matches = new List <FilterHandle>();
                _topNode.MatchEvent(theEvent, matches);
                Assert.IsTrue(matches.Count == 0);
            }

            // All of the matching events should cause exactly one match
            foreach (var theEvent in _matchedEvents)
            {
                IList <FilterHandle> matches = new List <FilterHandle>();
                _topNode.MatchEvent(theEvent, matches);
                Assert.IsTrue(matches.Count == 1);
            }

            // Remove all expressions previously added
            var count = 0;

            foreach (var treePath in _pathsAddedTo)
            {
                var callback = _filterCallbacks[count++];
                IndexTreeBuilder.Remove(_eventType, callback, treePath.ToArray(), _topNode);
            }

            // After the remove no matches are expected
            foreach (var theEvent in _matchedEvents)
            {
                IList <FilterHandle> matches = new List <FilterHandle>();
                _topNode.MatchEvent(theEvent, matches);
                Assert.IsTrue(matches.Count == 0);
            }
        }
Esempio n. 6
0
        public void SetUp()
        {
            var testBean = new SupportBean();

            testBean.IntPrimitive    = 50;
            testBean.DoublePrimitive = 0.5;
            testBean.TheString       = "jack";
            testBean.LongPrimitive   = 10;
            testBean.ShortPrimitive  = (short)20;

            _eventBean = SupportEventBeanFactory.CreateObject(testBean);
            _eventType = _eventBean.EventType;

            _matches = new List <FilterHandle>();

            // Allocate a couple of callbacks
            _testFilterCallback = new SupportFilterHandle[20];
            for (var i = 0; i < _testFilterCallback.Length; i++)
            {
                _testFilterCallback[i] = new SupportFilterHandle();
            }
        }
Esempio n. 7
0
        public void TestActiveCallbackRemove()
        {
            var spec        = SupportFilterSpecBuilder.Build(_eventTypeOne, new Object[0]).GetValueSet(null, null, null);
            var callbackTwo = new SupportFilterHandle();

            // callback that removes another matching filter spec callback
            Atomic <FilterServiceEntry> filterServiceEntryOne = new Atomic <FilterServiceEntry>();
            FilterHandleCallback        callbackOne           = new ProxyFilterHandleCallback
            {
                ProcStatementId = () => "",
                ProcIsSubselect = () => false,
                ProcMatchFound  = (e, allStmtMatches) =>
                {
                    Log.Debug(".matchFound Removing callbackTwo");
                    _filterService.Remove(callbackTwo, filterServiceEntryOne.Value);
                }
            };

            FilterServiceEntry filterServiceEntry = _filterService.Add(spec, callbackOne);

            filterServiceEntryOne.Set(filterServiceEntry);
            _filterService.Add(spec, callbackTwo);

            // send event
            var theEvent = MakeTypeOneEvent(1, "HELLO", false, 1);
            var matches  = new List <FilterHandle>();

            _filterService.Evaluate(theEvent, matches);
            foreach (FilterHandle match in matches)
            {
                var handle = (FilterHandleCallback)match;
                handle.MatchFound(theEvent, null);
            }

            // Callback two MUST be invoked, was removed by callback one, but since the
            // callback invocation order should not matter, the second one MUST also execute
            Assert.AreEqual(1, callbackTwo.GetAndResetCountInvoked());
        }
Esempio n. 8
0
        public void TestNodeGetSet()
        {
            FilterHandle exprOne = new SupportFilterHandle();

            // Check pre-conditions
            Assert.IsTrue(_testNode.NodeRWLock != null);
            Assert.IsFalse(_testNode.Contains(exprOne));
            Assert.AreEqual(0, _testNode.FilterCallbackCount);
            Assert.AreEqual(0, _testNode.Indizes.Count);
            Assert.IsTrue(_testNode.IsEmpty());

            _testNode.Add(exprOne);

            // Check after add
            Assert.IsTrue(_testNode.Contains(exprOne));
            Assert.AreEqual(1, _testNode.FilterCallbackCount);
            Assert.IsFalse(_testNode.IsEmpty());

            // Add an indexOne
            EventType            eventType  = SupportEventTypeFactory.CreateBeanType(typeof(SupportBean));
            FilterSpecLookupable lookupable = new FilterSpecLookupable("IntPrimitive", eventType.GetGetter("IntPrimitive"), eventType.GetPropertyType("IntPrimitive"), false);
            FilterParamIndexBase indexOne   = new SupportFilterParamIndex(lookupable);

            _testNode.Add(indexOne);

            // Check after add
            Assert.AreEqual(1, _testNode.Indizes.Count);
            Assert.AreEqual(indexOne, _testNode.Indizes.FirstOrDefault());

            // Check removes
            Assert.IsTrue(_testNode.Remove(exprOne));
            Assert.IsFalse(_testNode.IsEmpty());
            Assert.IsFalse(_testNode.Remove(exprOne));
            Assert.IsTrue(_testNode.Remove(indexOne));
            Assert.IsFalse(_testNode.Remove(indexOne));
            Assert.IsTrue(_testNode.IsEmpty());
        }