public void TestEvalEvents() { for (var i = 0; i < events.Count; i++) { IList <FilterHandle> matchList = new List <FilterHandle>(); filterService.Evaluate(events[i], (ICollection <FilterHandle>)matchList, (ExprEvaluatorContext)null); foreach (var match in matchList) { var handle = (SupportFilterHandle)match; handle.MatchFound(events[i], null); } var matches = matchesExpected[i]; for (var j = 0; j < matches.Length; j++) { SupportFilterHandle callback = filterCallbacks[j]; if (matches[j] != callback.GetAndResetCountInvoked()) { log.Debug(".testEvalEvents Match failed, event=" + events[i].Underlying); log.Debug(".testEvalEvents Match failed, eventNumber=" + i + " index=" + j); Assert.IsTrue(false); } } } }
public void TestActiveCallbackRemove() { var spec = SupportFilterSpecBuilder.Build(eventTypeOne, new object[0]).GetValueSet(null, null, null, null); var callbackTwo = new SupportFilterHandle(); // callback that removes another matching filter spec callback var callbackOne = new MySupportFilterHandle( filterService, callbackTwo, eventTypeOne, spec); filterService.Add(eventTypeOne, spec, callbackOne); filterService.Add(eventTypeOne, spec, callbackTwo); // send event var theEvent = MakeTypeOneEvent(1, "HELLO", false, 1); var matches = new List <FilterHandle>(); filterService.Evaluate(theEvent, (ICollection <FilterHandle>)matches, (ExprEvaluatorContext)null); foreach (var match in matches) { ((FilterHandleCallback)match).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.That(callbackTwo.GetAndResetCountInvoked(), Is.EqualTo(1)); }
public void TestNodeMatching() { var eventObject = new SupportBeanSimple("DepositEvent_1", 1); var eventBean = SupportEventBeanFactory .GetInstance(container) .CreateObject(eventObject); FilterHandle expr = new SupportFilterHandle(); testNode.Add(expr); // Check matching without an index node IList <FilterHandle> matches = new List <FilterHandle>(); testNode.MatchEvent(eventBean, matches, null); 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), new SlimReaderWriterLock()); testNode.Add(index); index.Put("DepositEvent_1", testEvaluator); // Verify matcher instance stored in index is called testNode.MatchEvent(eventBean, matches, null); Assert.IsTrue(testEvaluator.GetAndResetCountInvoked() == 1); Assert.IsTrue(testEvaluator.LastEvent == eventBean); Assert.AreEqual(1, matches.Count); Assert.AreEqual(expr, matches[0]); }
public void SetUp() { lockFactory = new FilterServiceGranularLockFactoryReentrant( container.RWLockManager()); var testBean = new SupportBean(); testBean.IntPrimitive = 50; testBean.DoublePrimitive = 0.5; testBean.TheString = "jack"; testBean.LongPrimitive = 10; testBean.ShortPrimitive = (short)20; eventBean = SupportEventBeanFactory .GetInstance(container) .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(); } }
private void RunAssertionAddRemoveFilter(FilterService service) { EventType eventType = supportEventTypeFactory.CreateBeanType(typeof(SupportBean)); var spec = SupportFilterSpecBuilder.Build(eventType, new object[] { "string", FilterOperator.EQUAL, "HELLO" }); var filterValues = spec.GetValueSet(null, null, null, null); var callables = new Func <bool> [5]; for (var ii = 0; ii < callables.Length; ii++) { callables[ii] = () => { var handle = new SupportFilterHandle(); for (var jj = 0; jj < 10000; jj++) { service.Add(eventType, filterValues, handle); service.Remove(handle, eventType, filterValues); } return(true); }; } var result = TryMT(callables); EPAssertionUtil.AssertAllBooleanTrue(result); }
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 .GetInstance(container) .CreateBeanType(typeof(SupportBean)); SupportExprEventEvaluator eval = new SupportExprEventEvaluator(eventType.GetGetter("IntPrimitive")); ExprFilterSpecLookupable lookupable = new ExprFilterSpecLookupable( "IntPrimitive", eval, null, eventType.GetPropertyType("IntPrimitive"), false, null); FilterParamIndexBase indexOne = new SupportFilterParamIndex(lookupable); testNode.Add(indexOne); // Check after add Assert.AreEqual(1, testNode.Indizes.Count); Assert.AreEqual(indexOne, testNode.Indizes[0]); // 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()); }
public void TestVerifyFilterSpecSet() { // Add all the above filter definitions foreach (var filterSpec in testFilterSpecs) { var filterValues = filterSpec.GetValueSet(null, null, null, null); FilterHandle callback = new SupportFilterHandle(); filterCallbacks.Add(callback); IndexTreeBuilderAdd.Add(filterValues, callback, topNode, lockFactory); } // 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, null); 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, null); Assert.IsTrue(matches.Count == 1); } // Remove all expressions previously added var count = 0; foreach (var filterSpec in testFilterSpecs) { var callback = filterCallbacks[count++]; var filterValues = filterSpec.GetValueSet(null, null, null, null); IndexTreeBuilderRemove.Remove(eventType, callback, filterValues[0], topNode); } // After the remove no matches are expected foreach (var theEvent in matchedEvents) { IList <FilterHandle> matches = new List <FilterHandle>(); topNode.MatchEvent(theEvent, matches, null); Assert.IsTrue(matches.Count == 0); } }
public void Run() { long currentThreadId = Thread.CurrentThread.ManagedThreadId; // Choose one of filter specifications, randomly, then reserve to make sure no one else has the same FilterSpecActivatable filterSpec = null; EventBean unmatchedEvent = null; EventBean matchedEvent = null; var index = 0; do { index = random.Next(testFilterSpecs.Count); filterSpec = testFilterSpecs[index]; unmatchedEvent = unmatchedEvents[index]; matchedEvent = matchedEvents[index]; } while (!ObjectReservationSingleton.GetInstance().Reserve(filterSpec)); // Add expression var filterValues = filterSpec.GetValueSet(null, null, null, null); FilterHandle filterCallback = new SupportFilterHandle(); IndexTreeBuilderAdd.Add(filterValues, filterCallback, topNode, lockFactory); // Fire a no-match IList <FilterHandle> matches = new List <FilterHandle>(); topNode.MatchEvent(unmatchedEvent, matches, null); if (matches.Count != 0) { log.Error( ".Run (" + currentThreadId + ") Got a match but expected no-match, matchCount=" + matches.Count + " bean=" + unmatchedEvent + " match=" + matches[0].GetHashCode()); Assert.IsFalse(true); } // Fire a match topNode.MatchEvent(matchedEvent, matches, null); if (matches.Count != 1) { log.Error( ".Run (" + currentThreadId + ") Got zero or two or more match but expected a match, count=" + matches.Count + " bean=" + matchedEvent); Assert.IsFalse(true); } // Remove the same expression again IndexTreeBuilderRemove.Remove(eventType, filterCallback, filterValues[0], topNode); log.Debug(".Run (" + Thread.CurrentThread.ManagedThreadId + ")" + " Completed"); ObjectReservationSingleton.GetInstance().Unreserve(filterSpec); }