コード例 #1
0
        private void RunAssertionSubselect(EPServiceProvider epService)
        {
            var filterSPI = (FilterServiceSPI)((EPServiceProviderSPI)epService).FilterService;

            SendTimeEvent(epService, "2002-05-1T08:00:00.000");
            epService.EPAdministrator.CreateEPL("create context NineToFive as start (0, 9, *, *, *) end (0, 17, *, *, *)");

            var fields    = "TheString,col".Split(',');
            var listener  = new SupportUpdateListener();
            var statement = (EPStatementSPI)epService.EPAdministrator.CreateEPL("context NineToFive select TheString, (select p00 from SupportBean_S0#lastevent) as col from SupportBean");

            statement.Events += listener.Update;
            Assert.AreEqual(0, filterSPI.FilterCountApprox);   // from the context

            // now started
            SendTimeEvent(epService, "2002-05-1T09:00:00.000");
            Assert.AreEqual(2, filterSPI.FilterCountApprox);   // from the context

            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E1", null });

            epService.EPRuntime.SendEvent(new SupportBean_S0(11, "S01"));
            epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E2", "S01" });

            // now gone
            SendTimeEvent(epService, "2002-05-1T17:00:00.000");
            Assert.AreEqual(0, filterSPI.FilterCountApprox);   // from the context

            epService.EPRuntime.SendEvent(new SupportBean("Ex", 0));
            Assert.IsFalse(listener.IsInvoked);

            // now started
            SendTimeEvent(epService, "2002-05-2T09:00:00.000");
            Assert.AreEqual(2, filterSPI.FilterCountApprox);   // from the context
            Assert.IsFalse(listener.IsInvoked);

            epService.EPRuntime.SendEvent(new SupportBean("E3", 3));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E3", null });

            epService.EPRuntime.SendEvent(new SupportBean_S0(12, "S02"));
            epService.EPRuntime.SendEvent(new SupportBean("E4", 4));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E4", "S02" });
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 1, 1, 0, 0);

            // now gone
            SendTimeEvent(epService, "2002-05-2T17:00:00.000");
            Assert.AreEqual(0, filterSPI.FilterCountApprox);   // from the context

            epService.EPRuntime.SendEvent(new SupportBean("Ey", 0));
            Assert.IsFalse(listener.IsInvoked);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 0, 0, 0, 0);

            epService.EPAdministrator.DestroyAllStatements();
        }
コード例 #2
0
        private void RunAssertionCategory(EPServiceProvider epService)
        {
            var filterSpi = (FilterServiceSPI)((EPServiceProviderSPI)epService).FilterService;
            var ctx       = "CategorizedContext";

            epService.EPAdministrator.CreateEPL("@Name('context') create context " + ctx + " " +
                                                "group IntPrimitive < 10 as cat1, " +
                                                "group IntPrimitive between 10 and 20 as cat2, " +
                                                "group IntPrimitive > 20 as cat3 " +
                                                "from SupportBean");

            var fields    = "c0,c1,c2".Split(',');
            var statement = (EPStatementSPI)epService.EPAdministrator.CreateEPL("context CategorizedContext " +
                                                                                "select context.name as c0, context.label as c1, sum(IntPrimitive) as c2 from SupportBean");
            var listener = new SupportUpdateListener();

            statement.Events += listener.Update;
            Assert.AreEqual(3, filterSpi.FilterCountApprox);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 3, 0, 0, 0);

            epService.EPRuntime.SendEvent(new SupportBean("E1", 5));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { ctx, "cat1", 5 });
            EPAssertionUtil.AssertPropsPerRow(statement.GetEnumerator(), statement.GetSafeEnumerator(), fields, new[] { new object[] { ctx, "cat1", 5 }, new object[] { ctx, "cat2", null }, new object[] { ctx, "cat3", null } });

            epService.EPRuntime.SendEvent(new SupportBean("E2", 4));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { ctx, "cat1", 9 });

            epService.EPRuntime.SendEvent(new SupportBean("E3", 11));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { ctx, "cat2", 11 });

            epService.EPRuntime.SendEvent(new SupportBean("E4", 25));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { ctx, "cat3", 25 });

            epService.EPRuntime.SendEvent(new SupportBean("E5", 25));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { ctx, "cat3", 50 });

            epService.EPRuntime.SendEvent(new SupportBean("E6", 3));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { ctx, "cat1", 12 });

            EPAssertionUtil.AssertPropsPerRow(statement.GetEnumerator(), statement.GetSafeEnumerator(), fields, new[] { new object[] { ctx, "cat1", 12 }, new object[] { ctx, "cat2", 11 }, new object[] { ctx, "cat3", 50 } });

            statement.Stop();
            Assert.AreEqual(0, filterSpi.FilterCountApprox);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 0, 0, 0, 0);

            var spi = (EPServiceProviderSPI)epService;

            Assert.AreEqual(1, spi.ContextManagementService.ContextCount);
            epService.EPAdministrator.GetStatement("context").Dispose();
            Assert.AreEqual(1, spi.ContextManagementService.ContextCount);

            statement.Dispose();
            Assert.AreEqual(0, spi.ContextManagementService.ContextCount);
        }
