Exemplo n.º 1
0
            public void Run(RegressionEnvironment env)
            {
                var epl =
                    "@public @buseventtype create schema CarEvent(carId string, tracked boolean);\n" +
                    "create table StatusTable(carId string primary key, lastevent CarEvent);\n" +
                    "on CarEvent(tracked=true) as ce merge StatusTable as st where ce.carId = st.carId \n" +
                    "  when matched \n" +
                    "    then update set lastevent = ce \n" +
                    "  when not matched \n" +
                    "    then insert(carId, lastevent) select ce.carId, ce \n" +
                    "    then insert into CarOutputStream select 'online' as Status, ce as outputevent;\n" +
                    "insert into CarTimeoutStream select e.* \n" +
                    "  from pattern[every e=CarEvent(tracked=true) -> (timer:interval(1 minutes) and not CarEvent(carId = e.carId, tracked=true))];\n" +
                    "on CarTimeoutStream as cts merge StatusTable as st where cts.carId = st.carId \n" +
                    "  when matched \n" +
                    "    then delete \n" +
                    "    then insert into CarOutputStream select 'offline' as Status, lastevent as outputevent;\n" +
                    "@Name('s0') select * from CarOutputStream";
                env.AdvanceTime(0);
                env.CompileDeploy(epl).AddListener("s0");

                SendCarMap(env, "C1");
                AssertReceivedMap(env.Listener("s0").AssertOneGetNewAndReset(), "online", "C1");

                env.Milestone(0);

                env.AdvanceTime(60000);
                AssertReceivedMap(env.Listener("s0").AssertOneGetNewAndReset(), "offline", "C1");

                env.UndeployAll();
            }
Exemplo n.º 2
0
            public void Run(RegressionEnvironment env)
            {
                var epl = "@Name('create') create variable int myvar = $X;\n" +
                          "on pattern[every timer:interval(10)] set myvar = myvar + 1;\n";
                env.AdvanceTime(0);
                var idOne = env.DeployGetId(env.Compile(epl.Replace("$X", "10")));
                var idTwo = env.DeployGetId(env.Compile(epl.Replace("$X", "20")));

                AssertVariable(env, idOne, 10);
                AssertVariable(env, idTwo, 20);

                env.AdvanceTime(10000);

                AssertVariable(env, idOne, 11);
                AssertVariable(env, idTwo, 21);

                env.Undeploy(idOne);

                env.AdvanceTime(20000);

                Assert.IsNull(env.Runtime.DeploymentService.GetStatement(idOne, "create"));
                AssertVariable(env, idTwo, 22);

                env.Undeploy(idTwo);
                Assert.IsNull(env.Runtime.DeploymentService.GetStatement(idTwo, "create"));
            }
Exemplo n.º 3
0
            public void Run(RegressionEnvironment env)
            {
                env.AdvanceTime(0);
                string epl = "@Name('s0') select distinct IntOne from SupportEventWithManyArray output every 1 seconds";
                env.CompileDeploy(epl).AddListener("s0");

                SendManyArray(env, new int[] {1, 2});
                SendManyArray(env, new int[] {2, 1});
                SendManyArray(env, new int[] {2, 3});
                SendManyArray(env, new int[] {1, 2});
                SendManyArray(env, new int[] {1, 2});

                env.AdvanceTime(1000);

                EPAssertionUtil.AssertPropsPerRow(
                    env.Listener("s0").GetAndResetLastNewData(),
                    "IntOne".SplitCsv(),
                    new object[][] {
                        new object[] {new int[] {1, 2}},
                        new object[] {new int[] {2, 1}},
                        new object[] {new int[] {2, 3}}
                    });

                env.UndeployAll();
            }
Exemplo n.º 4
0
            public void Run(RegressionEnvironment env)
            {
                env.AdvanceTime(1000);

                // no iterator allowed
                var stmtText = "@Name('s0') select count(*) as num " +
                               "from pattern [every timer:at(*/1,*,*,*,*)] unidirectional,\n" +
                               "SupportBean(IntPrimitive=1)#unique(TheString) a,\n" +
                               "SupportBean(IntPrimitive=2)#unique(TheString) b\n" +
                               "where a.TheString = b.TheString output every 2 minutes";
                env.CompileDeployAddListenerMileZero(stmtText, "s0");

                SendEvent(env, "A", 1);
                SendEvent(env, "A", 2);
                SendEvent(env, "B", 1);
                SendEvent(env, "B", 2);
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                env.AdvanceTime(70000);
                env.AdvanceTime(140000);

                env.AdvanceTime(210000);
                Assert.AreEqual(2L, env.Listener("s0").LastNewData[0].Get("num"));
                Assert.AreEqual(2L, env.Listener("s0").LastNewData[1].Get("num"));

                env.UndeployAll();
            }
Exemplo n.º 5
0
        private static void RunAssertionSelectIStream(
            RegressionEnvironment env,
            string dbname)
        {
            // set time to zero
            env.AdvanceTime(0);

            var stmtText = "@Name('s0') select istream myvarchar from " +
                           "SupportBean_S0#time(1 sec) as S0," +
                           " sql:" +
                           dbname +
                           " ['select myvarchar from mytesttable where ${Id} = mytesttable.myBigint'] as S1";
            env.CompileDeploy(stmtText).AddListener("s0");

            // Send 100 events which all fireStatementStopped a join
            for (var i = 0; i < 100; i++) {
                var bean = new SupportBean_S0(5);
                env.SendEventBean(bean);
                Assert.AreEqual("E", env.Listener("s0").AssertOneGetNewAndReset().Get("myvarchar"));
            }

            // now advance the time, this should not produce events or join
            var startTime = PerformanceObserver.MilliTime;
            env.AdvanceTime(2000);
            var endTime = PerformanceObserver.MilliTime;

            // log.info(".testSelectIStream delta=" + (endTime - startTime));
            Assert.IsTrue(endTime - startTime < 200);
            Assert.IsFalse(env.Listener("s0").IsInvoked);

            env.UndeployAll();
        }
