Esempio n. 1
0
            public void Run(RegressionEnvironment env)
            {
                // Test substitution parameter and inheritance in key matching
                var path = new RegressionPath();
                var types =
                    "create schema MyEventOne as " +
                    typeof(MyEventOne).MaskTypeName() +
                    ";\n" +
                    "create schema MyEventTwo as " +
                    typeof(MyEventTwo).MaskTypeName() +
                    ";\n";
                env.CompileDeployWBusPublicType(types, path);

                var epl = "select * from MyEventOne(Key = ?::IKey)";
                var compiled = env.Compile(epl, path);
                var lKey = new MyObjectKeyInterface();
                DeployWithResolver(env, compiled, "s0", prepared => prepared.SetObject(1, lKey));
                env.AddListener("s0");

                env.SendEventBean(new MyEventOne(lKey));
                Assert.IsTrue(env.Listener("s0").GetAndClearIsInvoked());

                // Test substitution parameter and concrete subclass in key matching
                epl = "select * from MyEventTwo where Key = ?::MyObjectKeyConcrete";
                compiled = env.Compile(epl, path);
                var cKey = new MyObjectKeyConcrete();
                DeployWithResolver(env, compiled, "s1", prepared => prepared.SetObject(1, cKey));
                env.AddListener("s1");

                env.SendEventBean(new MyEventTwo(cKey));
                Assert.IsTrue(env.Listener("s1").GetAndClearIsInvoked());

                env.UndeployAll();
            }
Esempio n. 2
0
            public void Run(RegressionEnvironment env)
            {
                string epl = "create objectarray schema Event();\n" +
                             "create objectarray schema ChildEvent(id string, action string) inherits Event;\n" +
                             "create objectarray schema Incident(name string, event Event);\n" +
                             "@Name('window') create window IncidentWindow#keepall as Incident;\n" +
                             "\n" +
                             "on ChildEvent e\n" +
                             "    merge IncidentWindow w\n" +
                             "    where e.id = cast(w.event.id? as string)\n" +
                             "    when not matched\n" +
                             "        then insert (name, event) select 'ChildIncident', e \n" +
                             "            where e.action = 'INSERT'\n" +
                             "    when matched\n" +
                             "        then update set w.event = e \n" +
                             "            where e.action = 'INSERT'\n" +
                             "        then delete\n" +
                             "            where e.action = 'CLEAR';";
                env.CompileDeployWBusPublicType(epl, new RegressionPath());

                env.SendEventObjectArray(new object[] {"ID1", "INSERT"}, "ChildEvent");
                EventBean @event = env.Statement("window").First();
                object[] underlying = (object[]) @event.Underlying;
                Assert.AreEqual("ChildIncident", underlying[0]);
                object[] underlyingInner = (object[]) ((EventBean) underlying[1]).Underlying;
                EPAssertionUtil.AssertEqualsExactOrder(new object[] {"ID1", "INSERT"}, underlyingInner);

                env.UndeployAll();
            }
Esempio n. 3
0
        private void RunAssertionDynamicProp(RegressionEnvironment env)
        {
            var path = new RegressionPath();
            env.CompileDeployWBusPublicType("create avro schema MyEvent()", path);

            env.CompileDeploy("@Name('s0') select * from MyEvent", path).AddListener("s0");

            var schema = ((AvroEventType) env.Statement("s0").EventType).SchemaAvro;
            env.SendEventAvro(new GenericRecord(schema.AsRecordSchema()), "MyEvent");
            var @event = env.Listener("s0").AssertOneGetNewAndReset();

            Assert.AreEqual(null, @event.Get("a?.b"));

            var innerSchema = SchemaBuilder.Record(
                "InnerSchema", Field("b", StringType(Property(PROP_STRING_KEY, PROP_STRING_VALUE))));
            var inner = new GenericRecord(innerSchema);
            inner.Put("b", "X");
            var recordSchema = SchemaBuilder.Record(
                "RecordSchema", Field("a", innerSchema));
            var record = new GenericRecord(recordSchema);
            record.Put("a", inner);
            env.SendEventAvro(record, "MyEvent");
            @event = env.Listener("s0").AssertOneGetNewAndReset();
            Assert.AreEqual("X", @event.Get("a?.b"));

            env.UndeployAll();
        }
        private static void TryAssertion2StreamInnerWGroupBy(RegressionEnvironment env)
        {
            var epl = "create objectarray schema E1 (id string, grp string, value int);\n" +
                      "create objectarray schema E2 (id string, value2 int);\n" +
                      "@Name('s0') select count(*) as c0, sum(E1.value) as c1, E1.id as c2 " +
                      "from E1 unidirectional inner join E2#keepall on E1.id = E2.id group by E1.grp";
            env.CompileDeployWBusPublicType(epl, new RegressionPath());
            env.AddListener("s0");
            var fields = new[] {"c0", "c1", "c2"};

            env.SendEventObjectArray(new object[] {"A", 100}, "E2");
            Assert.IsFalse(env.Listener("s0").IsInvoked);

            env.SendEventObjectArray(new object[] {"A", "X", 10}, "E1");
            EPAssertionUtil.AssertProps(
                env.Listener("s0").AssertOneGetNewAndReset(),
                fields,
                new object[] {1L, 10, "A"});

            env.SendEventObjectArray(new object[] {"A", "Y", 20}, "E1");
            EPAssertionUtil.AssertProps(
                env.Listener("s0").AssertOneGetNewAndReset(),
                fields,
                new object[] {1L, 20, "A"});

            env.UndeployAll();
        }
        private static void TryAssertionTypableNewOperatorDocSample(
            RegressionEnvironment env,
            string typeType)
        {
            var path = new RegressionPath();
            env.CompileDeploy("create " + typeType + " schema Item(name string, Price double)", path);
            env.CompileDeploy("create " + typeType + " schema PurchaseOrder(OrderId string, items Item[])", path);
            env.CompileDeployWBusPublicType("create schema TriggerEvent()", path);
            env.CompileDeploy(
                    "@Name('s0') insert into PurchaseOrder select '001' as OrderId, new {name= 'i1', Price=10} as items from TriggerEvent",
                    path)
                .AddListener("s0");

            env.SendEventMap(Collections.EmptyDataMap, "TriggerEvent");
            var @event = env.Listener("s0").AssertOneGetNewAndReset();
            EPAssertionUtil.AssertProps(
                @event,
                new[] {"OrderId", "items[0].name", "items[0].Price"},
                new object[] {"001", "i1", 10d});

            var underlying = (EventBean[]) @event.Get("items");
            Assert.AreEqual(1, underlying.Length);
            Assert.AreEqual("i1", underlying[0].Get("name"));
            Assert.AreEqual(10d, underlying[0].Get("Price"));

            env.UndeployAll();
        }
        private static void TryAssertionFragmentSingeColNamedWindow(RegressionEnvironment env)
        {
            var path = new RegressionPath();
            env.CompileDeployWBusPublicType("create schema AEvent (Symbol string)", path);

            env.CompileDeploy("create window MyEventWindow#lastevent (e AEvent)", path);
            env.CompileDeploy(
                "insert into MyEventWindow select (select * from AEvent#lastevent) as e from SupportBean(TheString = 'A')",
                path);
            env.CompileDeploy("create schema BEvent (e AEvent)", path);
            env.CompileDeploy(
                    "@Name('s0') insert into BEvent select (select e from MyEventWindow) as e from SupportBean(TheString = 'B')",
                    path)
                .AddListener("s0");

            env.SendEventMap(Collections.SingletonDataMap("Symbol", "GE"), "AEvent");
            env.SendEventBean(new SupportBean("A", 1));
            env.SendEventBean(new SupportBean("B", 2));
            var result = env.Listener("s0").AssertOneGetNewAndReset();
            var fragment = (EventBean) result.Get("e");
            Assert.AreEqual("AEvent", fragment.EventType.Name);
            Assert.AreEqual("GE", fragment.Get("Symbol"));

            env.UndeployAll();
        }