コード例 #3
0
        public void TestSubselect()
        {
            FilterServiceSPI filterSPI = (FilterServiceSPI)_spi.FilterService;

            SendTimeEvent("2002-05-1 8:00:00.000");
            _epService.EPAdministrator.CreateEPL("create context NineToFive as start (0, 9, *, *, *) end (0, 17, *, *, *)");

            String[] fields = "TheString,col".Split(',');
            SupportUpdateListener listener  = new SupportUpdateListener();
            EPStatementSPI        statement = (EPStatementSPI)_epService.EPAdministrator.CreateEPL("context NineToFive select TheString, (select p00 from SupportBean_S0.std:lastevent()) as col from SupportBean");

            statement.Events += listener.Update;
            Assert.AreEqual(0, filterSPI.FilterCountApprox);   // from the context

            // now started
            SendTimeEvent("2002-05-1 9:00:00.000");
            Assert.AreEqual(2, filterSPI.FilterCountApprox);   // from the context

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new Object[] { "E1", null });

            _epService.EPRuntime.SendEvent(new SupportBean_S0(11, "S01"));
            _epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new Object[] { "E2", "S01" });

            // now gone
            SendTimeEvent("2002-05-1 17:00:00.000");
            Assert.AreEqual(0, filterSPI.FilterCountApprox);   // from the context

            _epService.EPRuntime.SendEvent(new SupportBean("Ex", 0));
            Assert.IsFalse(listener.IsInvoked);

            // now started
            SendTimeEvent("2002-05-2 9:00:00.000");
            Assert.AreEqual(2, filterSPI.FilterCountApprox);   // from the context
            Assert.IsFalse(listener.IsInvoked);

            _epService.EPRuntime.SendEvent(new SupportBean("E3", 3));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new Object[] { "E3", null });

            _epService.EPRuntime.SendEvent(new SupportBean_S0(12, "S02"));
            _epService.EPRuntime.SendEvent(new SupportBean("E4", 4));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new Object[] { "E4", "S02" });
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 1, 1, 0, 0);

            // now gone
            SendTimeEvent("2002-05-2 17:00:00.000");
            Assert.AreEqual(0, filterSPI.FilterCountApprox);   // from the context

            _epService.EPRuntime.SendEvent(new SupportBean("Ey", 0));
            Assert.IsFalse(listener.IsInvoked);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 0, 0, 0, 0);
        }
