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 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); } }
private void MatchType( EventType eventType, EventBean eventBean, ICollection<FilterHandle> matches, ExprEvaluatorContext ctx) { FilterHandleSetNode rootNode = null; using (eventTypesRWLock.ReadLock.Acquire()) { rootNode = eventTypes.Get(eventType); } // If the top class node is null, no filters have yet been registered for this event type. // In this case, log a message and done. if (rootNode == null) { return; } rootNode.MatchEvent(eventBean, matches, ctx); }
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); }
public void TestBuildWithMatch() { var topNode = new FilterHandleSetNode(new SlimReaderWriterLock()); // Add some parameter-less expression var filterSpec = MakeFilterValues(); IndexTreeBuilderAdd.Add(filterSpec, testFilterCallback[0], topNode, lockFactory); Assert.IsTrue(topNode.Contains(testFilterCallback[0])); // Attempt a match topNode.MatchEvent(eventBean, matches, null); Assert.IsTrue(matches.Count == 1); matches.Clear(); // Add a filter that won't match, with a single parameter matching against an int filterSpec = MakeFilterValues("IntPrimitive", FilterOperator.EQUAL, 100); IndexTreeBuilderAdd.Add(filterSpec, testFilterCallback[1], topNode, lockFactory); Assert.IsTrue(topNode.Indizes.Count == 1); Assert.IsTrue(topNode.Indizes[0].CountExpensive == 1); // Match again topNode.MatchEvent(eventBean, matches, null); Assert.IsTrue(matches.Count == 1); matches.Clear(); // Add a filter that will match filterSpec = MakeFilterValues("IntPrimitive", FilterOperator.EQUAL, 50); IndexTreeBuilderAdd.Add(filterSpec, testFilterCallback[2], topNode, lockFactory); Assert.IsTrue(topNode.Indizes.Count == 1); Assert.IsTrue(topNode.Indizes[0].CountExpensive == 2); // match topNode.MatchEvent(eventBean, matches, null); Assert.IsTrue(matches.Count == 2); matches.Clear(); // Add some filter against a double filterSpec = MakeFilterValues("DoublePrimitive", FilterOperator.LESS, 1.1); IndexTreeBuilderAdd.Add(filterSpec, testFilterCallback[3], topNode, lockFactory); Assert.IsTrue(topNode.Indizes.Count == 2); Assert.IsTrue(topNode.Indizes[0].CountExpensive == 2); Assert.IsTrue(topNode.Indizes[1].CountExpensive == 1); topNode.MatchEvent(eventBean, matches, null); Assert.IsTrue(matches.Count == 3); matches.Clear(); filterSpec = MakeFilterValues("DoublePrimitive", FilterOperator.LESS_OR_EQUAL, 0.5); IndexTreeBuilderAdd.Add(filterSpec, testFilterCallback[4], topNode, lockFactory); Assert.IsTrue(topNode.Indizes.Count == 3); Assert.IsTrue(topNode.Indizes[0].CountExpensive == 2); Assert.IsTrue(topNode.Indizes[1].CountExpensive == 1); Assert.IsTrue(topNode.Indizes[2].CountExpensive == 1); topNode.MatchEvent(eventBean, matches, null); Assert.IsTrue(matches.Count == 4); matches.Clear(); // Add an filterSpec against double and string filterSpec = MakeFilterValues("DoublePrimitive", FilterOperator.LESS, 1.1, "TheString", FilterOperator.EQUAL, "jack"); IndexTreeBuilderAdd.Add(filterSpec, testFilterCallback[5], topNode, lockFactory); Assert.IsTrue(topNode.Indizes.Count == 3); Assert.IsTrue(topNode.Indizes[0].CountExpensive == 2); Assert.IsTrue(topNode.Indizes[1].CountExpensive == 1); Assert.IsTrue(topNode.Indizes[2].CountExpensive == 1); var nextLevelSetNode = (FilterHandleSetNode)topNode.Indizes[1].Get(1.1d); Assert.IsTrue(nextLevelSetNode != null); Assert.IsTrue(nextLevelSetNode.Indizes.Count == 1); topNode.MatchEvent(eventBean, matches, null); Assert.IsTrue(matches.Count == 5); matches.Clear(); filterSpec = MakeFilterValues("DoublePrimitive", FilterOperator.LESS, 1.1, "TheString", FilterOperator.EQUAL, "beta"); IndexTreeBuilderAdd.Add(filterSpec, testFilterCallback[6], topNode, lockFactory); topNode.MatchEvent(eventBean, matches, null); Assert.IsTrue(matches.Count == 5); matches.Clear(); filterSpec = MakeFilterValues("DoublePrimitive", FilterOperator.LESS, 1.1, "TheString", FilterOperator.EQUAL, "jack"); IndexTreeBuilderAdd.Add(filterSpec, testFilterCallback[7], topNode, lockFactory); Assert.IsTrue(nextLevelSetNode.Indizes.Count == 1); var nodeTwo = (FilterHandleSetNode)nextLevelSetNode.Indizes[0].Get("jack"); Assert.IsTrue(nodeTwo.FilterCallbackCount == 2); topNode.MatchEvent(eventBean, matches, null); Assert.IsTrue(matches.Count == 6); matches.Clear(); // Try depth first filterSpec = MakeFilterValues("TheString", FilterOperator.EQUAL, "jack", "LongPrimitive", FilterOperator.EQUAL, 10L, "ShortPrimitive", FilterOperator.EQUAL, (short)20); IndexTreeBuilderAdd.Add(filterSpec, testFilterCallback[8], topNode, lockFactory); topNode.MatchEvent(eventBean, matches, null); Assert.IsTrue(matches.Count == 7); matches.Clear(); // Add an filterSpec in the middle filterSpec = MakeFilterValues("LongPrimitive", FilterOperator.EQUAL, 10L, "TheString", FilterOperator.EQUAL, "jack"); IndexTreeBuilderAdd.Add(filterSpec, testFilterCallback[9], topNode, lockFactory); filterSpec = MakeFilterValues("LongPrimitive", FilterOperator.EQUAL, 10L, "TheString", FilterOperator.EQUAL, "jim"); IndexTreeBuilderAdd.Add(filterSpec, testFilterCallback[10], topNode, lockFactory); filterSpec = MakeFilterValues("LongPrimitive", FilterOperator.EQUAL, 10L, "TheString", FilterOperator.EQUAL, "joe"); IndexTreeBuilderAdd.Add(filterSpec, testFilterCallback[11], topNode, lockFactory); topNode.MatchEvent(eventBean, matches, null); Assert.IsTrue(matches.Count == 8); matches.Clear(); }
public void TestBuildMatchRemove() { var top = new FilterHandleSetNode(new SlimReaderWriterLock()); // Add a parameter-less filter var filterSpecNoParams = MakeFilterValues(); IndexTreeBuilderAdd.Add(filterSpecNoParams, testFilterCallback[0], top, lockFactory); // Try a match top.MatchEvent(eventBean, matches, null); Assert.IsTrue(matches.Count == 1); matches.Clear(); // Remove filter IndexTreeBuilderRemove.Remove(eventType, testFilterCallback[0], filterSpecNoParams[0], top); // Match should not be found top.MatchEvent(eventBean, matches, null); Assert.IsTrue(matches.Count == 0); matches.Clear(); // Add a depth-first filterSpec var filterSpecOne = MakeFilterValues( "TheString", FilterOperator.EQUAL, "jack", "LongPrimitive", FilterOperator.EQUAL, 10L, "ShortPrimitive", FilterOperator.EQUAL, (short)20); IndexTreeBuilderAdd.Add(filterSpecOne, testFilterCallback[1], top, lockFactory); var filterSpecTwo = MakeFilterValues( "TheString", FilterOperator.EQUAL, "jack", "LongPrimitive", FilterOperator.EQUAL, 10L, "ShortPrimitive", FilterOperator.EQUAL, (short)20); IndexTreeBuilderAdd.Add(filterSpecTwo, testFilterCallback[2], top, lockFactory); var filterSpecThree = MakeFilterValues( "TheString", FilterOperator.EQUAL, "jack", "LongPrimitive", FilterOperator.EQUAL, 10L); IndexTreeBuilderAdd.Add(filterSpecThree, testFilterCallback[3], top, lockFactory); var filterSpecFour = MakeFilterValues( "TheString", FilterOperator.EQUAL, "jack"); IndexTreeBuilderAdd.Add(filterSpecFour, testFilterCallback[4], top, lockFactory); var filterSpecFive = MakeFilterValues( "LongPrimitive", FilterOperator.EQUAL, 10L); IndexTreeBuilderAdd.Add(filterSpecFive, testFilterCallback[5], top, lockFactory); top.MatchEvent(eventBean, matches, null); Assert.IsTrue(matches.Count == 5); matches.Clear(); // Remove some of the nodes IndexTreeBuilderRemove.Remove(eventType, testFilterCallback[2], filterSpecTwo[0], top); top.MatchEvent(eventBean, matches, null); Assert.IsTrue(matches.Count == 4); matches.Clear(); // Remove some of the nodes IndexTreeBuilderRemove.Remove(eventType, testFilterCallback[4], filterSpecFour[0], top); top.MatchEvent(eventBean, matches, null); Assert.IsTrue(matches.Count == 3); matches.Clear(); // Remove some of the nodes IndexTreeBuilderRemove.Remove(eventType, testFilterCallback[5], filterSpecFive[0], top); top.MatchEvent(eventBean, matches, null); Assert.IsTrue(matches.Count == 2); matches.Clear(); // Remove some of the nodes IndexTreeBuilderRemove.Remove(eventType, testFilterCallback[1], filterSpecOne[0], top); top.MatchEvent(eventBean, matches, null); Assert.IsTrue(matches.Count == 1); matches.Clear(); // Remove some of the nodes IndexTreeBuilderRemove.Remove(eventType, testFilterCallback[3], filterSpecThree[0], top); top.MatchEvent(eventBean, matches, null); Assert.IsTrue(matches.Count == 0); matches.Clear(); }