Ejemplo n.º 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.CreateBeanType(typeof(SupportBean));
            FilterSpecLookupable lookupable = new FilterSpecLookupable("IntPrimitive", eventType.GetGetter("IntPrimitive"), eventType.GetPropertyType("IntPrimitive"), false);
            FilterParamIndexBase indexOne   = new SupportFilterParamIndex(lookupable);

            _testNode.Add(indexOne);

            // Check after add
            Assert.AreEqual(1, _testNode.Indizes.Count);
            Assert.AreEqual(indexOne, _testNode.Indizes.FirstOrDefault());

            // 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());
        }
Ejemplo n.º 2
0
        public void TestBuildWithMatch()
        {
            var topNode = new FilterHandleSetNode(_container.RWLockManager().CreateDefaultLock());

            // Add some parameter-less expression
            var filterSpec = MakeFilterValues();

            IndexTreeBuilder.Add(filterSpec, _testFilterCallback[0], topNode, _lockFactory);
            Assert.IsTrue(topNode.Contains(_testFilterCallback[0]));

            // Attempt a match
            topNode.MatchEvent(_eventBean, _matches);
            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);
            IndexTreeBuilder.Add(filterSpec, _testFilterCallback[1], topNode, _lockFactory);
            Assert.IsTrue(topNode.Indizes.Count == 1);
            Assert.IsTrue(topNode.Indizes[0].Count == 1);

            // Match again
            topNode.MatchEvent(_eventBean, _matches);
            Assert.IsTrue(_matches.Count == 1);
            _matches.Clear();

            // Add a filter that will match
            filterSpec = MakeFilterValues("IntPrimitive", FilterOperator.EQUAL, 50);
            IndexTreeBuilder.Add(filterSpec, _testFilterCallback[2], topNode, _lockFactory);
            Assert.IsTrue(topNode.Indizes.Count == 1);
            Assert.IsTrue(topNode.Indizes[0].Count == 2);

            // match
            topNode.MatchEvent(_eventBean, _matches);
            Assert.IsTrue(_matches.Count == 2);
            _matches.Clear();

            // Add some filter against a double
            filterSpec = MakeFilterValues("DoublePrimitive", FilterOperator.LESS, 1.1);
            IndexTreeBuilder.Add(filterSpec, _testFilterCallback[3], topNode, _lockFactory);
            Assert.IsTrue(topNode.Indizes.Count == 2);
            Assert.IsTrue(topNode.Indizes[0].Count == 2);
            Assert.IsTrue(topNode.Indizes[1].Count == 1);

            topNode.MatchEvent(_eventBean, _matches);
            Assert.IsTrue(_matches.Count == 3);
            _matches.Clear();

            filterSpec = MakeFilterValues("DoublePrimitive", FilterOperator.LESS_OR_EQUAL, 0.5);
            IndexTreeBuilder.Add(filterSpec, _testFilterCallback[4], topNode, _lockFactory);
            Assert.IsTrue(topNode.Indizes.Count == 3);
            Assert.IsTrue(topNode.Indizes[0].Count == 2);
            Assert.IsTrue(topNode.Indizes[1].Count == 1);
            Assert.IsTrue(topNode.Indizes[2].Count == 1);

            topNode.MatchEvent(_eventBean, _matches);
            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");
            IndexTreeBuilder.Add(filterSpec, _testFilterCallback[5], topNode, _lockFactory);
            Assert.IsTrue(topNode.Indizes.Count == 3);
            Assert.IsTrue(topNode.Indizes[0].Count == 2);
            Assert.IsTrue(topNode.Indizes[1].Count == 1);
            Assert.IsTrue(topNode.Indizes[2].Count == 1);
            var nextLevelSetNode = (FilterHandleSetNode)topNode.Indizes[1][1.1d];

            Assert.IsTrue(nextLevelSetNode != null);
            Assert.IsTrue(nextLevelSetNode.Indizes.Count == 1);

            topNode.MatchEvent(_eventBean, _matches);
            Assert.IsTrue(_matches.Count == 5);
            _matches.Clear();

            filterSpec = MakeFilterValues("DoublePrimitive", FilterOperator.LESS, 1.1,
                                          "TheString", FilterOperator.EQUAL, "beta");
            IndexTreeBuilder.Add(filterSpec, _testFilterCallback[6], topNode, _lockFactory);

            topNode.MatchEvent(_eventBean, _matches);
            Assert.IsTrue(_matches.Count == 5);
            _matches.Clear();

            filterSpec = MakeFilterValues("DoublePrimitive", FilterOperator.LESS, 1.1,
                                          "TheString", FilterOperator.EQUAL, "jack");
            IndexTreeBuilder.Add(filterSpec, _testFilterCallback[7], topNode, _lockFactory);
            Assert.IsTrue(nextLevelSetNode.Indizes.Count == 1);
            var nodeTwo = (FilterHandleSetNode)nextLevelSetNode.Indizes[0]["jack"];

            Assert.IsTrue(nodeTwo.FilterCallbackCount == 2);

            topNode.MatchEvent(_eventBean, _matches);
            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);
            IndexTreeBuilder.Add(filterSpec, _testFilterCallback[8], topNode, _lockFactory);

            topNode.MatchEvent(_eventBean, _matches);
            Assert.IsTrue(_matches.Count == 7);
            _matches.Clear();

            // Add an filterSpec in the middle
            filterSpec = MakeFilterValues("LongPrimitive", FilterOperator.EQUAL, 10L,
                                          "TheString", FilterOperator.EQUAL, "jack");
            IndexTreeBuilder.Add(filterSpec, _testFilterCallback[9], topNode, _lockFactory);

            filterSpec = MakeFilterValues("LongPrimitive", FilterOperator.EQUAL, 10L,
                                          "TheString", FilterOperator.EQUAL, "jim");
            IndexTreeBuilder.Add(filterSpec, _testFilterCallback[10], topNode, _lockFactory);

            filterSpec = MakeFilterValues("LongPrimitive", FilterOperator.EQUAL, 10L,
                                          "TheString", FilterOperator.EQUAL, "joe");
            IndexTreeBuilder.Add(filterSpec, _testFilterCallback[11], topNode, _lockFactory);

            topNode.MatchEvent(_eventBean, _matches);
            Assert.IsTrue(_matches.Count == 8);
            _matches.Clear();
        }