コード例 #4
0
        private void RunAssertionPrevPriorAndAggregation(EPServiceProvider epService)
        {
            SendTimeEvent(epService, "2002-05-1T08:00:00.000");
            epService.EPAdministrator.CreateEPL("create context NineToFive as start (0, 9, *, *, *) end (0, 17, *, *, *)");

            var fields    = "col1,col2,col3,col4,col5".Split(',');
            var listener  = new SupportUpdateListener();
            var statement = (EPStatementSPI)epService.EPAdministrator.CreateEPL("context NineToFive " +
                                                                                "select prev(TheString) as col1, prevwindow(sb) as col2, prevtail(TheString) as col3, prior(1, TheString) as col4, sum(IntPrimitive) as col5 " +
                                                                                "from SupportBean#keepall as sb");

            statement.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean());
            Assert.IsFalse(listener.IsInvoked);

            // now started
            SendTimeEvent(epService, "2002-05-1T09:00:00.000");
            var event1 = new SupportBean("E1", 1);

            epService.EPRuntime.SendEvent(event1);
            var expected = new object[][] { new object[] { null, new SupportBean[] { event1 }, "E1", null, 1 } };

            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, expected);
            EPAssertionUtil.AssertPropsPerRow(statement.GetEnumerator(), statement.GetSafeEnumerator(), fields, expected);

            var event2 = new SupportBean("E2", 2);

            epService.EPRuntime.SendEvent(event2);
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E1", new SupportBean[] { event2, event1 }, "E1", "E1", 3 });

            // now gone
            SendTimeEvent(epService, "2002-05-1T17:00:00.000");
            EPAssertionUtil.AssertPropsPerRow(statement.GetEnumerator(), statement.GetSafeEnumerator(), fields, null);

            epService.EPRuntime.SendEvent(new SupportBean());
            Assert.IsFalse(listener.IsInvoked);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 0, 0, 0, 0);

            // now started
            SendTimeEvent(epService, "2002-05-2T09:00:00.000");

            var event3 = new SupportBean("E3", 9);

            epService.EPRuntime.SendEvent(event3);
            expected = new object[][] { new object[] { null, new SupportBean[] { event3 }, "E3", null, 9 } };
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, expected);
            EPAssertionUtil.AssertPropsPerRow(statement.GetEnumerator(), statement.GetSafeEnumerator(), fields, expected);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 1, 0, 3, 1);

            epService.EPAdministrator.DestroyAllStatements();
        }
コード例 #5
0
        private void TryAssertionHash(EPServiceProvider epService, SupportUpdateListener listener, string ctx, EPStatementSPI statement, HashCodeFunc codeFunc)
        {
            string[] fields = "c0,c1,c2".Split(',');

            epService.EPRuntime.SendEvent(new SupportBean("E1", 5));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { ctx, "E1", 5 });
            AssertIterator(statement, fields, new[] { new object[] { ctx, "E1", 5 } });

            epService.EPRuntime.SendEvent(new SupportBean("E2", 6));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { ctx, "E2", 6 });
            AssertIterator(statement, fields, new[] { new object[] { ctx, "E1", 5 }, new object[] { ctx, "E2", 6 } });

            epService.EPRuntime.SendEvent(new SupportBean("E3", 7));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { ctx, "E3", 7 });
            AssertIterator(statement, fields, new[] { new object[] { ctx, "E1", 5 }, new object[] { ctx, "E3", 7 }, new object[] { ctx, "E2", 6 } });

            epService.EPRuntime.SendEvent(new SupportBean("E4", 8));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { ctx, "E4", 8 });
            AssertIterator(statement, fields, new[] { new object[] { ctx, "E1", 5 }, new object[] { ctx, "E3", 7 }, new object[] { ctx, "E4", 8 }, new object[] { ctx, "E2", 6 } });

            epService.EPRuntime.SendEvent(new SupportBean("E5", 9));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { ctx, "E5", 9 });
            AssertIterator(statement, fields, new[] { new object[] { ctx, "E5", 9 }, new object[] { ctx, "E1", 5 }, new object[] { ctx, "E3", 7 }, new object[] { ctx, "E4", 8 }, new object[] { ctx, "E2", 6 } });

            epService.EPRuntime.SendEvent(new SupportBean("E1", 10));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { ctx, "E1", 15 });
            AssertIterator(statement, fields, new[] { new object[] { ctx, "E5", 9 }, new object[] { ctx, "E1", 15 }, new object[] { ctx, "E3", 7 }, new object[] { ctx, "E4", 8 }, new object[] { ctx, "E2", 6 } });

            epService.EPRuntime.SendEvent(new SupportBean("E4", 11));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { ctx, "E4", 19 });
            AssertIterator(statement, fields, new[] { new object[] { ctx, "E5", 9 }, new object[] { ctx, "E1", 15 }, new object[] { ctx, "E3", 7 }, new object[] { ctx, "E4", 19 }, new object[] { ctx, "E2", 6 } });

            statement.Stop();
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 0, 0, 0, 0);

            EPServiceProviderSPI spi = (EPServiceProviderSPI)epService;

            Assert.AreEqual(1, spi.ContextManagementService.ContextCount);
            epService.EPAdministrator.GetStatement("context").Dispose();
            Assert.AreEqual(1, spi.ContextManagementService.ContextCount);

            statement.Dispose();
            Assert.AreEqual(0, spi.ContextManagementService.ContextCount);
        }