Esempio n. 7
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                env.CompileDeployWBusPublicType("create schema Geofence(x double, y double, vin string)", path);

                env.CompileDeploy(
                    "create table Regions(regionId string primary key, rx double, ry double, rwidth double, rheight double)",
                    path);
                env.CompileDeploy(
                    "create index RectangleIndex on Regions((rx, ry, rwidth, rheight) mxcifquadtree(0, 0, 10, 12))",
                    path);
                env.CompileDeploy(
                    "@Name('s0') " +
                    IndexBackingTableInfo.INDEX_CALLBACK_HOOK +
                    "on Geofence as vin insert into VINWithRegion select regionId, vin from Regions where rectangle(rx, ry, rwidth, rheight).intersects(rectangle(vin.x, vin.y, 0, 0))",
                    path);
                env.AddListener("s0");

                SupportQueryPlanIndexHook.AssertOnExprTableAndReset(
                    "RectangleIndex",
                    "non-unique hash={} btree={} advanced={mxcifquadtree(rx,ry,rwidth,rheight)}");

                env.CompileExecuteFAF("insert into Regions values ('R1', 2, 2, 5, 5)", path);
                env.SendEventMap(CollectionUtil.PopulateNameValueMap("x", 3d, "y", 3d, "vin", "V1"), "Geofence");

                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    new[] {"vin", "regionId"},
                    new object[] {"V1", "R1"});

                env.UndeployAll();
            }
Esempio n. 8
0
        private static void TryAssertionFromClauseDocSample(RegressionEnvironment env)
        {
            var epl =
                "create schema MyOrderItem(itemId string);\n" +
                "create schema MyOrderEvent(OrderId string, items MyOrderItem[]);\n" +
                "on MyOrderEvent\n" +
                "  insert into MyOrderBeginEvent select OrderId\n" +
                "  insert into MyOrderItemEvent select * from [select OrderId, * from items]\n" +
                "  insert into MyOrderEndEvent select OrderId\n" +
                "  output all;\n" +
                "create context MyOrderContext \n" +
                "  initiated by MyOrderBeginEvent as obe\n" +
                "  terminated by MyOrderEndEvent(OrderId = obe.OrderId);\n" +
                "@Name('count') context MyOrderContext select count(*) as orderItemCount from MyOrderItemEvent output when terminated;\n";
            env.CompileDeployWBusPublicType(epl, new RegressionPath()).AddListener("count");

            var @event = new Dictionary<string, object>();
            @event.Put("OrderId", "1010");
            @event.Put(
                "items",
                new[] {
                    Collections.SingletonDataMap("itemId", "A0001")
                });
            env.SendEventMap(@event, "MyOrderEvent");

            Assert.AreEqual(1L, env.Listener("count").AssertOneGetNewAndReset().Get("orderItemCount"));

            env.UndeployAll();
        }
        private static void TryAssertion(
            RegressionEnvironment env,
            bool enableIndexShareCreate,
            bool disableIndexShareConsumer,
            bool createExplicitIndex)
        {
            var path = new RegressionPath();
            env.CompileDeployWBusPublicType("create schema EventSchema(e0 string, e1 int, e2 string)", path);

            var createEpl = "create window MyWindow#keepall as select * from SupportBean";
            if (enableIndexShareCreate) {
                createEpl = "@Hint('enable_window_subquery_indexshare') " + createEpl;
            }

            env.CompileDeploy(createEpl, path);
            env.CompileDeploy("insert into MyWindow select * from SupportBean", path);

            if (createExplicitIndex) {
                env.CompileDeploy("create index MyIndex on MyWindow (TheString)", path);
            }

            var consumeEpl =
                "@Name('s0') select e0, (select TheString from MyWindow where IntPrimitive = es.e1 and TheString = es.e2) as val from EventSchema as es";
            if (disableIndexShareConsumer) {
                consumeEpl = "@Hint('disable_window_subquery_indexshare') " + consumeEpl;
            }

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

            var fields = new[] {"e0", "val"};

            // test once
            env.SendEventBean(new SupportBean("WX", 10));
            SendEvent(env, "E1", 10, "WX");
            EPAssertionUtil.AssertProps(
                env.Listener("s0").AssertOneGetNewAndReset(),
                fields,
                new object[] {"E1", "WX"});

            // preload
            for (var i = 0; i < 10000; i++) {
                env.SendEventBean(new SupportBean("W" + i, i));
            }

            var startTime = PerformanceObserver.MilliTime;
            for (var i = 0; i < 5000; i++) {
                SendEvent(env, "E" + i, i, "W" + i);
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"E" + i, "W" + i});
            }

            var endTime = PerformanceObserver.MilliTime;
            var delta = endTime - startTime;
            Assert.That(delta, Is.LessThan(500), "delta=" + delta);

            env.UndeployAll();
        }
