private static void TryAssertionReturnTypeIsEvents(
            RegressionEnvironment env,
            string methodName,
            AtomicLong milestone)
        {
            var path = new RegressionPath();
            var compiled = env.CompileWBusPublicType("create schema MyItem(Id string)");
            env.Deploy(compiled);
            path.Add(compiled);

            env.CompileDeploy(
                "@Name('s0') select " +
                methodName +
                "(TheString).where(v -> v.Id in ('id1', 'id3')) as c0 from SupportBean",
                path);
            env.AddListener("s0");

            env.SendEventBean(new SupportBean("id0,id1,id2,id3,id4", 0));
            var real = env.Listener("s0").AssertOneGetNewAndReset().Get("c0");
            var coll = real.Unwrap<IDictionary<string, object>>();
            EPAssertionUtil.AssertPropsPerRow(
                coll.ToArray(),
                new [] { "Id" },
                new[] {
                    new object[] {"id1"},
                    new object[] {"id3"}
                });

            env.UndeployAll();
        }
Esempio n. 2
0
            public void Run(RegressionEnvironment env)
            {
                string epl = "create schema MANE as MyAutoNameEvent;\n" +
                             "@Name('s0') select P0 from MANE;\n";
                EPCompiled compiled = env.CompileWBusPublicType(epl);
                env.Deploy(compiled).AddListener("s0");

                env.SendEventBean(new MyAutoNameEvent("test"), "MANE");
                Assert.AreEqual("test", env.Listener("s0").AssertOneGetNewAndReset().Get("P0"));

                env.UndeployAll();
            }
Esempio n. 3
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                var compiled = env.CompileWBusPublicType("create objectarray schema MyEventOA(p0 string, p1 long)");
                env.Deploy(compiled);
                path.Add(compiled);

                RunAssertionOA(env, path, false);
                RunAssertionOA(env, path, true);

                // test collector
                env.CompileDeploy(
                    "@Name('flow') create dataflow MyDataFlowOne " +
                    "EventBusSource -> ReceivedStream<MyEventOA> {filter: p0 like 'A%'} " +
                    "DefaultSupportCaptureOp(ReceivedStream) {}",
                    path);

                var collector = new MyCollector();
                var future = new DefaultSupportCaptureOp();
                var options = new EPDataFlowInstantiationOptions()
                    .WithOperatorProvider(new DefaultSupportGraphOpProvider(future))
                    .WithParameterProvider(
                        new DefaultSupportGraphParamProvider(
                            Collections.SingletonDataMap("collector", collector)));

                var instance = env.Runtime.DataFlowService.Instantiate(
                    env.DeploymentId("flow"),
                    "MyDataFlowOne",
                    options);
                instance.Start();

                env.SendEventObjectArray(new object[] {"B", 100L}, "MyEventOA");
                Sleep(50);
                Assert.IsNull(collector.Last);

                env.SendEventObjectArray(new object[] {"A", 101L}, "MyEventOA");
                future.WaitForInvocation(100, 1);
                Assert.IsNotNull(collector.Last.Emitter);
                Assert.AreEqual("MyEventOA", collector.Last.Event.EventType.Name);
                Assert.AreEqual(false, collector.Last.IsSubmitEventBean);

                instance.Cancel();

                env.UndeployAll();
            }
 private static SupportUpdateListener DeployPortScan(RegressionEnvironment env)
 {
     var epl =
         "create objectarray schema PortScanEvent(src string, dst string, port int, marker string);\n" +
         "\n" +
         "create table ScanCountTable(src string primary key, dst string primary key, cnt count(*), win window(*) @type(PortScanEvent));\n" +
         "\n" +
         "into table ScanCountTable\n" +
         "insert into CountStream\n" +
         "select src, dst, count(*) as cnt, window(*) as win\n" +
         "from PortScanEvent#unique(src, dst, port)#time(30 sec) group by src,dst;\n" +
         "\n" +
         "create window SituationsWindow#keepall (src string, dst string, detectionTime long);\n" +
         "\n" +
         "on CountStream(cnt >= 20) as cs\n" +
         "merge SituationsWindow sw\n" +
         "where cs.src = sw.src and cs.dst = sw.dst\n" +
         "when not matched \n" +
         "  then insert select src, dst, current_timestamp as detectionTime\n" +
         "  then insert into OutputAlerts select 'DETECTED' as type, cs.cnt as cnt, cs.win as contributors;\n" +
         "\n" +
         "on pattern [every timer:at(*, *, *, *, *)] \n" +
         "insert into OutputAlerts \n" +
         "select 'UPDATE' as type, ScanCountTable[src, dst].cnt as cnt, ScanCountTable[src, dst].win as contributors\n" +
         "from SituationsWindow sc;\n" +
         "\n" +
         "on pattern [every timer:at(*, *, *, *, *)] \n" +
         "merge SituationsWindow sw\n" +
         "when matched and (select cnt from ScanCountTable where src = sw.src and dst = sw.dst) < 10\n" +
         "  then delete\n" +
         "  then insert into OutputAlerts select 'DONE' as type, ScanCountTable[src, dst].cnt as cnt, null as contributors \n" +
         "when matched and detectionTime.after(current_timestamp, 16 hours)\n" +
         "  then delete\n" +
         "  then insert into OutputAlerts select 'EXPIRED' as type, -1L as cnt, null as contributors;\n" +
         "\n" +
         // For more output: "@Audit() select * from CountStream;\n" +
         "@Name('output') select * from OutputAlerts;\n";
     var compiled = env.CompileWBusPublicType(epl);
     env.Deploy(compiled);
     var listener = new SupportUpdateListener();
     env.Statement("output").AddListener(listener);
     return listener;
 }
