public void TestNodeMatching() { SupportBeanSimple eventObject = new SupportBeanSimple("DepositEvent_1", 1); EventBean eventBean = SupportEventBeanFactory.CreateObject(eventObject); FilterHandle expr = new SupportFilterHandle(); _testNode.Add(expr); // Check matching without an index node List <FilterHandle> matches = new List <FilterHandle>(); _testNode.MatchEvent(eventBean, matches); 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), ReaderWriterLockManager.CreateDefaultLock()); _testNode.Add(index); index["DepositEvent_1"] = _testEvaluator; // Verify matcher instance stored in index is called _testNode.MatchEvent(eventBean, matches); Assert.IsTrue(_testEvaluator.GetAndResetCountInvoked() == 1); Assert.IsTrue(_testEvaluator.GetLastEvent() == eventBean); Assert.AreEqual(1, matches.Count); Assert.AreEqual(expr, matches[0]); }
public void TestBoolean() { FilterParamIndexEquals index = MakeOne("BoolPrimitive", _testEventType); index.Put(false, _testEvaluator); VerifyBooleanPrimitive(index, false, 1); VerifyBooleanPrimitive(index, true, 0); }
public void TestFloatPrimitive() { FilterParamIndexEquals index = MakeOne("FloatPrimitive", _testEventType); index.Put(1.5f, _testEvaluator); VerifyFloatPrimitive(index, 1.5f, 1); VerifyFloatPrimitive(index, 2.2f, 0); VerifyFloatPrimitive(index, 0, 0); }
public void TestString() { FilterParamIndexEquals index = MakeOne("TheString", _testEventType); index["hello"] = _testEvaluator; index["test"] = _testEvaluator; VerifyString(index, null, 0); VerifyString(index, "dudu", 0); VerifyString(index, "hello", 1); VerifyString(index, "test", 1); }
public void TestLong() { FilterParamIndexEquals index = MakeOne("ShortBoxed", _testEventType); index.Put(((short)1), _testEvaluator); index.Put(((short)20), _testEvaluator); VerifyShortBoxed(index, (short)10, 0); VerifyShortBoxed(index, (short)1, 1); VerifyShortBoxed(index, (short)20, 1); VerifyShortBoxed(index, null, 0); Assert.AreEqual(_testEvaluator, index.Get((short)1)); Assert.IsTrue(index.ReadWriteLock != null); index.Remove((short)1); index.Remove((short)1); Assert.AreEqual(null, index.Get((short)1)); }
/// <summary> /// Factory for indexes that store filter parameter constants for a given event property and filter operator. /// <para /> /// Does not perform any check of validity of property name. /// </summary> /// <param name="lookupable">The lookupable.</param> /// <param name="lockFactory">The lock factory.</param> /// <param name="filterOperator">is the type of index to use</param> /// <returns> /// the proper index based on the filter operator type /// </returns> /// <exception cref="System.ArgumentException">Cannot create filter index instance for filter operator + filterOperator</exception> public static FilterParamIndexBase CreateIndex(FilterSpecLookupable lookupable, FilterServiceGranularLockFactory lockFactory, FilterOperator filterOperator) { FilterParamIndexBase index; Type returnValueType = lookupable.ReturnType; // Handle all EQUAL comparisons if (filterOperator == FilterOperator.EQUAL) { index = new FilterParamIndexEquals(lookupable, lockFactory.ObtainNew()); return(index); } // Handle all NOT-EQUAL comparisons if (filterOperator == FilterOperator.NOT_EQUAL) { index = new FilterParamIndexNotEquals(lookupable, lockFactory.ObtainNew()); return(index); } if (filterOperator == FilterOperator.IS) { index = new FilterParamIndexEqualsIs(lookupable, lockFactory.ObtainNew()); return(index); } if (filterOperator == FilterOperator.IS_NOT) { index = new FilterParamIndexNotEqualsIs(lookupable, lockFactory.ObtainNew()); return(index); } // Handle all GREATER, LESS etc. comparisons if ((filterOperator == FilterOperator.GREATER) || (filterOperator == FilterOperator.GREATER_OR_EQUAL) || (filterOperator == FilterOperator.LESS) || (filterOperator == FilterOperator.LESS_OR_EQUAL)) { if (returnValueType != typeof(String)) { index = new FilterParamIndexCompare(lookupable, lockFactory.ObtainNew(), filterOperator); } else { index = new FilterParamIndexCompareString(lookupable, lockFactory.ObtainNew(), filterOperator); } return(index); } // Handle all normal and inverted RANGE comparisons if (filterOperator.IsRangeOperator()) { if (returnValueType != typeof(String)) { index = new FilterParamIndexDoubleRange(lookupable, lockFactory.ObtainNew(), filterOperator); } else { index = new FilterParamIndexStringRange(lookupable, lockFactory.ObtainNew(), filterOperator); } return(index); } if (filterOperator.IsInvertedRangeOperator()) { if (returnValueType != typeof(String)) { return(new FilterParamIndexDoubleRangeInverted(lookupable, lockFactory.ObtainNew(), filterOperator)); } else { return(new FilterParamIndexStringRangeInverted(lookupable, lockFactory.ObtainNew(), filterOperator)); } } // Handle all IN and NOT IN comparisons if (filterOperator == FilterOperator.IN_LIST_OF_VALUES) { return(new FilterParamIndexIn(lookupable, lockFactory.ObtainNew())); } if (filterOperator == FilterOperator.NOT_IN_LIST_OF_VALUES) { return(new FilterParamIndexNotIn(lookupable, lockFactory.ObtainNew())); } // Handle all bool expression if (filterOperator == FilterOperator.BOOLEAN_EXPRESSION) { return(new FilterParamIndexBooleanExpr(lockFactory.ObtainNew())); } throw new ArgumentException("Cannot create filter index instance for filter operator " + filterOperator); }
/// <summary> /// Factory for indexes that store filter parameter constants for a given event property and filter operator. /// <para /> /// Does not perform any check of validity of property name. /// </summary> /// <param name="lookupable">The lookupable.</param> /// <param name="lockFactory">The lock factory.</param> /// <param name="filterOperator">is the type of index to use</param> /// <returns> /// the proper index based on the filter operator type /// </returns> /// <exception cref="System.ArgumentException">Cannot create filter index instance for filter operator + filterOperator</exception> public static FilterParamIndexBase CreateIndex( FilterSpecLookupable lookupable, FilterServiceGranularLockFactory lockFactory, FilterOperator filterOperator) { FilterParamIndexBase index; Type returnValueType = lookupable.ReturnType; // Handle all EQUAL comparisons if (filterOperator == FilterOperator.EQUAL) { index = new FilterParamIndexEquals(lookupable, lockFactory.ObtainNew()); return(index); } // Handle all NOT-EQUAL comparisons if (filterOperator == FilterOperator.NOT_EQUAL) { index = new FilterParamIndexNotEquals(lookupable, lockFactory.ObtainNew()); return(index); } if (filterOperator == FilterOperator.IS) { index = new FilterParamIndexEqualsIs(lookupable, lockFactory.ObtainNew()); return(index); } if (filterOperator == FilterOperator.IS_NOT) { index = new FilterParamIndexNotEqualsIs(lookupable, lockFactory.ObtainNew()); return(index); } // Handle all GREATER, LESS etc. comparisons if ((filterOperator == FilterOperator.GREATER) || (filterOperator == FilterOperator.GREATER_OR_EQUAL) || (filterOperator == FilterOperator.LESS) || (filterOperator == FilterOperator.LESS_OR_EQUAL)) { if (returnValueType != typeof(String)) { index = new FilterParamIndexCompare(lookupable, lockFactory.ObtainNew(), filterOperator); } else { index = new FilterParamIndexCompareString(lookupable, lockFactory.ObtainNew(), filterOperator); } return(index); } // Handle all normal and inverted RANGE comparisons if (filterOperator.IsRangeOperator()) { if (returnValueType != typeof(String)) { index = new FilterParamIndexDoubleRange(lookupable, lockFactory.ObtainNew(), filterOperator); } else { index = new FilterParamIndexStringRange(lookupable, lockFactory.ObtainNew(), filterOperator); } return(index); } if (filterOperator.IsInvertedRangeOperator()) { if (returnValueType != typeof(String)) { return(new FilterParamIndexDoubleRangeInverted(lookupable, lockFactory.ObtainNew(), filterOperator)); } else { return(new FilterParamIndexStringRangeInverted(lookupable, lockFactory.ObtainNew(), filterOperator)); } } // Handle all IN and NOT IN comparisons if (filterOperator == FilterOperator.IN_LIST_OF_VALUES) { return(new FilterParamIndexIn(lookupable, lockFactory.ObtainNew())); } if (filterOperator == FilterOperator.NOT_IN_LIST_OF_VALUES) { return(new FilterParamIndexNotIn(lookupable, lockFactory.ObtainNew())); } // Handle all bool expression if (filterOperator == FilterOperator.BOOLEAN_EXPRESSION) { return(new FilterParamIndexBooleanExpr(lockFactory.ObtainNew())); } // Handle advanced-index if (filterOperator == FilterOperator.ADVANCED_INDEX) { FilterSpecLookupableAdvancedIndex advLookable = (FilterSpecLookupableAdvancedIndex)lookupable; if (advLookable.IndexType.Equals(EngineImportApplicationDotMethodPointInsideRectangle.INDEX_TYPE_NAME)) { return(new FilterParamIndexQuadTreePointRegion(lockFactory.ObtainNew(), lookupable)); } else if (advLookable.IndexType.Equals(EngineImportApplicationDotMethodRectangeIntersectsRectangle.INDEX_TYPE_NAME)) { return(new FilterParamIndexQuadTreeMXCIF(lockFactory.ObtainNew(), lookupable)); } else { throw new IllegalStateException("Unrecognized index type " + advLookable.IndexType); } } throw new ArgumentException("Cannot create filter index instance for filter operator " + filterOperator); }