Esempio n. 10
0
        private static void TrySend(
            RegressionEnvironment env,
            int numThreads,
            int numEventsPerThread,
            bool indexShare)
        {
            // setup statements
            var path = new RegressionPath();
            var schemas = "create schema UpdateEvent as (uekey string, ueint int);\n" +
                          "create schema WindowSchema as (wskey string, wsint int);\n";
            env.CompileDeployWBusPublicType(schemas, path);

            var createEpl = "@Name('namedWindow') create window MyWindow#keepall as WindowSchema";
            if (indexShare) {
                createEpl = "@Hint('enable_window_subquery_indexshare') " + createEpl;
            }

            env.CompileDeploy(createEpl, path);

            env.CompileDeploy("create index ABC on MyWindow(wskey)", path);
            env.CompileDeploy(
                "on UpdateEvent mue merge MyWindow mw " +
                "where uekey = wskey and ueint = wsint " +
                "when not matched then insert select uekey as wskey, ueint as wsint " +
                "when matched then delete",
                path);
            // note: here all threads use the same string key to insert/delete and different values for the int
            env.CompileDeploy(
                "@Name('target') select (select intListAgg(wsint) from MyWindow mw where wskey = sb.TheString) as val from SupportBean sb",
                path);

            // execute
            var executor = Executors.NewMultiThreadedExecutor(numThreads);
            // new SupportThreadFactory(typeof(MultithreadStmtNamedWindowSubqueryAgg)).ThreadFactory)
            var futures = new List<IFuture<bool?>>();
            for (var i = 0; i < numThreads; i++) {
                futures.Add(executor.Submit(
                    new StmtNamedWindowSubqueryAggCallable(
                        i,
                        env.Runtime,
                        numEventsPerThread,
                        env.Statement("target"))));
            }
            
            // Give the futures 10 seconds to complete the futures...
            futures.AsParallel().ForAll(future => future.Wait(TimeSpan.FromSeconds(10)));

            executor.Shutdown();
            SupportCompileDeployUtil.ExecutorAwait(executor, TimeSpan.FromSeconds(10));
            SupportCompileDeployUtil.AssertFutures(futures);

            var events = EPAssertionUtil.EnumeratorToArray(env.Statement("namedWindow").GetEnumerator());
            Assert.AreEqual(0, events.Length);

            env.UndeployAll();
        }
Esempio n. 11
0
            public void Run(RegressionEnvironment env)
            {
                RegressionPath path = new RegressionPath();

                AssertStmt(env, path, "select Items.firstof().AssetId as firstcenter from LocationReport");
                AssertStmt(env, path, "select Items.where(p => p.Type=\"P\") from LocationReport");
                AssertStmt(env, path, "select Items.where((p,ind) => p.Type=\"P\" and ind>2) from LocationReport");
                AssertStmt(env, path, "select Items.aggregate(\"\",(result,item) => result||(case when result=\"\" then \"\" else \",\" end)||item.AssetId) as assets from LocationReport");
                AssertStmt(env, path, "select Items.allof(i => distance(i.Location.X,i.Location.Y,0,0)<1000) as assets from LocationReport");
                AssertStmt(env, path, "select Items.average(i => distance(i.Location.X,i.Location.Y,0,0)) as avgdistance from LocationReport");
                AssertStmt(env, path, "select Items.countof(i => distance(i.Location.X,i.Location.Y,0,0)<20) as cntcenter from LocationReport");
                AssertStmt(env, path, "select Items.firstof(i => distance(i.Location.X,i.Location.Y,0,0)<20) as firstcenter from LocationReport");
                AssertStmt(env, path, "select Items.lastof().AssetId as firstcenter from LocationReport");
                AssertStmt(env, path, "select Items.lastof(i => distance(i.Location.X,i.Location.Y,0,0)<20) as lastcenter from LocationReport");
                AssertStmt(env, path, "select Items.where(i => i.Type=\"L\").groupby(i => AssetIdPassenger) as luggagePerPerson from LocationReport");
                AssertStmt(env, path, "select Items.where((p,Ind) => p.Type=\"P\" and Ind>2) from LocationReport");
                AssertStmt(env, path, "select Items.groupby(k => AssetId,v => distance(v.Location.X,v.Location.Y,0,0)) as distancePerItem from LocationReport");
                AssertStmt(env, path, "select Items.min(i => distance(i.Location.X,i.Location.Y,0,0)) as mincenter from LocationReport");
                AssertStmt(env, path, "select Items.max(i => distance(i.Location.X,i.Location.Y,0,0)) as maxcenter from LocationReport");
                AssertStmt(env, path, "select Items.minBy(i => distance(i.Location.X,i.Location.Y,0,0)) as minItemCenter from LocationReport");
                AssertStmt(env, path, "select Items.minBy(i => distance(i.Location.X,i.Location.Y,0,0)).AssetId as minItemCenter from LocationReport");
                AssertStmt(env, path, "select Items.orderBy(i => distance(i.Location.X,i.Location.Y,0,0)) as itemsOrderedByDist from LocationReport");
                AssertStmt(env, path, "select Items.selectFrom(i => AssetId) as itemAssetIds from LocationReport");
                AssertStmt(env, path, "select Items.take(5) as first5Items, Items.takeLast(5) as last5Items from LocationReport");
                AssertStmt(env, path, "select Items.toMap(k => k.AssetId,v => distance(v.Location.X,v.Location.Y,0,0)) as assetDistance from LocationReport");
                AssertStmt(env, path, "select Items.where(i => i.AssetId=\"L001\").union(Items.where(i => i.Type=\"P\")) as itemsUnion from LocationReport");
                AssertStmt(env, path, "select (select Name from Zone#unique(Name)).orderBy() as orderedZones from pattern [every timer:interval(30)]");

                env.CompileDeployWBusPublicType("create schema MyEvent as (seqone String[], seqtwo String[])", path);

                AssertStmt(env, path, "select seqone.sequenceEqual(seqtwo) from MyEvent");
                AssertStmt(env, path, "select window(AssetId).orderBy() as orderedAssetIds from Item#time(10) group by AssetId");
                AssertStmt(env, path, "select prevwindow(AssetId).orderBy() as orderedAssetIds from Item#time(10) as items");
                AssertStmt(env, path, "select getZoneNames().where(z => z!=\"Z1\") from pattern [every timer:interval(30)]");
                AssertStmt(
                    env,
                    path,
                    "select Items.selectFrom(i => new{AssetId,distanceCenter=distance(i.Location.X,i.Location.Y,0,0)}) as itemInfo from LocationReport");
                AssertStmt(env, path, "select Items.leastFrequent(i => Type) as leastFreqType from LocationReport");

                string epl = "expression myquery {itm => " +
                             "(select * from Zone#keepall).where(z => inrect(z.Rectangle,itm.Location))" +
                             "} " +
                             "select AssetId, myquery(item) as subq, myquery(item).where(z => z.Name=\"Z01\") as assetItem " +
                             "from Item as item";

                AssertStmt(env, path, epl);

                AssertStmt(
                    env,
                    path,
                    "select za.Items.except(zb.Items) as itemsCompared from LocationReport as za unidirectional, LocationReport#length(10) as zb");

                env.UndeployAll();
            }
            private static void RunTransposeMapAndObjectArray(
                RegressionEnvironment env,
                EventRepresentationChoice representation)
            {
                var fields = new[] {"p0", "p1"};
                var path = new RegressionPath();
                var schema = representation.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedMySchema>() + "create schema MySchema(p0 string, p1 int)";
                env.CompileDeployWBusPublicType(schema, path);

                string generateFunction;
                if (representation.IsObjectArrayEvent()) {
                    generateFunction = "GenerateOA";
                }
                else if (representation.IsMapEvent()) {
                    generateFunction = "GenerateMap";
                }
                else if (representation.IsAvroEvent()) {
                    generateFunction = "GenerateAvro";
                }
                else if (representation.IsJsonEvent() || representation.IsJsonProvidedClassEvent()) {
                    generateFunction = "GenerateJson";
                }
                else {
                    throw new IllegalStateException("Unrecognized code " + representation);
                }

                var epl = "insert into MySchema select transpose(" +
                          generateFunction +
                          "(TheString, IntPrimitive)) from SupportBean";
                env.CompileDeploy("@Name('s0') " + epl, path).AddListener("s0");

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

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

                // MySchema already exists, start second statement
                env.CompileDeploy("@Name('s1') " + epl, path).AddListener("s1");
                env.UndeployModuleContaining("s0");

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

                env.UndeployAll();
            }