Exemplo n.º 6
0
            public void Run(RegressionEnvironment env)
            {
                var epl =
                    $"create schema CarOutputStream(Status string, outputevent {typeof(SupportBean).MaskTypeName()});\n" +
                    $"create table StatusTable(TheString string primary key, lastevent {typeof(SupportBean).MaskTypeName()});\n" +
                    "on SupportBean as ce merge StatusTable as st where ce.TheString = st.TheString \n" +
                    "  when matched \n" +
                    "    then update set lastevent = ce \n" +
                    "  when not matched \n" +
                    "    then insert select ce.TheString as TheString, ce as lastevent\n" +
                    "    then insert into CarOutputStream select 'online' as Status, ce as outputevent;\n" +
                    "insert into CarTimeoutStream select e.* \n" +
                    "  from pattern[every e=SupportBean -> (timer:interval(1 minutes) and not SupportBean(TheString = e.TheString))];\n" +
                    "on CarTimeoutStream as cts merge StatusTable as st where cts.TheString = st.TheString \n" +
                    "  when matched \n" +
                    "    then delete \n" +
                    "    then insert into CarOutputStream select 'offline' as Status, lastevent as outputevent;\n" +
                    "@Name('s0') select * from CarOutputStream";
                env.AdvanceTime(0);
                env.CompileDeploy(epl).AddListener("s0");

                env.SendEventBean(new SupportBean("E1", 1));
                AssertReceivedPojo(env.Listener("s0").AssertOneGetNewAndReset(), "online", "E1");

                env.Milestone(0);

                env.AdvanceTime(60000);
                AssertReceivedPojo(env.Listener("s0").AssertOneGetNewAndReset(), "offline", "E1");

                env.UndeployAll();
            }
Exemplo n.º 7
0
            public void Run(RegressionEnvironment env)
            {
                env.AdvanceTime(0);
                string epl =
                    "@public @buseventtype @JsonSchema(ClassName='" +
                    typeof(MyLocalJsonProvidedEventOne).FullName +
                    "') create json schema EventOne();\n" +
                    "@public @buseventtype @JsonSchema(ClassName='" +
                    typeof(MyLocalJsonProvidedEventTwo).FullName +
                    "') create json schema EventTwo();\n" +
                    "@public @buseventtype @JsonSchema(ClassName='" +
                    typeof(MyLocalJsonProvidedEventOut).FullName +
                    "') create json schema EventOut();\n" +
                    "@Name('s0') insert into EventOut select s as startEvent, e as endEvents from pattern [" +
                    "every s=EventOne -> e=EventTwo(id=s.id) until timer:interval(10 sec)]";

                env.CompileDeploy(epl).AddListener("s0");

                env.SendEventJson("{\"id\":\"G1\"}", "EventOne");
                env.SendEventJson("{\"id\":\"G1\",\"val\":2}", "EventTwo");
                env.SendEventJson("{\"id\":\"G1\",\"val\":3}", "EventTwo");
                env.AdvanceTime(10000);

                MyLocalJsonProvidedEventOut @out = (MyLocalJsonProvidedEventOut)env.Listener("s0").AssertOneGetNewAndReset().Underlying;

                Assert.AreEqual("G1", @out.startEvent.id);
                Assert.AreEqual("G1", @out.endEvents[0].id);
                Assert.AreEqual(2, @out.endEvents[0].val);
                Assert.AreEqual("G1", @out.endEvents[1].id);
                Assert.AreEqual(3, @out.endEvents[1].val);

                env.UndeployAll();
            }
Exemplo n.º 8
0
        private static void TryGroupByAssertions(RegressionEnvironment env)
        {
            AssertSelectResultType(env.Statement("s0"));

            env.AdvanceTime(0);

            SendEvent(env, SYMBOL_DELL, 10000, 51);
            AssertEvents(env, SYMBOL_DELL, 10000, 51, false);

            SendEvent(env, SYMBOL_IBM, 30000, 70);
            AssertEvents(env, SYMBOL_IBM, 30000, 70, false);

            SendEvent(env, SYMBOL_DELL, 20000, 52);
            AssertEvents(env, SYMBOL_DELL, 20000, 103, false);

            SendEvent(env, SYMBOL_IBM, 30000, 70);
            AssertEvents(env, SYMBOL_IBM, 30000, 140, false);

            env.AdvanceTime(35000);

            //These events are out of the window and new sums are generated
            SendEvent(env, SYMBOL_DELL, 10000, 90);
            AssertEvents(env, SYMBOL_DELL, 10000, 90, false);

            SendEvent(env, SYMBOL_IBM, 30000, 120);
            AssertEvents(env, SYMBOL_IBM, 30000, 120, false);

            SendEvent(env, SYMBOL_DELL, 20000, 90);
            AssertEvents(env, SYMBOL_DELL, 20000, 180, false);

            SendEvent(env, SYMBOL_IBM, 30000, 120);
            AssertEvents(env, SYMBOL_IBM, 30000, 240, false);
        }
