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 FilterSpecCompiled 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.Instance.Reserve(filterSpec)); // Add expression var filterValues = filterSpec.GetValueSet(null, null, null); FilterHandle filterCallback = new SupportFilterHandle(); var pathAddedTo = IndexTreeBuilder.Add(filterValues, filterCallback, _topNode, _lockFactory); // Fire a no-match IList <FilterHandle> matches = new List <FilterHandle>(); _topNode.MatchEvent(unmatchedEvent, matches); if (matches.Count != 0) { Log.Fatal(".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); if (matches.Count != 1) { Log.Fatal(".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 IndexTreeBuilder.Remove(_eventType, filterCallback, pathAddedTo[0].ToArray(), _topNode); Log.Debug(".run (" + Thread.CurrentThread.ManagedThreadId + ")" + " Completed"); ObjectReservationSingleton.Instance.Unreserve(filterSpec); }
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 FilterSpecCompiled filterSpec = null; EventBean unmatchedEvent = null; EventBean matchedEvent = null; var index = 0; do { //index = (int) (atomic.IncrementAndGet() % _testFilterSpecs.Count); index = Random.Next(_testFilterSpecs.Count); filterSpec = _testFilterSpecs[index]; unmatchedEvent = _unmatchedEvents[index]; matchedEvent = _matchedEvents[index]; }while(!ObjectReservationSingleton.Instance.Reserve(filterSpec)); #if DEBUG && DIAGNOSTIC Log.Info("Reserved: {0} = {1}", index, filterSpec); #endif // Add expression var filterValues = filterSpec.GetValueSet(null, null, null); var filterCallback = new SupportFilterHandle(); #if DEBUG && DIAGNOSTIC Log.Info("TestMultithreaded: {0}", filterValues); #endif var pathAddedTo = IndexTreeBuilder.Add(filterValues, filterCallback, _topNode, _lockFactory); // Fire a no-match IList <FilterHandle> matches = new List <FilterHandle>(); _topNode.MatchEvent(unmatchedEvent, matches); if (matches.Count != 0) { Log.Fatal(".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); if (matches.Count != 1) { Log.Fatal(".Run (" + currentThreadId + ") Got zero or two or more match but expected a match, count=" + matches.Count + " bean=" + matchedEvent); foreach (var entry in LoggerNLog.MemoryTarget.Logs) { System.Diagnostics.Debug.WriteLine(entry); } Assert.IsFalse(true); } // Remove the same expression again IndexTreeBuilder.Remove(_eventType, filterCallback, pathAddedTo[0].ToArray(), _topNode); ObjectReservationSingleton.Instance.Unreserve(filterSpec); }