Esempio n. 13
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                env.CompileDeployWBusPublicType(
                    "create objectarray schema MyEventThree(k0 int, k1 int, k2 int, col int)",
                    path);

                env.CompileDeploy(
                    "create table MyTableGS3D(k0 int primary key, k1 int primary key, k2 int primary key, total sum(int))",
                    path);
                env.CompileDeploy(
                    "into table MyTableGS3D insert into MyStreamThree select sum(col) as total from MyEventThree#length(3) group by grouping sets(k0,k1,k2)",
                    path);

                var fields = new[] {"k0", "k1", "k2", "total"};
                env.SendEventObjectArray(new object[] {1, 10, 100, 1000}, "MyEventThree");
                env.SendEventObjectArray(new object[] {2, 10, 200, 2000}, "MyEventThree");

                env.Milestone(0);

                env.SendEventObjectArray(new object[] {1, 20, 300, 3000}, "MyEventThree");

                AssertValuesIterate(
                    env,
                    path,
                    "MyTableGS3D",
                    fields,
                    new[] {
                        new object[] {1, null, null, 4000}, new object[] {2, null, null, 2000},
                        new object[] {null, 10, null, 3000}, new object[] {null, 20, null, 3000},
                        new object[] {null, null, 100, 1000}, new object[] {null, null, 200, 2000},
                        new object[] {null, null, 300, 3000}
                    });

                env.Milestone(1);

                env.SendEventObjectArray(new object[] {1, 10, 400, 4000}, "MyEventThree"); // expires {1, 10, 100, 1000}

                env.Milestone(2);

                AssertValuesIterate(
                    env,
                    path,
                    "MyTableGS3D",
                    fields,
                    new[] {
                        new object[] {1, null, null, 7000}, new object[] {2, null, null, 2000},
                        new object[] {null, 10, null, 6000}, new object[] {null, 20, null, 3000},
                        new object[] {null, null, 100, null}, new object[] {null, null, 400, 4000},
                        new object[] {null, null, 200, 2000}, new object[] {null, null, 300, 3000}
                    });

                env.UndeployAll();
            }
Esempio n. 14
0
        public void Run(RegressionEnvironment env)
        {
            var path = new RegressionPath();
            var epl =
                "create schema N1N1 (n1n1 string);\n" +
                "create schema N1 (n1 string, n2 N1N1);\n" +
                "create schema NestedMapWithSimpleProps (nested N1);\n";
            env.CompileDeployWBusPublicType(epl, path);

            RunAssertion(env, path);
        }
        public void Run(RegressionEnvironment env)
        {
            var epl = "create objectarray schema RootEvent(base string);\n" +
                      "create objectarray schema Sub1Event(sub1 string) inherits RootEvent;\n" +
                      "create objectarray schema Sub2Event(sub2 string) inherits RootEvent;\n" +
                      "create objectarray schema SubAEvent(suba string) inherits Sub1Event;\n" +
                      "create objectarray schema SubBEvent(subb string) inherits SubAEvent;\n";
            var path = new RegressionPath();
            env.CompileDeployWBusPublicType(epl, path);

            EventObjectArrayInheritanceConfigInit.RunObjectArrInheritanceAssertion(env, path);
        }