Exemplo n.º 9
0
            public void Run(RegressionEnvironment env)
            {
                env.AdvanceTime(0);

                env.CompileDeploy(
                        "@Name('s0') insert into MyStream select * from SupportBean output first every 1 second;\n" +
                        "@Name('s1') select * from MyStream")
                    .AddListener("s0")
                    .AddListener("s1");

                env.SendEventBean(new SupportBean("E1", 0));
                AssertReceivedS0AndS1(
                    env,
                    new[] {new object[] {"E1"}});

                env.SendEventBean(new SupportBean("E2", 0));
                Assert.IsFalse(env.Listener("s0").IsInvoked);
                Assert.IsFalse(env.Listener("s1").IsInvoked);

                env.AdvanceTime(1000);

                env.SendEventBean(new SupportBean("E2", 0));
                AssertReceivedS0AndS1(
                    env,
                    new[] {new object[] {"E2"}});

                env.UndeployAll();
            }
Exemplo n.º 10
0
            public void Run(RegressionEnvironment env)
            {
                env.AdvanceTime(0);

                var stmtText = "@Name('s0') select mychar from " +
                               " sql:MyDBWithRetain ['select mychar from mytesttable where mytesttable.myBigint = 2'] as S0," +
                               " pattern [every timer:interval(5 sec) ]";
                env.CompileDeploy(stmtText).AddListener("s0");

                env.AdvanceTime(5000);
                Assert.AreEqual("Y", env.Listener("s0").AssertOneGetNewAndReset().Get("mychar"));

                env.AdvanceTime(9999);
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                env.AdvanceTime(10000);
                Assert.AreEqual("Y", env.Listener("s0").AssertOneGetNewAndReset().Get("mychar"));

                // with variable
                var path = new RegressionPath();
                env.CompileDeploy("create variable long VarLastTimestamp = 0", path);
                var epl = "@Name('Poll every 5 seconds') insert into PollStream" +
                          " select * from pattern[every timer:interval(5 sec)]," +
                          " sql:MyDBWithRetain ['select mychar from mytesttable where mytesttable.myBigint > ${VarLastTimestamp}'] as S0";
                var model = env.EplToModel(epl);
                env.CompileDeploy(model, path);
                env.UndeployAll();
            }
Exemplo n.º 11
0
            public void Run(RegressionEnvironment env)
            {
                var stmtText = "@Name('s0') select irstream a.Id as idA, b.Id as idB, " +
                               "a.P00 as P00A, b.P00 as P00B from pattern [every a=SupportBean_S0" +
                               " -> every b=SupportBean_S0(P00=a.P00)]#time(1)";
                env.CompileDeploy(stmtText).AddListener("s0");
                env.AdvanceTime(0);

                SendEvent(env, 1, "e1a");
                Assert.IsFalse(env.Listener("s0").IsInvoked);
                SendEvent(env, 2, "e1a");
                AssertNewEvent(env, 1, 2, "e1a");

                env.AdvanceTime(500);
                SendEvent(env, 10, "e2a");
                SendEvent(env, 11, "e2b");
                SendEvent(env, 12, "e2c");
                Assert.IsFalse(env.Listener("s0").IsInvoked);
                SendEvent(env, 13, "e2b");
                AssertNewEvent(env, 11, 13, "e2b");

                env.AdvanceTime(1000);
                AssertOldEvent(env, 1, 2, "e1a");

                env.AdvanceTime(1500);
                AssertOldEvent(env, 11, 13, "e2b");

                env.UndeployAll();
            }
            public void Run(RegressionEnvironment env)
            {
                MyStaticEval.CountCalled = 0;
                MyStaticEval.WaitTimeMSec = 0;
                env.AdvanceTime(0);

                var epl = "@Name('s0') select * from " +
                          " SupportBean#time(1) as sb, " +
                          " SupportBean_S0#keepall as S0 " +
                          " where myStaticEvaluator(sb.TheString, S0.P00)";
                env.CompileDeployAddListenerMileZero(epl, "s0");

                env.SendEventBean(new SupportBean_S0(1, "x"));
                Assert.AreEqual(0, MyStaticEval.CountCalled);

                env.SendEventBean(new SupportBean("y", 10));
                Assert.AreEqual(1, MyStaticEval.CountCalled);
                Assert.IsTrue(env.Listener("s0").IsInvoked);

                // this would be observed as hanging if there was remove-stream evaluation
                MyStaticEval.WaitTimeMSec = 10000000;
                env.AdvanceTime(100000);

                env.UndeployAll();
            }
Exemplo n.º 13
0
        private static void RunAssertionPattern(
            RegressionEnvironment env,
            long startTime,
            string patternExpr,
            params long[] flipTimes)
        {
            env.AdvanceTime(startTime);

            var epl = "@Name('s0') select * from pattern[" + patternExpr + "]";
            env.CompileDeploy(epl).AddListener("s0");

            var count = 0;
            foreach (var flipTime in flipTimes) {
                env.AdvanceTime(flipTime - 1);
                Assert.IsFalse(env.Listener("s0").GetAndClearIsInvoked(), "Failed for flip " + count);

                env.AdvanceTime(flipTime);
                Assert.IsTrue(env.Listener("s0").GetAndClearIsInvoked(), "Failed for flip " + count);
                count++;
            }

            env.AdvanceTime(long.MaxValue);
            Assert.IsFalse(env.Listener("s0").GetAndClearIsInvoked());

            env.UndeployAll();
        }