コード例 #6
0
        private void RunAssertion(String ctx, EPStatementSPI statement)
        {
            statement.Events += _listener.Update;

            var fields = "c0,c1,c2".Split(',');

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 5));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { ctx, "cat1", null });

            _epService.EPRuntime.SendEvent(new SupportBean("E2", 20));
            Assert.IsFalse(_listener.IsInvoked);

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 4));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { ctx, "cat1", 5 });

            _epService.EPAdministrator.GetStatement("context").Dispose();
            Assert.AreEqual(1, _spi.ContextManagementService.ContextCount);

            _epService.EPAdministrator.DestroyAllStatements();
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 0, 0, 0, 0);
            Assert.AreEqual(0, _spi.ContextManagementService.ContextCount);
        }
コード例 #7
0
ファイル: ContextCategory.cs プロジェクト: lanicon/nesper
            public void Run(RegressionEnvironment env)
            {
                var milestone = new AtomicLong();
                var ctx = "CategorizedContext";
                var fields = new [] { "c0", "c1", "c2" };

                var epl = "@Name('context') create context " +
                          ctx +
                          " " +
                          "group IntPrimitive < 10 as cat1, " +
                          "group IntPrimitive between 10 and 20 as cat2, " +
                          "group IntPrimitive > 20 as cat3 " +
                          "from SupportBean;\n";
                epl += "@Name('s0') context CategorizedContext " +
                       "select context.name as c0, context.label as c1, sum(IntPrimitive) as c2 from SupportBean;\n";
                env.CompileDeploy(epl).AddListener("s0");

                Assert.AreEqual(3, SupportFilterServiceHelper.GetFilterSvcCountApprox(env));
                AgentInstanceAssertionUtil.AssertInstanceCounts(env, "s0", 3, null, null, null);

                env.MilestoneInc(milestone);

                env.SendEventBean(new SupportBean("E1", 5));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {ctx, "cat1", 5});
                EPAssertionUtil.AssertPropsPerRow(
                    env.Statement("s0").GetEnumerator(),
                    env.Statement("s0").GetSafeEnumerator(),
                    fields,
                    new[] {
                        new object[] {ctx, "cat1", 5},
                        new object[] {ctx, "cat2", null},
                        new object[] {ctx, "cat3", null}
                    });

                env.MilestoneInc(milestone);

                env.SendEventBean(new SupportBean("E2", 4));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {ctx, "cat1", 9});

                env.SendEventBean(new SupportBean("E3", 11));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {ctx, "cat2", 11});

                env.MilestoneInc(milestone);

                env.SendEventBean(new SupportBean("E4", 25));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {ctx, "cat3", 25});

                env.SendEventBean(new SupportBean("E5", 25));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {ctx, "cat3", 50});

                env.MilestoneInc(milestone);

                env.SendEventBean(new SupportBean("E6", 3));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {ctx, "cat1", 12});

                EPAssertionUtil.AssertPropsPerRow(
                    env.Statement("s0").GetEnumerator(),
                    env.Statement("s0").GetSafeEnumerator(),
                    fields,
                    new[] {
                        new object[] {ctx, "cat1", 12},
                        new object[] {ctx, "cat2", 11},
                        new object[] {ctx, "cat3", 50}
                    });

                Assert.AreEqual(1, SupportContextMgmtHelper.GetContextCount(env));
                Assert.AreEqual(3, SupportFilterServiceHelper.GetFilterSvcCountApprox(env));

                env.UndeployModuleContaining("s0");

                Assert.AreEqual(0, SupportFilterServiceHelper.GetFilterSvcCountApprox(env));
                Assert.AreEqual(0, SupportContextMgmtHelper.GetContextCount(env));
            }