Esempio n. 16
0
        public void Run(RegressionEnvironment env)
        {
            var fields = new [] { "company","value","total" };

            var eplSchema = "create schema S2 ( company string, value double, total double)";
            var path = new RegressionPath();
            env.CompileDeployWBusPublicType(eplSchema, path);

            // ESPER-568
            env.CompileDeploy("@Name('create') create window S2Win#time(25 hour)#firstunique(company) as S2", path);
            env.CompileDeploy("insert into S2Win select * from S2#firstunique(company)", path);
            env.CompileDeploy("on S2 as a update S2Win as b set total = b.value + a.value", path);
            env.CompileDeploy("@Name('s0') select count(*) as cnt from S2Win", path).AddListener("s0");

            CreateSendEvent(env, "S2", "AComp", 3.0, 0.0);
            Assert.AreEqual(1L, env.Listener("s0").AssertOneGetNewAndReset().Get("cnt"));
            EPAssertionUtil.AssertPropsPerRow(
                env.GetEnumerator("create"),
                fields,
                new[] {new object[] {"AComp", 3.0, 0.0}});

            CreateSendEvent(env, "S2", "AComp", 6.0, 0.0);
            Assert.AreEqual(1L, env.Listener("s0").AssertOneGetNewAndReset().Get("cnt"));
            EPAssertionUtil.AssertPropsPerRow(
                env.GetEnumerator("create"),
                fields,
                new[] {new object[] {"AComp", 3.0, 9.0}});

            CreateSendEvent(env, "S2", "AComp", 5.0, 0.0);
            Assert.AreEqual(1L, env.Listener("s0").AssertOneGetNewAndReset().Get("cnt"));
            EPAssertionUtil.AssertPropsPerRow(
                env.GetEnumerator("create"),
                fields,
                new[] {new object[] {"AComp", 3.0, 8.0}});

            CreateSendEvent(env, "S2", "BComp", 4.0, 0.0);
            // this example does not have @priority thereby it is undefined whether there are two counts delivered or one
            if (env.Listener("s0").LastNewData.Length == 2) {
                Assert.AreEqual(1L, env.Listener("s0").LastNewData[0].Get("cnt"));
                Assert.AreEqual(2L, env.Listener("s0").LastNewData[1].Get("cnt"));
            }
            else {
                Assert.AreEqual(2L, env.Listener("s0").AssertOneGetNewAndReset().Get("cnt"));
            }

            EPAssertionUtil.AssertPropsPerRow(
                env.GetEnumerator("create"),
                fields,
                new[] {new object[] {"AComp", 3.0, 7.0}, new object[] {"BComp", 4.0, 0.0}});

            env.UndeployAll();
        }
Esempio n. 17
0
        public void Run(RegressionEnvironment env)
        {
            var epl = "create schema ScoreCycle (userId string, keyword string, ProductId string, score long);\n" +
                      "\n" +
                      "create schema UserKeywordTotalStream (userId string, keyword string, sumScore long);\n" +
                      "\n" +
                      "create context HashByUserCtx as\n" +
                      "coalesce by consistent_hash_crc32(userId) from ScoreCycle,\n" +
                      "consistent_hash_crc32(userId) from UserKeywordTotalStream \n" +
                      "granularity 10000000;\n" +
                      "\n" +
                      "context HashByUserCtx create window ScoreCycleWindow#unique(userId, keyword, ProductId) as ScoreCycle;\n" +
                      "\n" +
                      "context HashByUserCtx insert into ScoreCycleWindow select * from ScoreCycle;\n" +
                      "\n" +
                      "@Name('Select') context HashByUserCtx insert into UserKeywordTotalStream\n" +
                      "select userId, keyword, sum(score) as sumScore from ScoreCycleWindow group by userId, keyword;";
            env.CompileDeployWBusPublicType(epl, new RegressionPath());
            var listener = new MyUpdateListener();
            env.Statement("Select").AddListener(listener);

            IList<IDictionary<string, object>> sendsT1 = new List<IDictionary<string, object>>();
            sendsT1.Add(MakeEvent("A", "house", "P0", 1));
            sendsT1.Add(MakeEvent("B", "house", "P0", 2));
            IList<IDictionary<string, object>> sendsT2 = new List<IDictionary<string, object>>();
            sendsT2.Add(MakeEvent("B", "house", "P0", 3));
            sendsT1.Add(MakeEvent("A", "house", "P0", 4));

            var threadPool = Executors.NewFixedThreadPool(
                2,
                new SupportThreadFactory(typeof(MultithreadContextUnique)).ThreadFactory);
            var runnableOne = new SendEventRunnable(env.Runtime, sendsT1, "ScoreCycle");
            var runnableTwo = new SendEventRunnable(env.Runtime, sendsT2, "ScoreCycle");
            threadPool.Submit(runnableOne.Run);
            threadPool.Submit(runnableTwo.Run);

            threadPool.Shutdown();
            SupportCompileDeployUtil.ExecutorAwait(threadPool, 1, TimeUnit.SECONDS);

            Assert.IsNull(runnableOne.LastException);
            Assert.IsNull(runnableTwo.LastException);

            // compare
            var received = listener.Received;
            foreach (var item in received) {
                Console.Out.WriteLine(item);
            }

            Assert.AreEqual(4, received.Count);

            env.UndeployAll();
        }
Esempio n. 18
0
        public void Run(RegressionEnvironment env)
        {
            var path = new RegressionPath();
            var epl =
                "create schema RootEvent(base string);\n" +
                "create schema Sub1Event(sub1 string) inherits RootEvent;\n" +
                "create schema Sub2Event(sub2 string) inherits RootEvent;\n" +
                "create schema SubAEvent(suba string) inherits Sub1Event;\n" +
                "create schema SubBEvent(subb string) inherits Sub1Event, Sub2Event;\n";
            env.CompileDeployWBusPublicType(epl, path);

            EventMapInheritanceInitTime.RunAssertionMapInheritance(env, path);
        }
Esempio n. 19
0
        private static void RunAssertionObjectArrPropertyReorder(RegressionEnvironment env)
        {
            var epl = "create objectarray schema MyInner (p_inner string);\n" +
                      "create objectarray schema MyOATarget (unfilled string, p0 string, p1 string, i0 MyInner);\n" +
                      "create objectarray schema MyOASource (p0 string, p1 string, i0 MyInner);\n" +
                      "insert into MyOATarget select p0, p1, i0, null as unfilled from MyOASource;\n" +
                      "@Name('s0') select * from MyOATarget;\n";
            env.CompileDeployWBusPublicType(epl, new RegressionPath()).AddListener("s0");

            env.SendEventObjectArray(new object[] {"p0value", "p1value", new object[] {"i"}}, "MyOASource");
            EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), "p0,p1".SplitCsv(), new object[] {"p0value", "p1value"});

            env.UndeployAll();
        }