Exemplo n.º 14
0
            public void Run(RegressionEnvironment env)
            {
                env.AdvanceTime(0);

                // Every event generates a new row, this time we sum the price by symbol and output volume
                var epl = "@Name('s0') select Symbol, Volume, sum(Price) as mySum from SupportMarketDataBean#time(30)";
                env.CompileDeployAddListenerMileZero(epl, "s0");

                AssertSelectResultType(env.Statement("s0"));

                SendEvent(env, SYMBOL_DELL, 10000, 51);
                AssertEvents(env, SYMBOL_DELL, 10000, 51, false);

                SendEvent(env, SYMBOL_IBM, 20000, 52);
                AssertEvents(env, SYMBOL_IBM, 20000, 103, false);

                SendEvent(env, SYMBOL_DELL, 40000, 45);
                AssertEvents(env, SYMBOL_DELL, 40000, 148, false);

                env.AdvanceTime(35000);

                //These events are out of the window and new sums are generated

                SendEvent(env, SYMBOL_IBM, 30000, 70);
                AssertEvents(env, SYMBOL_IBM, 30000, 70, false);

                SendEvent(env, SYMBOL_DELL, 10000, 20);
                AssertEvents(env, SYMBOL_DELL, 10000, 90, false);

                env.UndeployAll();
            }
Exemplo n.º 15
0
            public void Run(RegressionEnvironment env)
            {
                env.AdvanceTime(0);
                string[] fields = {"TheString"};

                var epl = "create variable boolean KEEP = true;\n" +
                          "@Name('s0') select irstream * from SupportBean#expr(KEEP);\n";
                env.CompileDeploy(epl).AddListener("s0");

                env.AdvanceTime(1000);
                env.SendEventBean(new SupportBean("E1", 1));
                EPAssertionUtil.AssertPropsPerRow(
                    env.Statement("s0").GetEnumerator(),
                    fields,
                    new[] {new object[] {"E1"}});

                env.Runtime.VariableService.SetVariableValue(env.DeploymentId("s0"), "KEEP", false);
                EPAssertionUtil.AssertPropsPerRow(
                    env.Statement("s0").GetEnumerator(),
                    fields,
                    new[] {new object[] {"E1"}});

                env.Listener("s0").Reset();
                env.AdvanceTime(1001);
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetOldAndReset(),
                    fields,
                    new object[] {"E1"});
                Assert.IsFalse(env.Statement("s0").GetEnumerator().MoveNext());

                env.Milestone(0);

                env.SendEventBean(new SupportBean("E2", 2));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").LastNewData[0],
                    fields,
                    new object[] {"E2"});
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").LastOldData[0],
                    fields,
                    new object[] {"E2"});
                env.Listener("s0").Reset();
                Assert.IsFalse(env.Statement("s0").GetEnumerator().MoveNext());

                env.Runtime.VariableService.SetVariableValue(env.DeploymentId("s0"), "KEEP", true);

                env.SendEventBean(new SupportBean("E3", 3));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"E3"});
                EPAssertionUtil.AssertPropsPerRow(
                    env.Statement("s0").GetEnumerator(),
                    fields,
                    new[] {new object[] {"E3"}});

                env.UndeployAll();
            }
Exemplo n.º 16
0
            public void Run(RegressionEnvironment env)
            {
                env.AdvanceTime(0);
                string[] fields = {"TheString"};

                var epl = "create variable boolean POST = false;\n" +
                          "@Name('s0') select irstream * from SupportBean#expr_batch(POST);\n";
                env.CompileDeployAddListenerMileZero(epl, "s0");

                env.AdvanceTime(1000);
                env.SendEventBean(new SupportBean("E1", 1));
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                env.Runtime.VariableService.SetVariableValue(env.DeploymentId("s0"), "POST", true);
                env.AdvanceTime(1001);
                EPAssertionUtil.AssertPropsPerRow(
                    env.Listener("s0").GetAndResetDataListsFlattened(),
                    fields,
                    new[] {new object[] {"E1"}},
                    null);

                env.SendEventBean(new SupportBean("E2", 1));
                EPAssertionUtil.AssertPropsPerRow(
                    env.Listener("s0").GetAndResetDataListsFlattened(),
                    fields,
                    new[] {new object[] {"E2"}},
                    new[] {new object[] {"E1"}});

                env.SendEventBean(new SupportBean("E3", 1));
                EPAssertionUtil.AssertPropsPerRow(
                    env.Listener("s0").GetAndResetDataListsFlattened(),
                    fields,
                    new[] {new object[] {"E3"}},
                    new[] {new object[] {"E2"}});

                env.Runtime.VariableService.SetVariableValue(env.DeploymentId("s0"), "POST", false);
                env.SendEventBean(new SupportBean("E4", 1));
                env.SendEventBean(new SupportBean("E5", 2));
                env.AdvanceTime(2000);
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                env.Runtime.VariableService.SetVariableValue(env.DeploymentId("s0"), "POST", true);
                env.AdvanceTime(2001);
                EPAssertionUtil.AssertPropsPerRow(
                    env.Listener("s0").GetAndResetDataListsFlattened(),
                    fields,
                    new[] {new object[] {"E4"}, new object[] {"E5"}},
                    new[] {new object[] {"E3"}});

                env.SendEventBean(new SupportBean("E6", 1));
                EPAssertionUtil.AssertPropsPerRow(
                    env.Listener("s0").GetAndResetDataListsFlattened(),
                    fields,
                    new[] {new object[] {"E6"}},
                    new[] {new object[] {"E4"}, new object[] {"E5"}});

                env.UndeployAll();
            }