コード例 #8
0
            public void Run(RegressionEnvironment env)
            {
                // Comment-in to see CRC32 code.
                for (var i = 0; i < 10; i++) {
                    var key = "E" + i;
                    var code = SupportHashCodeFuncGranularCRC32.ComputeCRC32(key) % 4;
                    var hashCode = i.GetHashCode() % 4;
                    //System.out.println(key + " code " + code + " hashCode " + hashCode);
                }

                var path = new RegressionPath();
                var ctx = "HashSegmentedContext";
                var milestone = new AtomicLong();

                // test CRC32 Hash
                var eplCtx = "@Name('context') create context " +
                             ctx +
                             " as " +
                             "coalesce consistent_hash_crc32(TheString) from SupportBean " +
                             "granularity 4 " +
                             "preallocate";
                env.CompileDeploy(eplCtx, path);

                var eplStmt = "@Name('s0') context " +
                              ctx +
                              " " +
                              "select context.name as c0, TheString as c1, sum(IntPrimitive) as c2 from SupportBean#keepall group by TheString";
                env.CompileDeploy(eplStmt, path).AddListener("s0");
                Assert.AreEqual(4, SupportFilterServiceHelper.GetFilterSvcCountApprox(env));
                AgentInstanceAssertionUtil.AssertInstanceCounts(env, "s0", 4, null, null, null);

                TryAssertionHash(env, milestone, "s0", ctx); // equivalent to: SupportHashCodeFuncGranularCRC32(4)
                Assert.AreEqual(0, SupportFilterServiceHelper.GetFilterSvcCountApprox(env));
                path.Clear();

                // test same with SODA
                env.EplToModelCompileDeploy(eplCtx, path);
                env.CompileDeploy(eplStmt, path).AddListener("s0");
                TryAssertionHash(env, milestone, "s0", ctx);
                path.Clear();

                // test with Java-hashCode String hash
                env.CompileDeploy(
                    "@Name('context') create context " +
                    ctx +
                    " " +
                    "coalesce hash_code(TheString) from SupportBean " +
                    "granularity 6 " +
                    "preallocate",
                    path);

                env.CompileDeploy(
                    "@Name('s0') context " +
                    ctx +
                    " " +
                    "select context.name as c0, TheString as c1, sum(IntPrimitive) as c2 from SupportBean#keepall group by TheString",
                    path);
                env.AddListener("s0");
                Assert.AreEqual(6, SupportFilterServiceHelper.GetFilterSvcCountApprox(env));
                AgentInstanceAssertionUtil.AssertInstanceCounts(env, "s0", 6, null, null, null);

                TryAssertionHash(env, milestone, "s0", ctx);
                Assert.AreEqual(0, SupportFilterServiceHelper.GetFilterSvcCountApprox(env));
                path.Clear();

                // test no pre-allocate
                env.CompileDeploy(
                    "@Name('context') create context " +
                    ctx +
                    " " +
                    "coalesce hash_code(TheString) from SupportBean " +
                    "granularity 16",
                    path);

                env.CompileDeploy(
                    "@Name('s0') context " +
                    ctx +
                    " " +
                    "select context.name as c0, TheString as c1, sum(IntPrimitive) as c2 from SupportBean#keepall group by TheString",
                    path);
                env.AddListener("s0");
                Assert.AreEqual(1, SupportFilterServiceHelper.GetFilterSvcCountApprox(env));
                AgentInstanceAssertionUtil.AssertInstanceCounts(env, "s0", 0, null, null, null);

                TryAssertionHash(env, milestone, "s0", ctx);
                Assert.AreEqual(0, SupportFilterServiceHelper.GetFilterSvcCountApprox(env));

                env.UndeployAll();
            }