Esempio n. 20
0
        private static void RunAssertionCreateStreamTwo(
            RegressionEnvironment env,
            EventRepresentationChoice eventRepresentationEnum)
        {
            var path = new RegressionPath();
            var epl = eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedMyEvent>() +
                      " create schema MyEvent(myId int)\n;" +
                      eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedAllMyEvent>() +
                      " create schema AllMyEvent as (myEvent MyEvent, clazz String, reverse boolean);\n" +
                      eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedSuspectMyEvent>() +
                      " create schema SuspectMyEvent as (myEvent MyEvent, clazz String);\n";
            env.CompileDeployWBusPublicType(epl, path);

            env.CompileDeploy(
                    "@Name('s0') insert into AllMyEvent " +
                    "select c as myEvent, 'test' as clazz, false as reverse " +
                    "from MyEvent(myId=1) c",
                    path)
                .AddListener("s0");

            Assert.IsTrue(eventRepresentationEnum.MatchesClass(env.Statement("s0").EventType.UnderlyingType));

            env.CompileDeploy(
                    "@Name('s1') insert into SuspectMyEvent " +
                    "select c.myEvent as myEvent, clazz " +
                    "from AllMyEvent(not reverse) c",
                    path)
                .AddListener("s1");

            if (eventRepresentationEnum.IsObjectArrayEvent()) {
                env.SendEventObjectArray(MakeEvent(1).Values.ToArray(), "MyEvent");
            }
            else if (eventRepresentationEnum.IsMapEvent()) {
                env.SendEventMap(MakeEvent(1), "MyEvent");
            }
            else if (eventRepresentationEnum.IsAvroEvent()) {
                env.SendEventAvro(MakeEventAvro(1), "MyEvent");
            }
            else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) {
                env.SendEventJson("{\"myId\": 1}", "MyEvent");
            }
            else {
                Assert.Fail();
            }

            AssertCreateStreamTwo(eventRepresentationEnum, env.Listener("s0").AssertOneGetNewAndReset(), env.Statement("s0"));
            AssertCreateStreamTwo(eventRepresentationEnum, env.Listener("s1").AssertOneGetNewAndReset(), env.Statement("s1"));

            env.UndeployAll();
        }
            public void Run(RegressionEnvironment env)
            {
                string epl = "create objectarray schema Event(meta1 string[], meta2 string[]);\n" +
                             "@Name('s0') select * from Event(meta1.intersect(meta2).countOf() > 0);\n";

                env.CompileDeployWBusPublicType(epl, new RegressionPath()).AddListener("s0");

                SendAndAssert(env, "a,b", "a,b", true);
                SendAndAssert(env, "c,d", "a,b", false);
                SendAndAssert(env, "c,d", "a,d", true);
                SendAndAssert(env, "a,d,a,a", "b,c", false);
                SendAndAssert(env, "a,d,a,a", "b,d", true);

                env.UndeployAll();
            }
Esempio n. 22
0
        private static void TryAssertionSplitPremptiveNamedWindow(
            RegressionEnvironment env,
            EventRepresentationChoice eventRepresentationEnum)
        {
            var path = new RegressionPath();
            env.CompileDeployWBusPublicType(
                eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedTrigger>() + " create schema TypeTrigger(trigger int)",
                path);
            env.CompileDeploy(eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedTypeTwo>() + " create schema TypeTwo(col2 int)", path);
            env.CompileDeploy(
                eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedTypeTwo>() + " create window WinTwo#keepall as TypeTwo",
                path);

            var stmtOrigText = "on TypeTrigger " +
                               "insert into OtherStream select 1 " +
                               "insert into WinTwo(col2) select 2 " +
                               "output all";
            env.CompileDeploy(stmtOrigText, path);

            env.CompileDeploy("@Name('s0') on OtherStream select col2 from WinTwo", path).AddListener("s0");

            // populate WinOne
            env.SendEventBean(new SupportBean("E1", 2));

            // fire trigger
            if (eventRepresentationEnum.IsObjectArrayEvent()) {
                env.SendEventObjectArray(new object[] {null}, "TypeTrigger");
            }
            else if (eventRepresentationEnum.IsMapEvent()) {
                env.SendEventMap(new Dictionary<string, object>(), "TypeTrigger");
            }
            else if (eventRepresentationEnum.IsAvroEvent()) {
                var @event = new GenericRecord(
                    SchemaBuilder.Record("name", TypeBuilder.OptionalInt("trigger")));
                env.SendEventAvro(@event, "TypeTrigger");
            }
            else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) {
                env.SendEventJson("{}", "TypeTrigger");
            }
            else {
                Assert.Fail();
            }

            Assert.AreEqual(2, env.Listener("s0").AssertOneGetNewAndReset().Get("col2"));

            env.UndeployAll();
        }
Esempio n. 23
0
            public void Run(RegressionEnvironment env)
            {
                var epl = "create schema IncomingEvent(Id int);\n" +
                          "create schema RetainedEvent(Id int);\n" +
                          "insert into RetainedEvent select * from IncomingEvent#expr_batch(current_count >= 10000);\n" +
                          "create window RetainedEventWindow#keepall as RetainedEvent;\n" +
                          "insert into RetainedEventWindow select * from RetainedEvent;\n";
                env.CompileDeployWBusPublicType(epl, new RegressionPath());

                IDictionary<string, object> @event = new Dictionary<string, object>();
                @event.Put("Id", 1);
                for (var i = 0; i < 10000; i++) {
                    env.SendEventMap(@event, "IncomingEvent");
                }

                env.UndeployAll();
            }
