예제 #1
0
        private void RunAssertionContextPartitionSelection(EPServiceProvider epService)
        {
            var fields = "c0,c1,c2,c3".Split(',');

            epService.EPAdministrator.CreateEPL("create context MyCtx as group by IntPrimitive < -5 as grp1, group by IntPrimitive between -5 and +5 as grp2, group by IntPrimitive > 5 as grp3 from SupportBean");
            var stmt = epService.EPAdministrator.CreateEPL("context MyCtx select context.id as c0, context.label as c1, TheString as c2, sum(IntPrimitive) as c3 from SupportBean#keepall group by TheString");

            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            epService.EPRuntime.SendEvent(new SupportBean("E2", -5));
            epService.EPRuntime.SendEvent(new SupportBean("E1", 2));
            epService.EPRuntime.SendEvent(new SupportBean("E3", -100));
            epService.EPRuntime.SendEvent(new SupportBean("E3", -8));
            epService.EPRuntime.SendEvent(new SupportBean("E1", 60));
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), stmt.GetSafeEnumerator(), fields, new[] {
                new object[] { 0, "grp1", "E3", -108 },
                new object[] { 1, "grp2", "E1", 3 },
                new object[] { 1, "grp2", "E2", -5 },
                new object[] { 2, "grp3", "E1", 60 }
            });

            // test iterator targeted by context partition id
            var selectorById = new SupportSelectorById(Collections.SingletonSet(1));

            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(selectorById), stmt.GetSafeEnumerator(selectorById), fields, new[] { new object[] { 1, "grp2", "E1", 3 }, new object[] { 1, "grp2", "E2", -5 } });

            // test iterator targeted for a given category
            var selector = new SupportSelectorCategory(new HashSet <string>(Collections.List("grp1", "grp3")));

            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(selector), stmt.GetSafeEnumerator(selector), fields, new[] { new object[] { 0, "grp1", "E3", -108 }, new object[] { 2, "grp3", "E1", 60 } });

            // test iterator targeted for a given filtered category
            var filtered = new MySelectorFilteredCategory("grp1");

            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(filtered), stmt.GetSafeEnumerator(filtered), fields, new[] { new object[] { 0, "grp1", "E3", -108 } });
            Assert.IsFalse(stmt.GetEnumerator(new SupportSelectorCategory((ISet <string>)null)).MoveNext());
            Assert.IsFalse(stmt.GetEnumerator(new SupportSelectorCategory(Collections.GetEmptySet <string>())).MoveNext());

            // test always-false filter - compare context partition info
            filtered = new MySelectorFilteredCategory(null);
            Assert.IsFalse(stmt.GetEnumerator(filtered).MoveNext());
            EPAssertionUtil.AssertEqualsAnyOrder(new object[] { "grp1", "grp2", "grp3" }, filtered.Categories);

            try {
                stmt.GetEnumerator(new ProxyContextPartitionSelectorSegmented()
                {
                    ProcPartitionKeys = () => null
                });
                Assert.Fail();
            } catch (InvalidContextPartitionSelector ex) {
                Assert.IsTrue(ex.Message.StartsWith("Invalid context partition selector, expected an implementation class of any of [ContextPartitionSelectorAll, ContextPartitionSelectorFiltered, ContextPartitionSelectorById, ContextPartitionSelectorCategory] interfaces but received com."),
                              "message: " + ex.Message);
            }

            epService.EPAdministrator.DestroyAllStatements();
        }
