示例#1
0
            public void Run(RegressionEnvironment env)
            {
                var name = "MyContextStartS0EndS1";
                var path = new RegressionPath();
                var contextEPL =
                    "@Name('ctx') create context MyContextStartS0EndS1 start SupportBean_S0 as S0 end SupportBean_S1";
                env.CompileDeploy(contextEPL, path);
                var depIdCtx = env.DeploymentId("ctx");

                var listener = new SupportContextListener(env);
                env.Runtime.ContextPartitionService.AddContextPartitionStateListener(
                    depIdCtx,
                    "MyContextStartS0EndS1",
                    listener);
                env.CompileDeploy("@Name('a') context MyContextStartS0EndS1 select count(*) from SupportBean", path);
                var depIdA = env.DeploymentId("a");
                env.CompileDeploy("@Name('b') context MyContextStartS0EndS1 select count(*) from SupportBean_S0", path);
                var depIdB = env.DeploymentId("b");

                listener.AssertAndReset(
                    EventContextWStmt(depIdCtx, name, typeof(ContextStateEventContextStatementAdded), depIdA, "a"),
                    EventContext(depIdCtx, name, typeof(ContextStateEventContextActivated)),
                    EventContextWStmt(depIdCtx, name, typeof(ContextStateEventContextStatementAdded), depIdB, "b"));

                env.SendEventBean(new SupportBean_S0(1));
                listener.AssertAndReset(
                    EventPartitionInitTerm(depIdCtx, name, typeof(ContextStateEventContextPartitionAllocated)));

                env.UndeployAll();
            }
示例#2
0
            public void Run(RegressionEnvironment env)
            {
                var listener = new SupportContextListener(env);
                env.Runtime.ContextPartitionService.AddContextStateListener(listener);

                var path = new RegressionPath();
                env.CompileDeploy(
                    "@Name('ctx') create context MyContext " +
                    "context ContextPosNeg group by IntPrimitive > 0 as pos, group by IntPrimitive < 0 as neg from SupportBean, " +
                    "context ByString partition by TheString from SupportBean",
                    path);
                var depIdCtx = env.DeploymentId("ctx");
                listener.AssertAndReset(EventContext(depIdCtx, "MyContext", typeof(ContextStateEventContextCreated)));

                env.CompileDeploy("@Name('s0') context MyContext select count(*) from SupportBean", path);
                var depIdStmt = env.DeploymentId("s0");
                listener.AssertAndReset(
                    EventContextWStmt(
                        depIdCtx,
                        "MyContext",
                        typeof(ContextStateEventContextStatementAdded),
                        depIdStmt,
                        "s0"),
                    EventContext(depIdCtx, "MyContext", typeof(ContextStateEventContextActivated)));

                env.SendEventBean(new SupportBean("E1", 1));
                var allocated = listener.GetAllocatedEvents();
                Assert.AreEqual(1, allocated.Count);
                var nested = (ContextPartitionIdentifierNested) allocated[0].Identifier;
                EPAssertionUtil.AssertEqualsExactOrder(
                    new [] { "E1" },
                    ((ContextPartitionIdentifierPartitioned) nested.Identifiers[1]).Keys);
                Assert.AreEqual(1, listener.GetAndReset().Count);

                env.UndeployModuleContaining("s0");
                listener.AssertAndReset(
                    EventContextWStmt(
                        depIdCtx,
                        "MyContext",
                        typeof(ContextStateEventContextStatementRemoved),
                        depIdStmt,
                        "s0"),
                    EventPartitionInitTerm(depIdCtx, "MyContext", typeof(ContextStateEventContextPartitionDeallocated)),
                    EventContext(depIdCtx, "MyContext", typeof(ContextStateEventContextDeactivated)));

                env.UndeployModuleContaining("ctx");
                listener.AssertAndReset(EventContext(depIdCtx, "MyContext", typeof(ContextStateEventContextDestroyed)));

                env.Runtime.ContextPartitionService.RemoveContextStateListeners();
            }
