public void TestInvalidSecondAdd() { try { _testIndex.Add(_testEventType, _handleSetNode); Assert.IsTrue(false); } catch (IllegalStateException ex) { // Expected } }
public void SetUp() { SupportBean testBean = new SupportBean(); _testEventBean = SupportEventBeanFactory.CreateObject(testBean); _testEventType = _testEventBean.EventType; _handleSetNode = new FilterHandleSetNode(ReaderWriterLockManager.CreateDefaultLock()); _filterCallback = new SupportFilterHandle(); _handleSetNode.Add(_filterCallback); _testIndex = new EventTypeIndex(new FilterServiceGranularLockFactoryReentrant()); _testIndex.Add(_testEventType, _handleSetNode); }
public void TestInterfaceMatch() { _testEventBean = SupportEventBeanFactory.CreateObject(new ISupportABCImpl("a", "b", "ab", "c")); _testEventType = SupportEventTypeFactory.CreateBeanType(typeof(ISupportBaseAB)); _testIndex = new EventTypeIndex(new FilterServiceGranularLockFactoryReentrant()); _testIndex.Add(_testEventType, _handleSetNode); List <FilterHandle> matchesList = new List <FilterHandle>(); _testIndex.MatchEvent(_testEventBean, matchesList); Assert.AreEqual(1, matchesList.Count); Assert.AreEqual(_filterCallback, matchesList[0]); }
public void TestSuperclassMatch() { _testEventBean = SupportEventBeanFactory.CreateObject(new ISupportAImplSuperGImplPlus()); _testEventType = SupportEventTypeFactory.CreateBeanType(typeof(ISupportA)); _testIndex = new EventTypeIndex(new FilterServiceGranularLockFactoryReentrant(_container.RWLockManager())); _testIndex.Add(_testEventType, _handleSetNode); List <FilterHandle> matchesList = new List <FilterHandle>(); _testIndex.MatchEvent(_testEventBean, matchesList); Assert.AreEqual(1, matchesList.Count); Assert.AreEqual(_filterCallback, matchesList[0]); }
/// <summary> /// Add a filter to the event type index structure, and to the filter subtree. /// Throws an IllegalStateException exception if the callback is already registered. /// </summary> /// <param name="filterValueSet">is the filter information</param> /// <param name="filterCallback">is the callback</param> /// <param name="lockFactory">The lock factory.</param> /// <returns></returns> /// <exception cref="IllegalStateException">Callback for filter specification already exists in collection</exception> public FilterServiceEntry Add(FilterValueSet filterValueSet, FilterHandle filterCallback, FilterServiceGranularLockFactory lockFactory) { using (Instrument.With( i => i.QFilterAdd(filterValueSet, filterCallback), i => i.AFilterAdd())) { var eventType = filterValueSet.EventType; // Check if a filter tree exists for this event type var rootNode = _eventTypeIndex.Get(eventType); // Make sure we have a root node if (rootNode == null) { using (_callbacksLock.Acquire()) { rootNode = _eventTypeIndex.Get(eventType); if (rootNode == null) { rootNode = new FilterHandleSetNode(lockFactory.ObtainNew()); _eventTypeIndex.Add(eventType, rootNode); } } } // GetInstance add to tree var path = IndexTreeBuilder.Add(filterValueSet, filterCallback, rootNode, lockFactory); var pathArray = path.Select(p => p.ToArray()).ToArray(); var pair = new EventTypeIndexBuilderValueIndexesPair(filterValueSet, pathArray); // for non-isolatable callbacks the consumer keeps track of tree location if (_isolatableCallbacks == null) { return(pair); } // for isolatable callbacks this class is keeping track of tree location using (_callbacksLock.Acquire()) { _isolatableCallbacks.Put(filterCallback, pair); } return(null); } }