/// <summary> /// Remove a filter callback from the given index node. /// </summary> /// <param name="eventType">event type</param> /// <param name="valueSet">value set</param> /// <param name="filterCallback">is the callback to remove</param> public void Remove( FilterHandle filterCallback, EventType eventType, FilterValueSetParam[][] valueSet) { var rootNode = eventTypeIndex.Get(eventType); if (rootNode != null) { if (valueSet.Length == 0) { IndexTreeBuilderRemove.Remove(eventType, filterCallback, FilterSpecParam.EMPTY_VALUE_ARRAY, rootNode); } else { for (var i = 0; i < valueSet.Length; i++) { IndexTreeBuilderRemove.Remove(eventType, filterCallback, valueSet[i], rootNode); } } } }
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); }
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(); }