예제 #2
0
            public void Run(RegressionEnvironment env)
            {
                var fields = new [] { "c0", "c1", "c2", "c3" };
                var milestone = new AtomicLong();
                var path = new RegressionPath();

                env.CompileDeploy(
                    "@Name('ctx') create context MyCtx as group by IntPrimitive < -5 as grp1, group by IntPrimitive between -5 and +5 as grp2, group by IntPrimitive > 5 as grp3 from SupportBean",
                    path);
                env.CompileDeploy(
                    "@Name('s0') context MyCtx select context.id as c0, context.label as c1, TheString as c2, sum(IntPrimitive) as c3 from SupportBean#keepall group by TheString",
                    path);

                env.SendEventBean(new SupportBean("E1", 1));
                env.SendEventBean(new SupportBean("E2", -5));
                env.SendEventBean(new SupportBean("E1", 2));

                env.MilestoneInc(milestone);

                env.SendEventBean(new SupportBean("E3", -100));
                env.SendEventBean(new SupportBean("E3", -8));
                env.SendEventBean(new SupportBean("E1", 60));
                EPAssertionUtil.AssertPropsPerRowAnyOrder(
                    env.Statement("s0").GetEnumerator(),
                    env.Statement("s0").GetSafeEnumerator(),
                    fields,
                    new[] {
                        new object[] {0, "grp1", "E3", -108},
                        new object[] {1, "grp2", "E1", 3},
                        new object[] {1, "grp2", "E2", -5},
                        new object[] {2, "grp3", "E1", 60}
                    });
                SupportContextPropUtil.AssertContextProps(
                    env,
                    "ctx",
                    "MyCtx",
                    new[] {0, 1, 2},
                    "label",
                    new[] {
                        new object[] {"grp1"},
                        new object[] {"grp2"},
                        new object[] {"grp3"}
                    });

                env.MilestoneInc(milestone);

                // test iterator targeted by context partition id
                var selectorById = new SupportSelectorById(Collections.SingletonList(1));
                EPAssertionUtil.AssertPropsPerRowAnyOrder(
                    env.Statement("s0").GetEnumerator(selectorById),
                    env.Statement("s0").GetSafeEnumerator(selectorById),
                    fields,
                    new[] {
                        new object[] {1, "grp2", "E1", 3},
                        new object[] {1, "grp2", "E2", -5}
                    });

                // test iterator targeted for a given category
                var selector = new SupportSelectorCategory(
                    new HashSet<string>(Arrays.AsList("grp1", "grp3")));
                EPAssertionUtil.AssertPropsPerRowAnyOrder(
                    env.Statement("s0").GetEnumerator(selector),
                    env.Statement("s0").GetSafeEnumerator(selector),
                    fields,
                    new[] {
                        new object[] {0, "grp1", "E3", -108},
                        new object[] {2, "grp3", "E1", 60}
                    });

                // test iterator targeted for a given filtered category
                var filtered = new MySelectorFilteredCategory("grp1");
                EPAssertionUtil.AssertPropsPerRowAnyOrder(
                    env.Statement("s0").GetEnumerator(filtered),
                    env.Statement("s0").GetSafeEnumerator(filtered),
                    fields,
                    new[] {
                        new object[] {0, "grp1", "E3", -108}
                    });
                Assert.IsFalse(
                    env.Statement("s0")
                        .GetEnumerator(
                            new SupportSelectorCategory(
                                (ISet<string>) null))
                        .MoveNext());
                Assert.IsFalse(
                    env.Statement("s0")
                        .GetEnumerator(
                            new SupportSelectorCategory(
                                new EmptySet<string>()))
                        .MoveNext());

                env.MilestoneInc(milestone);

                // test always-false filter - compare context partition info
                filtered = new MySelectorFilteredCategory(null);
                Assert.IsFalse(env.Statement("s0").GetEnumerator(filtered).MoveNext());
                EPAssertionUtil.AssertEqualsAnyOrder(new object[] {"grp1", "grp2", "grp3"}, filtered.Categories);

                try {
                    env.Statement("s0")
                        .GetEnumerator(
                            new ProxyContextPartitionSelectorSegmented {
                                ProcPartitionKeys = () => null
                            });
                    Assert.Fail();
                }
                catch (InvalidContextPartitionSelector ex) {
                    Assert.IsTrue(
                        ex.Message.StartsWith(
                            "Invalid context partition selector, expected an implementation class of any of [ContextPartitionSelectorAll, ContextPartitionSelectorFiltered, ContextPartitionSelectorById, ContextPartitionSelectorCategory] interfaces but received com."),
                        "message: " + ex.Message);
                }

                env.UndeployAll();
            }