Esempio n. 5
0
            public void Run(RegressionEnvironment env)
            {
                var compiled = env.CompileWBusPublicType("create schema OrderEvent(Price double)");
                env.Deploy(compiled);
                var path = new RegressionPath();
                path.Add(compiled);

                var epl = "@Name('All-Order-Events') @Audit('stream,property') select Price from OrderEvent";
                env.CompileDeploy(epl, path).AddListener("All-Order-Events");

                if (EventRepresentationChoiceExtensions.GetEngineDefault(env.Configuration).IsObjectArrayEvent()) {
                    env.SendEventObjectArray(new object[] {100d}, "OrderEvent");
                }
                else {
                    env.SendEventMap(Collections.SingletonDataMap("Price", 100d), "OrderEvent");
                }

                env.UndeployAll();
            }
            public void Run(RegressionEnvironment env)
            {
                var collections = typeof(Collections).FullName;
                var path = new RegressionPath();
                var script = "create expression EventBean[] js:mySplitScriptReturnEventBeanArray(value) [\n" +
                             "function mySplitScriptReturnEventBeanArray(value) {" +
                             "  var split = value.split(',');\n" +
                             "  var etype = host.resolveType('com.espertech.esper.common.client.EventBean');\n" +
                             "  var events = host.newArr(etype, split.length);  " +
                             "  for (var i = 0; i < split.length; i++) {\n" +
                             "    var pvalue = split[i].substring(1);\n" +
                             "    if (split[i].startsWith(\"A\")) {\n" +
                             $"      events[i] = epl.EventBeanService.AdapterForMap(Collections.SingletonDataMap(\"P0\", pvalue), \"AEvent\");\n" +
                             "    }\n" +
                             "    else if (split[i].startsWith(\"B\")) {\n" +
                             $"      events[i] = epl.EventBeanService.AdapterForMap(Collections.SingletonDataMap(\"P1\", pvalue), \"BEvent\");\n" +
                             "    }\n" +
                             "    else {\n" +
                             "      xhost.throwException(\"UnsupportedOperationException\", \"Unrecognized type\");\n" +
                             "    }\n" +
                             "  }\n" +
                             "  return events;\n" +
                             "};" +
                             "return mySplitScriptReturnEventBeanArray(value);" +
                             "]";
                env.CompileDeploy(script, path);

                var epl = "create schema BaseEvent();\n" +
                          "create schema AEvent(P0 string) inherits BaseEvent;\n" +
                          "create schema BEvent(P1 string) inherits BaseEvent;\n" +
                          "create schema SplitEvent(value string);\n";
                var compiled = env.CompileWBusPublicType(epl);
                env.Deploy(compiled);
                path.Add(compiled);

                TryAssertionSplitExprReturnsEventBean(env, path, "mySplitUDFReturnEventBeanArray");
                TryAssertionSplitExprReturnsEventBean(env, path, "mySplitScriptReturnEventBeanArray");

                env.UndeployAll();
            }
            public void Run(RegressionEnvironment env)
            {
                var c1 = env.CompileWBusPublicType("create schema EventSchema(e0 string, e1 int, e2 string)");
                var c2 = env.CompileWBusPublicType("create schema WindowSchema(col0 string, col1 long, col2 string)");
                var path = new RegressionPath();
                path.Add(c1);
                path.Add(c2);
                env.Deploy(c1);
                env.Deploy(c2);

                var createEpl = _namedWindow
                    ? "create window MyInfra#keepall as WindowSchema"
                    : "create table MyInfra (col0 string primary key, col1 long, col2 string)";
                if (_enableIndexShareCreate)
                {
                    createEpl = "@Hint('enable_window_subquery_indexshare') " + createEpl;
                }

                env.CompileDeploy(createEpl, path);
                env.CompileDeploy("insert into MyInfra select * from WindowSchema", path);

                if (_createExplicitIndex)
                {
                    env.CompileDeploy("@Name('index') create index MyIndex on MyInfra (col2, col1)", path);
                }

                var fields = new[] { "e0", "val" };
                var consumeEpl =
                    "@Name('s0') select e0, (select col0 from MyInfra where col2 = es.e2 and col1 = es.e1) as val from EventSchema es";
                if (_disableIndexShareConsumer)
                {
                    consumeEpl = "@Hint('disable_window_subquery_indexshare') " + consumeEpl;
                }

                env.CompileDeploy(consumeEpl, path).AddListener("s0");

                SendWindow(env, "W1", 10L, "c31");
                SendEvent(env, "E1", 10, "c31");
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] { "E1", "W1" });

                SendEvent(env, "E2", 11, "c32");
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] { "E2", null });

                SendWindow(env, "W2", 11L, "c32");
                SendEvent(env, "E3", 11, "c32");
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] { "E3", "W2" });

                SendWindow(env, "W3", 11L, "c31");
                SendWindow(env, "W4", 10L, "c32");

                SendEvent(env, "E4", 11, "c31");
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] { "E4", "W3" });

                SendEvent(env, "E5", 10, "c31");
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] { "E5", "W1" });

                SendEvent(env, "E6", 10, "c32");
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] { "E6", "W4" });

                // test late start
                env.UndeployModuleContaining("s0");
                env.CompileDeploy(consumeEpl, path).AddListener("s0");

                SendEvent(env, "E6", 10, "c32");
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] { "E6", "W4" });

                env.UndeployModuleContaining("s0");
                if (env.Statement("index") != null)
                {
                    env.UndeployModuleContaining("index");
                }

                env.UndeployAll();
            }