Exemplo n.º 17
0
            public void Run(RegressionEnvironment env)
            {
                if (env.IsHA) {
                    return;
                }

                var graph = "@Name('flow') create dataflow MySelect\n" +
                            "Emitter -> instream_s0<SupportBean>{name: 'emitterS0'}\n" +
                            "select(instream_s0) -> outstream {\n" +
                            "  select: (select sum(IntPrimitive) as sumInt from instream_s0 output snapshot every 1 minute)\n" +
                            "}\n" +
                            "DefaultSupportCaptureOp(outstream) {}\n";
                env.AdvanceTime(0);
                env.CompileDeploy(graph);

                var capture = new DefaultSupportCaptureOp();
                var operators = CollectionUtil.PopulateNameValueMap("DefaultSupportCaptureOp", capture);

                var options =
                    new EPDataFlowInstantiationOptions().WithOperatorProvider(
                        new DefaultSupportGraphOpProviderByOpName(operators));
                var instance = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MySelect", options);
                var captive = instance.StartCaptive();
                var emitter = captive.Emitters.Get("emitterS0");

                env.AdvanceTime(5000);
                emitter.Submit(new SupportBean("E1", 5));
                emitter.Submit(new SupportBean("E2", 3));
                emitter.Submit(new SupportBean("E3", 6));
                Assert.AreEqual(0, capture.GetCurrentAndReset().Length);

                env.AdvanceTime(60000 + 5000);
                EPAssertionUtil.AssertProps(
                    env.Container,
                    (object[]) capture.GetCurrentAndReset()[0],
                    new [] { "sumInt" },
                    new object[] {14});

                emitter.Submit(new SupportBean("E4", 3));
                emitter.Submit(new SupportBean("E5", 6));
                Assert.AreEqual(0, capture.GetCurrentAndReset().Length);

                env.AdvanceTime(120000 + 5000);
                EPAssertionUtil.AssertProps(
                    env.Container,
                    (object[]) capture.GetCurrentAndReset()[0],
                    new [] { "sumInt" },
                    new object[] {14 + 9});

                instance.Cancel();

                emitter.Submit(new SupportBean("E5", 6));
                env.AdvanceTime(240000 + 5000);
                Assert.AreEqual(0, capture.GetCurrentAndReset().Length);

                env.UndeployAll();
            }
Exemplo n.º 18
0
            public void Run(RegressionEnvironment env)
            {
                var fields = new[] {"c0", "c1"};
                env.AdvanceTime(0);
                var epl =
                    "@Name('s0') select irstream TheString as c0, IntPrimitive as c1 from SupportBean#firsttime(10 sec)";
                env.CompileDeployAddListenerMileZero(epl, "s0");

                env.Milestone(1);

                EPAssertionUtil.AssertPropsPerRow(env.GetEnumerator("s0"), fields, new object[0][]);
                SendSupportBean(env, "E1", 1);
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"E1", 1});

                env.Milestone(2);

                EPAssertionUtil.AssertPropsPerRowAnyOrder(
                    env.GetEnumerator("s0"),
                    fields,
                    new[] {new object[] {"E1", 1}});
                env.AdvanceTime(2000);
                SendSupportBean(env, "E2", 20);
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"E2", 20});

                env.Milestone(3);

                env.AdvanceTime(9999);

                env.Milestone(4);

                env.AdvanceTime(10000);
                EPAssertionUtil.AssertPropsPerRowAnyOrder(
                    env.GetEnumerator("s0"),
                    fields,
                    new[] {new object[] {"E1", 1}, new object[] {"E2", 20}});
                SendSupportBean(env, "E3", 30);
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                env.Milestone(5);

                SendSupportBean(env, "E4", 40);
                Assert.IsFalse(env.Listener("s0").IsInvoked);
                EPAssertionUtil.AssertPropsPerRowAnyOrder(
                    env.GetEnumerator("s0"),
                    fields,
                    new[] {new object[] {"E1", 1}, new object[] {"E2", 20}});

                env.UndeployAll();
            }
Exemplo n.º 19
0
            public void Run(RegressionEnvironment env)
            {
                var stmt =
                    "@Name('s0') select * from pattern [every [2] (a=SupportBean_A() -> b=SupportBean_B(Id=a.Id))]";

                env.CompileDeploy(stmt);
                env.AddListener("s0");

                env.SendEventBean(new SupportBean_A("A1"));
                env.SendEventBean(new SupportBean_B("A1"));
                env.SendEventBean(new SupportBean_A("A2"));
                env.SendEventBean(new SupportBean_B("A2"));
                Assert.IsTrue(env.Listener("s0").IsInvoked);

                env.UndeployAll();

                // test with timer:interval
                env.AdvanceTime(0);
                var query =
                    "@Name('s0') select * from pattern [every ([2:]e1=SupportBean(TheString='2') until timer:interval(5))->([2:]e2=SupportBean(TheString='3') until timer:interval(2))]";
                env.CompileDeploy(query).AddListener("s0");

                env.SendEventBean(new SupportBean("2", 0));
                env.SendEventBean(new SupportBean("2", 0));
                env.AdvanceTime(5000);

                env.SendEventBean(new SupportBean("3", 0));
                env.SendEventBean(new SupportBean("3", 0));
                env.SendEventBean(new SupportBean("3", 0));
                env.SendEventBean(new SupportBean("3", 0));
                env.AdvanceTime(10000);

                env.SendEventBean(new SupportBean("2", 0));
                env.SendEventBean(new SupportBean("2", 0));
                env.AdvanceTime(15000);

                // test followed by 3 streams
                env.UndeployAll();

                var epl = "@Name('s0') select * from pattern [ every [2] A=SupportBean(TheString='1') " +
                          "-> [2] B=SupportBean(TheString='2' and IntPrimitive=A[0].IntPrimitive)" +
                          "-> [2] C=SupportBean(TheString='3' and IntPrimitive=A[0].IntPrimitive)]";
                env.CompileDeploy(epl).AddListener("s0");

                env.SendEventBean(new SupportBean("1", 10));
                env.SendEventBean(new SupportBean("1", 20));
                env.SendEventBean(new SupportBean("2", 10));
                env.SendEventBean(new SupportBean("2", 10));
                env.SendEventBean(new SupportBean("3", 10));
                env.SendEventBean(new SupportBean("3", 10));
                Assert.IsTrue(env.Listener("s0").IsInvoked);

                env.UndeployAll();
            }