示例#3
0
            public void Run(RegressionEnvironment env)
            {
                var listener = new SupportContextListener(env);
                env.Runtime.ContextPartitionService.AddContextStateListener(listener);

                var path = new RegressionPath();
                env.CompileDeploy(
                    "@Name('ctx') create context MyContext start SupportBean_S0 as S0 end SupportBean_S1",
                    path);
                var depIdCtx = env.DeploymentId("ctx");
                listener.AssertAndReset(EventContext(depIdCtx, "MyContext", typeof(ContextStateEventContextCreated)));

                env.CompileDeploy("@Name('s0') context MyContext select count(*) from SupportBean", path);
                var depIdStmt = env.DeploymentId("s0");
                listener.AssertAndReset(
                    EventContextWStmt(
                        depIdCtx,
                        "MyContext",
                        typeof(ContextStateEventContextStatementAdded),
                        depIdStmt,
                        "s0"),
                    EventContext(depIdCtx, "MyContext", typeof(ContextStateEventContextActivated)));

                env.SendEventBean(new SupportBean_S0(1));
                listener.AssertAndReset(
                    EventPartitionInitTerm(depIdCtx, "MyContext", typeof(ContextStateEventContextPartitionAllocated)));

                env.SendEventBean(new SupportBean_S1(1));
                listener.AssertAndReset(
                    EventPartitionInitTerm(
                        depIdCtx,
                        "MyContext",
                        typeof(ContextStateEventContextPartitionDeallocated)));

                env.UndeployModuleContaining("s0");
                listener.AssertAndReset(
                    EventContextWStmt(
                        depIdCtx,
                        "MyContext",
                        typeof(ContextStateEventContextStatementRemoved),
                        depIdStmt,
                        "s0"),
                    EventContext(depIdCtx, "MyContext", typeof(ContextStateEventContextDeactivated)));

                env.UndeployModuleContaining("ctx");
                listener.AssertAndReset(EventContext(depIdCtx, "MyContext", typeof(ContextStateEventContextDestroyed)));

                env.Runtime.ContextPartitionService.RemoveContextStateListeners();
            }
示例#4
0
            public void Run(RegressionEnvironment env)
            {
                var listener = new SupportContextListener(env);
                env.Runtime.ContextPartitionService.AddContextStateListener(listener);

                var path = new RegressionPath();
                env.CompileDeploy(
                    "@Name('ctx') create context MyContext group by IntPrimitive > 0 as pos, group by IntPrimitive < 0 as neg from SupportBean",
                    path);
                env.CompileDeploy("@Name('s0') context MyContext select count(*) from SupportBean", path);

                var allocated = listener.GetAllocatedEvents();
                Assert.AreEqual(2, allocated.Count);
                Assert.AreEqual("neg", ((ContextPartitionIdentifierCategory) allocated[1].Identifier).Label);
                listener.GetAndReset();

                env.UndeployModuleContaining("s0");
                env.UndeployModuleContaining("ctx");
                env.Runtime.ContextPartitionService.RemoveContextStateListeners();
            }
示例#5
0
            public void Run(RegressionEnvironment env)
            {
                var api = env.Runtime.ContextPartitionService;

                var epl = "@Name('ctx') create context MyContext start SupportBean_S0 as S0 end SupportBean_S1";
                var listeners = new SupportContextListener[3];
                for (var i = 0; i < listeners.Length; i++) {
                    listeners[i] = new SupportContextListener(env);
                    env.Runtime.ContextPartitionService.AddContextStateListener(listeners[i]);
                }

                env.CompileDeploy(epl);
                var depIdCtx = env.DeploymentId("ctx");
                for (var i = 0; i < listeners.Length; i++) {
                    listeners[i]
                        .AssertAndReset(EventContext(depIdCtx, "MyContext", typeof(ContextStateEventContextCreated)));
                }

                api.RemoveContextStateListener(listeners[0]);
                env.UndeployModuleContaining("ctx");
                listeners[0].AssertNotInvoked();
                listeners[1]
                    .AssertAndReset(EventContext(depIdCtx, "MyContext", typeof(ContextStateEventContextDestroyed)));
                listeners[2]
                    .AssertAndReset(EventContext(depIdCtx, "MyContext", typeof(ContextStateEventContextDestroyed)));

                var enumerator = api.ContextStateListeners;
                Assert.AreSame(listeners[1], enumerator.Advance());
                Assert.AreSame(listeners[2], enumerator.Advance());
                Assert.IsFalse(enumerator.MoveNext());

                api.RemoveContextStateListeners();
                Assert.IsFalse(api.ContextStateListeners.MoveNext());

                env.CompileDeploy(epl);
                env.UndeployAll();
                for (var i = 0; i < listeners.Length; i++) {
                    listeners[i].AssertNotInvoked();
                }
            }