コード例 #9
0
        private void RunAssertionHashSegmented(EPServiceProvider epService)
        {
            // Comment-in to see CRC32 code.
            for (int i = 0; i < 10; i++)
            {
                string key      = "E" + i;
                long   code     = SupportHashCodeFuncGranularCRC32.ComputeCrc32(key) % 4;
                int    hashCode = i.GetHashCode() % 4;
                //Log.Info(key + " code " + code + " hashCode " + hashCode);
            }

            // test CRC32 Hash
            FilterServiceSPI filterSPI = (FilterServiceSPI)((EPServiceProviderSPI)epService).FilterService;
            string           ctx       = "HashSegmentedContext";
            string           eplCtx    = "@Name('context') create context " + ctx + " as " +
                                         "coalesce consistent_hash_crc32(TheString) from SupportBean " +
                                         "granularity 4 " +
                                         "preallocate";

            epService.EPAdministrator.CreateEPL(eplCtx);

            string eplStmt = "context " + ctx + " " +
                             "select context.name as c0, TheString as c1, sum(IntPrimitive) as c2 from SupportBean#keepall group by TheString";
            EPStatementSPI statement = (EPStatementSPI)epService.EPAdministrator.CreateEPL(eplStmt);
            var            listener  = new SupportUpdateListener();

            statement.Events += listener.Update;
            Assert.AreEqual(4, filterSPI.FilterCountApprox);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 4, 0, 0, 0);

            TryAssertionHash(epService, listener, ctx, statement, new SupportHashCodeFuncGranularCRC32(4).CodeFor);
            Assert.AreEqual(0, filterSPI.FilterCountApprox);

            // test same with SODA
            EPStatementObjectModel modelCtx = epService.EPAdministrator.CompileEPL(eplCtx);

            Assert.AreEqual(eplCtx, modelCtx.ToEPL());
            EPStatement stmtCtx = epService.EPAdministrator.Create(modelCtx);

            Assert.AreEqual(eplCtx, stmtCtx.Text);

            statement         = (EPStatementSPI)epService.EPAdministrator.CreateEPL(eplStmt);
            statement.Events += listener.Update;
            TryAssertionHash(epService, listener, ctx, statement, new SupportHashCodeFuncGranularCRC32(4).CodeFor);

            // test with Java-hashCode string hash
            epService.EPAdministrator.CreateEPL("@Name('context') create context " + ctx + " " +
                                                "coalesce hash_code(TheString) from SupportBean " +
                                                "granularity 6 " +
                                                "preallocate");

            statement = (EPStatementSPI)epService.EPAdministrator.CreateEPL("context " + ctx + " " +
                                                                            "select context.name as c0, TheString as c1, sum(IntPrimitive) as c2 from SupportBean#keepall group by TheString");
            statement.Events += listener.Update;
            Assert.AreEqual(6, filterSPI.FilterCountApprox);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 6, 0, 0, 0);

            TryAssertionHash(epService, listener, ctx, statement, HashCodeFuncGranularInternalHash(6));
            Assert.AreEqual(0, filterSPI.FilterCountApprox);

            // test no pre-allocate
            epService.EPAdministrator.CreateEPL("@Name('context') create context " + ctx + " " +
                                                "coalesce hash_code(TheString) from SupportBean " +
                                                "granularity 16 ");

            statement = (EPStatementSPI)epService.EPAdministrator.CreateEPL("context " + ctx + " " +
                                                                            "select context.name as c0, TheString as c1, sum(IntPrimitive) as c2 from SupportBean#keepall group by TheString");
            statement.Events += listener.Update;
            Assert.AreEqual(1, filterSPI.FilterCountApprox);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 0, 0, 0, 0);

            TryAssertionHash(epService, listener, ctx, statement, HashCodeFuncGranularInternalHash(16));
            Assert.AreEqual(0, filterSPI.FilterCountApprox);
        }