Esempio n. 24
0
            public void Run(RegressionEnvironment env)
            {
                var epl =
                    "create schema ValueEvent(value long);\n" +
                    "create schema ResetEvent(startThreshold long);\n" +
                    "create table CurrentMaxTable(currentThreshold long);\n" +
                    "@Name('s0') insert into ThresholdTriggered select * from ValueEvent(value >= CurrentMaxTable.currentThreshold);\n" +
                    "on ResetEvent merge CurrentMaxTable when matched then update set currentThreshold = startThreshold when not matched then insert select startThreshold as currentThreshold;\n" +
                    "on ThresholdTriggered update CurrentMaxTable set currentThreshold = value + 100;\n";
                env.CompileDeployWBusPublicType(epl, new RegressionPath()).AddListener("s0");

                env.SendEventMap(Collections.SingletonDataMap("startThreshold", 100L), "ResetEvent");
                env.SendEventMap(Collections.SingletonDataMap("value", 30L), "ValueEvent");
                env.SendEventMap(Collections.SingletonDataMap("value", 99L), "ValueEvent");

                env.Milestone(0);

                env.SendEventMap(Collections.SingletonDataMap("value", 100L), "ValueEvent");
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    new[] {"value"},
                    new object[] {100L});

                env.SendEventMap(Collections.SingletonDataMap("value", 101L), "ValueEvent");
                env.SendEventMap(Collections.SingletonDataMap("value", 103L), "ValueEvent");
                env.SendEventMap(Collections.SingletonDataMap("value", 130L), "ValueEvent");
                env.SendEventMap(Collections.SingletonDataMap("value", 199L), "ValueEvent");

                env.Milestone(1);

                env.SendEventMap(Collections.SingletonDataMap("value", 200L), "ValueEvent");
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    new[] {"value"},
                    new object[] {200L});

                env.SendEventMap(Collections.SingletonDataMap("value", 201L), "ValueEvent");
                env.SendEventMap(Collections.SingletonDataMap("value", 260L), "ValueEvent");
                env.SendEventMap(Collections.SingletonDataMap("value", 301L), "ValueEvent");
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    new[] {"value"},
                    new object[] {301L});

                env.UndeployAll();
            }
Esempio n. 25
0
            private static void TryAssertionInnerJoinLateStart(
                RegressionEnvironment env,
                EventRepresentationChoice eventRepresentationEnum)
            {
                var schemaEPL = eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedProduct>() +
                                "@Name('schema') create schema Product (product string, size int);\n" +
                                eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedPortfolio>() +
                                " create schema Portfolio (portfolio string, product string);\n";
                var path = new RegressionPath();
                env.CompileDeployWBusPublicType(schemaEPL, path);

                env.CompileDeploy("@Name('window') create window ProductWin#keepall as Product", path);

                Assert.IsTrue(eventRepresentationEnum.MatchesClass(env.Statement("schema").EventType.UnderlyingType));
                Assert.IsTrue(eventRepresentationEnum.MatchesClass(env.Statement("window").EventType.UnderlyingType));

                env.CompileDeploy("insert into ProductWin select * from Product", path);
                env.CompileDeploy("create window PortfolioWin#keepall as Portfolio", path);
                env.CompileDeploy("insert into PortfolioWin select * from Portfolio", path);

                SendProduct(env, eventRepresentationEnum, "productA", 1);
                SendProduct(env, eventRepresentationEnum, "productB", 2);
                sendPortfolio(env, eventRepresentationEnum, "Portfolio", "productA");

                var stmtText = "@Name(\"Query2\") select portfolio, ProductWin.product, size " +
                               "from PortfolioWin unidirectional inner join ProductWin on PortfolioWin.product=ProductWin.product";
                env.CompileDeploy(stmtText, path).AddListener("Query2");

                sendPortfolio(env, eventRepresentationEnum, "Portfolio", "productB");
                EPAssertionUtil.AssertProps(
                    env.Listener("Query2").AssertOneGetNewAndReset(),
                    new[] {"portfolio", "ProductWin.product", "size"},
                    new object[] {"Portfolio", "productB", 2});

                sendPortfolio(env, eventRepresentationEnum, "Portfolio", "productC");
                env.Listener("Query2").Reset();

                SendProduct(env, eventRepresentationEnum, "productC", 3);
                sendPortfolio(env, eventRepresentationEnum, "Portfolio", "productC");
                EPAssertionUtil.AssertProps(
                    env.Listener("Query2").AssertOneGetNewAndReset(),
                    new[] {"portfolio", "ProductWin.product", "size"},
                    new object[] {"Portfolio", "productC", 3});

                env.UndeployAll();
            }