Exemplo n.º 20
0
        private static void AssertReceivedAtTime(
            RegressionEnvironment env,
            string time)
        {
            var msec = DateTimeParsingFunctions.ParseDefaultMSecWZone(time);

            env.AdvanceTime(msec - 1);
            Assert.IsFalse(env.Listener("s0").IsInvokedAndReset());

            env.AdvanceTime(msec);
            Assert.IsTrue(env.Listener("s0").IsInvokedAndReset(), "expected but not received at " + time);
        }
Exemplo n.º 21
0
        private static void TrySend(
            RegressionEnvironment env,
            int numThreads,
            int numRepeats)
        {
            // set time to 0
            env.AdvanceTime(0);

            var listener = new SupportMTUpdateListener();
            env.CompileDeploy(
                "@Name('s0') select irstream IntPrimitive, TheString as key from SupportBean#time(1 sec)");
            env.Statement("s0").AddListener(listener);

            var threadPool = Executors.NewFixedThreadPool(
                numThreads,
                new SupportThreadFactory(typeof(MultithreadStmtTimeWindow)).ThreadFactory);
            var futures = new List<IFuture<bool>>();
            for (var i = 0; i < numThreads; i++) {
                var callable = new SendEventCallable(i, env.Runtime, new GeneratorEnumerator(numRepeats));
                futures.Add(threadPool.Submit(callable));
            }

            // Advance time window every 100 milliseconds for 1 second
            for (var i = 0; i < 10; i++) {
                env.AdvanceTime(i * 1000);
                SupportCompileDeployUtil.ThreadSleep(100);
            }

            threadPool.Shutdown();
            SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS);
            SupportCompileDeployUtil.AssertFutures(futures);

            // set time to a large value
            env.AdvanceTime(10000000000L);

            // Assert results
            var totalExpected = numThreads * numRepeats;

            // assert new data
            var resultNewData = listener.GetNewDataListFlattened();
            Assert.AreEqual(totalExpected, resultNewData.Length);
            var resultsNewData = SortPerIntKey(resultNewData);
            AssertResult(numRepeats, numThreads, resultsNewData);

            // assert old data
            var resultOldData = listener.GetOldDataListFlattened();
            Assert.AreEqual(totalExpected, resultOldData.Length);
            var resultsOldData = SortPerIntKey(resultOldData);
            AssertResult(numRepeats, numThreads, resultsOldData);

            env.UndeployAll();
        }
Exemplo n.º 22
0
        public void Run(RegressionEnvironment env)
        {
            var path = new RegressionPath();
            env.CompileDeploy("create window MyWindowOne#keepall as (TheString string, intv int)", path);
            env.CompileDeploy("insert into MyWindowOne select TheString, IntPrimitive as intv from SupportBean", path);

            env.AdvanceTime(0);

            string[] fields = {"TheString", "c"};
            env.CompileDeploy(
                    "@Name('s0') select irstream TheString, count(*) as c from MyWindowOne group by TheString output snapshot every 1 second",
                    path)
                .AddListener("s0");

            env.SendEventBean(new SupportBean("A", 1));
            env.SendEventBean(new SupportBean("A", 2));
            env.SendEventBean(new SupportBean("B", 4));

            env.AdvanceTime(1000);

            EPAssertionUtil.AssertPropsPerRow(
                env.Listener("s0").GetAndResetLastNewData(),
                fields,
                new[] {new object[] {"A", 2L}, new object[] {"B", 1L}});

            env.SendEventBean(new SupportBean("B", 5));
            env.AdvanceTime(2000);

            EPAssertionUtil.AssertPropsPerRow(
                env.Listener("s0").GetAndResetLastNewData(),
                fields,
                new[] {new object[] {"A", 2L}, new object[] {"B", 2L}});

            env.AdvanceTime(3000);

            EPAssertionUtil.AssertPropsPerRow(
                env.Listener("s0").GetAndResetLastNewData(),
                fields,
                new[] {new object[] {"A", 2L}, new object[] {"B", 2L}});

            env.SendEventBean(new SupportBean("A", 5));
            env.SendEventBean(new SupportBean("C", 1));
            env.AdvanceTime(4000);

            EPAssertionUtil.AssertPropsPerRow(
                env.Listener("s0").GetAndResetLastNewData(),
                fields,
                new[] {new object[] {"A", 3L}, new object[] {"B", 2L}, new object[] {"C", 1L}});

            env.UndeployAll();
        }