コード例 #10
0
        public void TestHashSegmented()
        {
            // Comment-in to see CRC32 code.
            for (var i = 0; i < 10; i++)
            {
                var key      = "E" + i;
                var code     = SupportHashCodeFuncGranularCRC32.ComputeCRC32(key) % 4;
                var hashCode = i.GetHashCode() % 4;
                //Console.WriteLine(key + " code " + code + " hashCode " + hashCode);
            }

            // test CRC32 Hash
            var filterSPI = (FilterServiceSPI)_spi.FilterService;
            var ctx       = "HashSegmentedContext";
            var eplCtx    = "@Name('context') create context " + ctx + " as " +
                            "coalesce Consistent_hash_crc32(TheString) from SupportBean " +
                            "granularity 4 " +
                            "preallocate";

            _epService.EPAdministrator.CreateEPL(eplCtx);

            var eplStmt = "context " + ctx + " " +
                          "select context.name as c0, TheString as c1, Sum(IntPrimitive) as c2 from SupportBean.win:keepall() group by TheString";
            var statement = (EPStatementSPI)_epService.EPAdministrator.CreateEPL(eplStmt);

            statement.Events += _listener.Update;
            Assert.AreEqual(4, filterSPI.FilterCountApprox);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 4, 0, 0, 0);

            RunAssertionHash(ctx, statement, new SupportHashCodeFuncGranularCRC32(4));
            Assert.AreEqual(0, filterSPI.FilterCountApprox);

            // test same with SODA
            var modelCtx = _epService.EPAdministrator.CompileEPL(eplCtx);

            Assert.AreEqual(eplCtx, modelCtx.ToEPL());
            var stmtCtx = _epService.EPAdministrator.Create(modelCtx);

            Assert.AreEqual(eplCtx, stmtCtx.Text);

            statement         = (EPStatementSPI)_epService.EPAdministrator.CreateEPL(eplStmt);
            statement.Events += _listener.Update;
            RunAssertionHash(ctx, statement, new SupportHashCodeFuncGranularCRC32(4));

            // test with GetHashCode String hash
            _epService.EPAdministrator.CreateEPL("@Name('context') create context " + ctx + " " +
                                                 "coalesce Hash_code(TheString) from SupportBean " +
                                                 "granularity 6 " +
                                                 "preallocate");

            statement = (EPStatementSPI)_epService.EPAdministrator.CreateEPL("context " + ctx + " " +
                                                                             "select context.name as c0, TheString as c1, Sum(IntPrimitive) as c2 from SupportBean.win:keepall() group by TheString");
            statement.Events += _listener.Update;
            Assert.AreEqual(6, filterSPI.FilterCountApprox);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 6, 0, 0, 0);

            RunAssertionHash(ctx, statement, new HashCodeFuncGranularInternalHash(6));
            Assert.AreEqual(0, filterSPI.FilterCountApprox);

            // test no pre-allocate
            _epService.EPAdministrator.CreateEPL("@Name('context') create context " + ctx + " " +
                                                 "coalesce Hash_code(TheString) from SupportBean " +
                                                 "granularity 16 ");

            statement = (EPStatementSPI)_epService.EPAdministrator.CreateEPL("context " + ctx + " " +
                                                                             "select context.name as c0, TheString as c1, Sum(IntPrimitive) as c2 from SupportBean.win:keepall() group by TheString");
            statement.Events += _listener.Update;
            Assert.AreEqual(1, filterSPI.FilterCountApprox);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 0, 0, 0, 0);

            RunAssertionHash(ctx, statement, new HashCodeFuncGranularInternalHash(16));
            Assert.AreEqual(0, filterSPI.FilterCountApprox);
        }