Esempio n. 26
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                var schemaEPL =
                    "create objectarray schema MyEventOne(type string, p0 int, p1 string);\n" +
                    "create objectarray schema MyEventTwo(type string, f0 string, f1 int);\n";
                env.CompileDeployWBusPublicType(schemaEPL, path);

                env.CompileDeploy("@Name('s0') select * from MyEventOne", path).AddListener("s0");
                env.CompileDeploy("@Name('s1') select * from MyEventTwo", path).AddListener("s1");

                env.CompileDeploy(
                    "@Name('flow') create dataflow MyDataFlow " +
                    "MyObjectArrayGraphSource -> OutStream<?> {}" +
                    "EventBusSink(OutStream) {" +
                    "  collector : {" +
                    "    class: '" +
                    typeof(MyTransformToEventBus).FullName +
                    "'" +
                    "  }" +
                    "}");

                var source = new MyObjectArrayGraphSource(
                    Arrays.AsList(
                            new object[] {"type1", 100, "abc"},
                            new object[] {"type2", "GE", -1}
                        )
                        .GetEnumerator());
                var options = new EPDataFlowInstantiationOptions()
                    .WithOperatorProvider(new DefaultSupportGraphOpProvider(source));
                env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlow", options).Start();

                env.Listener("s0").WaitForInvocation(3000, 1);
                env.Listener("s1").WaitForInvocation(3000, 1);
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    new [] { "p0","p1" },
                    new object[] {100, "abc"});
                EPAssertionUtil.AssertProps(
                    env.Listener("s1").AssertOneGetNewAndReset(),
                    new [] { "f0","f1" },
                    new object[] {"GE", -1});

                env.UndeployAll();
            }
        private static void TrySend(
            RegressionEnvironment env,
            int numThreads,
            int numEventsPerThread)
        {
            var path = new RegressionPath();
            var schemas = "create schema MyUpdateEvent as (key string, intupd int);\n" +
                          "create schema MySchema as (TheString string, intval int);\n";
            env.CompileDeployWBusPublicType(schemas, path);

            env.CompileDeploy("@Name('window') create window MyWindow#keepall as MySchema", path);
            env.CompileDeploy(
                "on MyUpdateEvent mue merge MyWindow mw " +
                "where mw.TheString = mue.key " +
                "when not matched then insert select key as TheString, intupd as intval " +
                "when matched then delete",
                path);
            env.CompileDeploy(
                "@Name('target') select (select intval from MyWindow mw where mw.TheString = sb.TheString) as val from SupportBean sb",
                path);

            // execute
            var threadPool = Executors.NewFixedThreadPool(
                numThreads,
                new SupportThreadFactory(typeof(MultithreadStmtNamedWindowSubqueryLookup)).ThreadFactory);
            var future = new IFuture<bool?>[numThreads];
            for (var i = 0; i < numThreads; i++) {
                future[i] = threadPool.Submit(
                    new StmtNamedWindowSubqueryLookupCallable(
                        i,
                        env.Runtime,
                        numEventsPerThread,
                        env.Statement("target")));
            }

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

            var events = EPAssertionUtil.EnumeratorToArray(env.GetEnumerator("window"));
            Assert.AreEqual(0, events.Length);

            env.UndeployAll();
        }
        private void RunAssertionBean(RegressionEnvironment env)
        {
            var path = new RegressionPath();
            env.CompileDeployWBusPublicType(
                "create schema MyIndexMappedSamplerBean as " + typeof(MyIndexMappedSamplerBean).MaskTypeName(),
                path);

            env.CompileDeploy("@Name('s0') select * from MyIndexMappedSamplerBean", path).AddListener("s0");

            env.SendEventBean(new MyIndexMappedSamplerBean());

            var @event = env.Listener("s0").AssertOneGetNewAndReset();
            var type = @event.EventType;
            Assert.AreEqual(2, type.GetGetterIndexed("ListOfInt").Get(@event, 1));
            Assert.AreEqual(2, type.GetGetterIndexed("IterableOfInt").Get(@event, 1));

            env.UndeployAll();
        }
Esempio n. 29
0
            public void Run(RegressionEnvironment env)
            {
                var epl = eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedSchemaOne>() +
                          " @name('schema') create schema SchemaOne(col1 int, col2 int);\n";
                epl += eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedSchemaWindow>() +
                       " @name('create') create window SchemaWindow#lastevent as (s1 SchemaOne);\n";
                epl += "insert into SchemaWindow (s1) select sone from SchemaOne as sone;\n";
                env.CompileDeployWBusPublicType(epl, new RegressionPath()).AddListener("create");

                Assert.IsTrue(eventRepresentationEnum.MatchesClass(env.Statement("schema").EventType.UnderlyingType));
                Assert.IsTrue(eventRepresentationEnum.MatchesClass(env.Statement("create").EventType.UnderlyingType));

                if (eventRepresentationEnum.IsObjectArrayEvent()) {
                    env.SendEventObjectArray(new object[] {10, 11}, "SchemaOne");
                }
                else if (eventRepresentationEnum.IsMapEvent()) {
                    IDictionary<string, object> theEvent = new Dictionary<string, object>();
                    theEvent.Put("col1", 10);
                    theEvent.Put("col2", 11);
                    env.SendEventMap(theEvent, "SchemaOne");
                }
                else if (eventRepresentationEnum.IsAvroEvent()) {
                    var theEvent = new GenericRecord(
                        SupportAvroUtil
                            .GetAvroSchema(env.Runtime.EventTypeService.GetEventTypePreconfigured("SchemaOne"))
                            .AsRecordSchema());
                    theEvent.Put("col1", 10);
                    theEvent.Put("col2", 11);
                    env.EventService.SendEventAvro(theEvent, "SchemaOne");
                }
                else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) {
                    env.EventService.SendEventJson("{\"col1\": 10, \"col2\": 11}", "SchemaOne");
                }
                else {
                    Assert.Fail();
                }

                EPAssertionUtil.AssertProps(
                    env.Listener("create").AssertOneGetNewAndReset(),
                    new[] {"s1.col1", "s1.col2"},
                    new object[] {10, 11});

                env.UndeployAll();
            }
Esempio n. 30
0
        private static void RunAssertPopulateFromNamedWindow(
            RegressionEnvironment env,
            EventRepresentationChoice type)
        {
            var path = new RegressionPath();
            var schemaEPL = type.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedNode>() + "create schema Node(nid string)";
            env.CompileDeployWBusPublicType(schemaEPL, path);

            env.CompileDeploy("create window NodeWindow#unique(nid) as Node", path);
            env.CompileDeploy("insert into NodeWindow select * from Node", path);
            env.CompileDeploy(
                type.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedNodePlus>() + "create schema NodePlus(npid string, node Node)",
                path);
            env.CompileDeploy("@Name('s0') insert into NodePlus select 'E1' as npid, n1 as node from NodeWindow n1", path).AddListener("s0");

            if (type.IsObjectArrayEvent()) {
                env.SendEventObjectArray(new object[] {"n1"}, "Node");
            }
            else if (type.IsMapEvent()) {
                env.SendEventMap(Collections.SingletonDataMap("nid", "n1"), "Node");
            }
            else if (type.IsAvroEvent()) {
                var genericRecord = new GenericRecord(SchemaBuilder.Record("name", RequiredString("nid")));
                genericRecord.Put("nid", "n1");
                env.SendEventAvro(genericRecord, "Node");
            }
            else if (type.IsJsonEvent() || type.IsJsonProvidedClassEvent()) {
                var @object = new JObject();
                @object.Add("nid", "n1");
                env.SendEventJson(@object.ToString(), "Node");
            }
            else {
                Assert.Fail();
            }

            var @event = env.Listener("s0").AssertOneGetNewAndReset();
            Assert.AreEqual("E1", @event.Get("npid"));
            Assert.AreEqual("n1", @event.Get("node.nid"));
            var fragment = (EventBean) @event.GetFragment("node");
            Assert.AreEqual("Node", fragment.EventType.Name);

            env.UndeployAll();
        }