Exemplo n.º 23
0
            public void Run(RegressionEnvironment env)
            {
                env.AdvanceTime(0);
                string[] fields = {"TheString"};

                var epl = "create variable long SIZE = 1000;\n" +
                          "@Name('s0') select irstream * from SupportBean#expr(newest_timestamp - oldest_timestamp < SIZE)";
                env.CompileDeploy(epl).AddListener("s0").Milestone(0);

                env.AdvanceTime(1000);
                env.SendEventBean(new SupportBean("E1", 0));
                EPAssertionUtil.AssertPropsPerRow(
                    env.Statement("s0").GetEnumerator(),
                    fields,
                    new[] {new object[] {"E1"}});

                env.Milestone(1);

                env.AdvanceTime(2000);
                env.SendEventBean(new SupportBean("E2", 0));
                EPAssertionUtil.AssertPropsPerRow(
                    env.Statement("s0").GetEnumerator(),
                    fields,
                    new[] {new object[] {"E2"}});

                env.Runtime.VariableService.SetVariableValue(env.DeploymentId("s0"), "SIZE", 10000);

                env.Milestone(2);

                env.AdvanceTime(5000);
                env.SendEventBean(new SupportBean("E3", 0));
                EPAssertionUtil.AssertPropsPerRow(
                    env.Statement("s0").GetEnumerator(),
                    fields,
                    new[] {new object[] {"E2"}, new object[] {"E3"}});

                env.Milestone(3);

                env.Runtime.VariableService.SetVariableValue(env.DeploymentId("s0"), "SIZE", 2000);

                env.Milestone(4);

                env.AdvanceTime(6000);
                env.SendEventBean(new SupportBean("E4", 0));
                EPAssertionUtil.AssertPropsPerRow(
                    env.Statement("s0").GetEnumerator(),
                    fields,
                    new[] {new object[] {"E3"}, new object[] {"E4"}});

                env.UndeployAll();
            }
Exemplo n.º 24
0
            public void Run(RegressionEnvironment env)
            {
                env.AdvanceTime(0);
                string[] fields = {"TheString"};

                var epl = "create variable long SIZE = 1000;\n" +
                          "@Name('s0') select irstream * from SupportBean#expr_batch(newest_timestamp - oldest_timestamp > SIZE);\n";
                env.CompileDeployAddListenerMileZero(epl, "s0");

                env.AdvanceTime(1000);
                env.SendEventBean(new SupportBean("E1", 0));
                env.AdvanceTime(1900);
                env.SendEventBean(new SupportBean("E2", 0));
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                env.Runtime.VariableService.SetVariableValue(env.DeploymentId("s0"), "SIZE", 500);
                env.AdvanceTime(1901);
                EPAssertionUtil.AssertPropsPerRow(
                    env.Listener("s0").GetAndResetDataListsFlattened(),
                    fields,
                    new[] {new object[] {"E1"}, new object[] {"E2"}},
                    null);

                env.SendEventBean(new SupportBean("E3", 0));
                env.AdvanceTime(2300);
                env.SendEventBean(new SupportBean("E4", 0));
                env.AdvanceTime(2500);
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                env.SendEventBean(new SupportBean("E5", 0));
                EPAssertionUtil.AssertPropsPerRow(
                    env.Listener("s0").GetAndResetDataListsFlattened(),
                    fields,
                    new[] {new object[] {"E3"}, new object[] {"E4"}, new object[] {"E5"}},
                    new[] {new object[] {"E1"}, new object[] {"E2"}});

                env.AdvanceTime(3100);
                env.SendEventBean(new SupportBean("E6", 0));
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                env.Runtime.VariableService.SetVariableValue(env.DeploymentId("s0"), "SIZE", 999);
                env.AdvanceTime(3700);
                env.SendEventBean(new SupportBean("E7", 0));
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                env.AdvanceTime(4100);
                env.SendEventBean(new SupportBean("E8", 0));
                EPAssertionUtil.AssertPropsPerRow(
                    env.Listener("s0").GetAndResetDataListsFlattened(),
                    fields,
                    new[] {new object[] {"E6"}, new object[] {"E7"}, new object[] {"E8"}},
                    new[] {new object[] {"E3"}, new object[] {"E4"}, new object[] {"E5"}});

                env.UndeployAll();
            }
Exemplo n.º 25
0
            public void Run(RegressionEnvironment env)
            {
                var runtimeSPI = (EPEventServiceSPI) env.EventService;

                env.AdvanceTime(0);
                Assert.IsNull(env.EventService.NextScheduledTime);
                AssertSchedules(runtimeSPI.StatementNearestSchedules, new object[0][]);

                env.CompileDeploy("@Name('s0') select * from pattern[timer:interval(2 sec)]");
                Assert.AreEqual(2000L, (long) env.EventService.NextScheduledTime);
                AssertSchedules(
                    runtimeSPI.StatementNearestSchedules,
                    new[] {new object[] {"s0", 2000L}});

                env.CompileDeploy("@Name('s2') select * from pattern[timer:interval(150 msec)]");
                Assert.AreEqual(150L, (long) env.EventService.NextScheduledTime);
                AssertSchedules(
                    runtimeSPI.StatementNearestSchedules,
                    new[] {new object[] {"s2", 150L}, new object[] {"s0", 2000L}});

                env.UndeployModuleContaining("s2");
                Assert.AreEqual(2000L, (long) env.EventService.NextScheduledTime);
                AssertSchedules(
                    runtimeSPI.StatementNearestSchedules,
                    new[] {new object[] {"s0", 2000L}});

                env.CompileDeploy("@Name('s3') select * from pattern[timer:interval(3 sec) and timer:interval(4 sec)]");
                Assert.AreEqual(2000L, (long) env.EventService.NextScheduledTime);
                AssertSchedules(
                    runtimeSPI.StatementNearestSchedules,
                    new[] {new object[] {"s0", 2000L}, new object[] {"s3", 3000L}});

                env.AdvanceTime(2500);
                Assert.AreEqual(3000L, (long) env.EventService.NextScheduledTime);
                AssertSchedules(
                    runtimeSPI.StatementNearestSchedules,
                    new[] {new object[] {"s3", 3000L}});

                env.AdvanceTime(3500);
                Assert.AreEqual(4000L, (long) env.EventService.NextScheduledTime);
                AssertSchedules(
                    runtimeSPI.StatementNearestSchedules,
                    new[] {new object[] {"s3", 4000L}});

                env.AdvanceTime(4500);
                Assert.AreEqual(null, env.EventService.NextScheduledTime);
                AssertSchedules(runtimeSPI.StatementNearestSchedules, new object[0][]);

                env.UndeployAll();
            }