示例#6
0
            public void Run(RegressionEnvironment env)
            {
                var listener = new SupportContextListener(env);
                env.Runtime.ContextPartitionService.AddContextStateListener(listener);

                var epl =
                    "@Name('ctx') create context MyContext coalesce by consistent_hash_crc32(TheString) from SupportBean granularity 2 preallocate;\n" +
                    "@Name('s0') context MyContext select count(*) from SupportBean;\n";
                env.CompileDeploy(epl);
                var deploymentId = env.DeploymentId("s0");

                var allocated = listener.GetAllocatedEvents();
                Assert.AreEqual(2, allocated.Count);
                Assert.AreEqual(1, ((ContextPartitionIdentifierHash) allocated[1].Identifier).Hash);
                listener.GetAndReset();

                env.UndeployAll();

                listener.AssertAndReset(
                    EventContextWStmt(
                        deploymentId,
                        "MyContext",
                        typeof(ContextStateEventContextStatementRemoved),
                        deploymentId,
                        "s0"),
                    EventPartitionInitTerm(
                        deploymentId,
                        "MyContext",
                        typeof(ContextStateEventContextPartitionDeallocated)),
                    EventPartitionInitTerm(
                        deploymentId,
                        "MyContext",
                        typeof(ContextStateEventContextPartitionDeallocated)),
                    EventContext(deploymentId, "MyContext", typeof(ContextStateEventContextDeactivated)),
                    EventContext(deploymentId, "MyContext", typeof(ContextStateEventContextDestroyed)));

                env.Runtime.ContextPartitionService.RemoveContextStateListeners();
            }
示例#7
0
        private static void RunAssertionPartitionAddRemoveListener(
            RegressionEnvironment env,
            string eplContext,
            string contextName)
        {
            var path = new RegressionPath();
            env.CompileDeploy("@Name('ctx') " + eplContext, path);
            env.CompileDeploy("@Name('s0') context " + contextName + " select count(*) from SupportBean", path);
            var api = env.Runtime.ContextPartitionService;
            var depIdCtx = env.DeploymentId("ctx");

            var listeners = new SupportContextListener[3];
            for (var i = 0; i < listeners.Length; i++) {
                listeners[i] = new SupportContextListener(env);
                env.Runtime.ContextPartitionService.AddContextPartitionStateListener(
                    depIdCtx,
                    contextName,
                    listeners[i]);
            }

            env.SendEventBean(new SupportBean_S0(1));
            for (var i = 0; i < listeners.Length; i++) {
                listeners[i]
                    .AssertAndReset(
                        EventPartitionInitTerm(
                            depIdCtx,
                            contextName,
                            typeof(ContextStateEventContextPartitionAllocated)));
            }

            api.RemoveContextPartitionStateListener(depIdCtx, contextName, listeners[0]);
            env.SendEventBean(new SupportBean_S1(1));
            listeners[0].AssertNotInvoked();
            listeners[1]
                .AssertAndReset(
                    EventPartitionInitTerm(
                        depIdCtx,
                        contextName,
                        typeof(ContextStateEventContextPartitionDeallocated)));
            listeners[2]
                .AssertAndReset(
                    EventPartitionInitTerm(
                        depIdCtx,
                        contextName,
                        typeof(ContextStateEventContextPartitionDeallocated)));

            var enumerator = api.GetContextPartitionStateListeners(depIdCtx, contextName);
            Assert.AreSame(listeners[1], enumerator.Advance());
            Assert.AreSame(listeners[2], enumerator.Advance());
            Assert.IsFalse(enumerator.MoveNext());

            api.RemoveContextPartitionStateListeners(depIdCtx, contextName);
            Assert.IsFalse(api.GetContextPartitionStateListeners(depIdCtx, contextName).MoveNext());

            env.SendEventBean(new SupportBean_S0(2));
            env.SendEventBean(new SupportBean_S1(2));
            for (var i = 0; i < listeners.Length; i++) {
                listeners[i].AssertNotInvoked();
            }

            env.UndeployAll();
        }