Exemple #1
0
        public void TestNodeGetSet()
        {
            FilterHandle exprOne = new SupportFilterHandle();

            // Check pre-conditions
            Assert.IsTrue(testNode.NodeRWLock != null);
            Assert.IsFalse(testNode.Contains(exprOne));
            Assert.AreEqual(0, testNode.FilterCallbackCount);
            Assert.AreEqual(0, testNode.Indizes.Count);
            Assert.IsTrue(testNode.IsEmpty());

            testNode.Add(exprOne);

            // Check after add
            Assert.IsTrue(testNode.Contains(exprOne));
            Assert.AreEqual(1, testNode.FilterCallbackCount);
            Assert.IsFalse(testNode.IsEmpty());

            // Add an indexOne
            EventType eventType = SupportEventTypeFactory
                                  .GetInstance(container)
                                  .CreateBeanType(typeof(SupportBean));
            SupportExprEventEvaluator eval       = new SupportExprEventEvaluator(eventType.GetGetter("IntPrimitive"));
            ExprFilterSpecLookupable  lookupable = new ExprFilterSpecLookupable(
                "IntPrimitive",
                eval,
                null,
                eventType.GetPropertyType("IntPrimitive"),
                false,
                null);
            FilterParamIndexBase indexOne = new SupportFilterParamIndex(lookupable);

            testNode.Add(indexOne);

            // Check after add
            Assert.AreEqual(1, testNode.Indizes.Count);
            Assert.AreEqual(indexOne, testNode.Indizes[0]);

            // Check removes
            Assert.IsTrue(testNode.Remove(exprOne));
            Assert.IsFalse(testNode.IsEmpty());
            Assert.IsFalse(testNode.Remove(exprOne));
            Assert.IsTrue(testNode.Remove(indexOne));
            Assert.IsFalse(testNode.Remove(indexOne));
            Assert.IsTrue(testNode.IsEmpty());
        }
Exemple #2
0
        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();
        }