Exemplo n.º 26
0
        private static void RuntestTimeBatch(RegressionEnvironment env)
        {
            string[] fields = {"myint"};

            env.AdvanceTime(0);
            EPAssertionUtil.AssertPropsPerRow(env.GetEnumerator("s0"), fields, null);

            SendSupportBeanEvent(env, 10);
            EPAssertionUtil.AssertPropsPerRow(
                env.GetEnumerator("s0"),
                fields,
                new[] {new object[] {100}});

            SendSupportBeanEvent(env, 5);
            EPAssertionUtil.AssertPropsPerRow(
                env.GetEnumerator("s0"),
                fields,
                new[] {new object[] {100}, new object[] {50}});

            env.Milestone(0);

            SendSupportBeanEvent(env, 2);
            EPAssertionUtil.AssertPropsPerRow(
                env.GetEnumerator("s0"),
                fields,
                new[] {new object[] {100}, new object[] {50}, new object[] {20}});

            env.AdvanceTime(10000);
            var received = env.Listener("s0").LastNewData;
            Assert.AreEqual(3, received.Length);
            Assert.AreEqual(100, received[0].Get("myint"));
            Assert.AreEqual(50, received[1].Get("myint"));
            Assert.AreEqual(20, received[2].Get("myint"));

            EPAssertionUtil.AssertPropsPerRow(env.GetEnumerator("s0"), fields, null);

            SendSupportBeanEvent(env, 9);
            EPAssertionUtil.AssertPropsPerRow(
                env.GetEnumerator("s0"),
                fields,
                new[] {new object[] {90}});

            SendSupportBeanEvent(env, 8);
            EPAssertionUtil.AssertPropsPerRow(
                env.GetEnumerator("s0"),
                fields,
                new[] {new object[] {90}, new object[] {80}});

            env.UndeployAll();
        }
        public void Run(RegressionEnvironment env)
        {
            var path = new RegressionPath();
            env.AdvanceTime(0);
            env.CompileDeploy("@Name('0') create schema StatementMetric as " + typeof(StatementMetric).FullName);
            env.CompileDeploy("@Name('A') create window MyWindow#lastevent as select * from SupportBean", path);
            env.CompileDeploy("@Name('B1') insert into MyWindow select * from SupportBean", path);
            env.CompileDeploy("@Name('B2') insert into MyWindow select * from SupportBean", path);
            env.CompileDeploy("@Name('C') select sum(IntPrimitive) from MyWindow", path);
            env.CompileDeploy("@Name('D') select sum(w1.IntPrimitive) from MyWindow w1, MyWindow w2", path);

            var appModuleTwo = "@Name('W') create window SupportBeanWindow#keepall as SupportBean;" +
                               "" +
                               "@Name('M') on SupportBean oe\n" +
                               "  merge SupportBeanWindow Pw\n" +
                               "  where Pw.TheString = oe.TheString\n" +
                               "  when not matched \n" +
                               "    then insert select *\n" +
                               "  when matched and oe.IntPrimitive=1\n" +
                               "    then delete\n" +
                               "  when matched\n" +
                               "    then update set Pw.IntPrimitive = oe.IntPrimitive";
            env.CompileDeploy(appModuleTwo, path);

            env.CompileDeploy("@Name('X') select * from " + typeof(StatementMetric).FullName).AddListener("X");
            var fields = new [] { "StatementName","NumInput" };
            
            env.SendEventBean(new SupportBean("E1", 1));
            env.AdvanceTime(1000);
            var received = ArrayHandlingUtil.Reorder("StatementName", env.Listener("X").NewDataListFlattened);
            foreach (var theEvent in received) {
                Log.Info(theEvent.Get("StatementName") + " = " + theEvent.Get("NumInput"));
            }

            EPAssertionUtil.AssertPropsPerRow(
                received,
                fields,
                new[] {
                    new object[] {"A", 2L},
                    new object[] {"B1", 1L},
                    new object[] {"B2", 1L},
                    new object[] {"C", 2L},
                    new object[] {"D", 2L},
                    new object[] {"M", 1L},
                    new object[] {"W", 1L}
                });

            env.UndeployAll();
        }
Exemplo n.º 28
0
 private static void SendCurrentTimeWithMinus(
     RegressionEnvironment env,
     string time,
     long minus)
 {
     env.AdvanceTime(DateTimeParsingFunctions.ParseDefaultMSec(time) - minus);
 }
Exemplo n.º 29
0
 private static void SendTimerAssertNotInvoked(
     RegressionEnvironment env,
     long timeInMSec)
 {
     env.AdvanceTime(timeInMSec);
     Assert.IsFalse(env.Listener("s0").IsInvoked);
 }
Exemplo n.º 30
0
            public void Run(RegressionEnvironment env)
            {
                env.AdvanceTime(0);
                env.CompileDeploy("@Name('s0') select count(*) as y from SupportBean#time_batch(1 seconds) group by TheString having count(*) > 0");
                env.AddListener("s0");

                env.SendEventBean(new SupportBean("E1", 0));
                env.AdvanceTime(1000);
                EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), "y".SplitCsv(), new object[] {1L});

                env.SendEventBean(new SupportBean("E2", 0));
                env.AdvanceTime(2000);
                EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), "y".SplitCsv(), new object[] {1L});

                env.UndeployAll();
            }