Ejemplo n.º 1
0
        public void RunAssertionCreateSchemaModelAfter(EventRepresentationEnum eventRepresentationEnum)
        {
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema EventTypeOne (hsi int)");
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema EventTypeTwo (event EventTypeOne)");
            var stmt = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window NamedWindow.std:unique(event.hsi) as EventTypeTwo");

            _epService.EPAdministrator.CreateEPL("on EventTypeOne as ev insert into NamedWindow select ev as event");

            IDictionary <String, object> theEvent = new LinkedHashMap <string, object>();

            theEvent.Put("hsi", 10);
            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(theEvent.Values.ToArray(), "EventTypeOne");
            }
            else
            {
                _epService.EPRuntime.SendEvent(theEvent, "EventTypeOne");
            }
            var result = stmt.First();
            var getter = result.EventType.GetGetter("event.hsi");

            Assert.AreEqual(10, getter.Get(result));

            _epService.Initialize();
        }
Ejemplo n.º 2
0
        public void RunAssertionEventTypeColumnDef(EventRepresentationEnum eventRepresentationEnum)
        {
            var stmtSchema = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema SchemaOne(col1 int, col2 int)");

            Assert.AreEqual(eventRepresentationEnum.GetOutputClass(), stmtSchema.EventType.UnderlyingType);

            var stmt = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window SchemaWindow.std:lastevent() as (s1 SchemaOne)");

            Assert.AreEqual(eventRepresentationEnum.GetOutputClass(), stmt.EventType.UnderlyingType);

            stmt.AddListener(_listenerWindow);
            _epService.EPAdministrator.CreateEPL("insert into SchemaWindow (s1) select sone from SchemaOne as sone");

            IDictionary <String, object> theEvent = new LinkedHashMap <string, object>();

            theEvent.Put("col1", 10);
            theEvent.Put("col2", 11);
            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(theEvent.Values.ToArray(), "SchemaOne");
            }
            else
            {
                _epService.EPRuntime.SendEvent(theEvent, "SchemaOne");
            }
            EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), "s1.col1,s1.col2".Split(','), new object[] { 10, 11 });

            _epService.EPAdministrator.DestroyAllStatements();
            _epService.EPAdministrator.Configuration.RemoveEventType("SchemaOne", true);
            _epService.EPAdministrator.Configuration.RemoveEventType("SchemaWindow", true);
        }
        private void RunTransposeMapAndObjectArray(EventRepresentationEnum representation)
        {
            String[] fields = "p0,p1".Split(',');
            _epService.EPAdministrator.CreateEPL("create " + representation.GetOutputTypeCreateSchemaName() + " schema MySchema(p0 string, p1 int)");

            String generateFunction = representation == EventRepresentationEnum.MAP ? "generateMap" : "generateOA";
            String epl = "@Name('first') insert into MySchema select transpose(" + generateFunction + "(TheString, IntPrimitive)) from SupportBean";

            _epService.EPAdministrator.CreateEPL(epl).Events += _listener.Update;

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

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

            // MySchema already exists, start second statement
            _epService.EPAdministrator.CreateEPL(epl).AddListener(_listener);
            _epService.EPAdministrator.GetStatement("first").Dispose();

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

            _epService.EPAdministrator.Configuration.RemoveEventType("MySchema", true);
            _epService.EPAdministrator.DestroyAllStatements();
        }
Ejemplo n.º 4
0
        private void RunAssertionObjectArrayDelivery(EventRepresentationEnum eventRepresentationEnum)
        {
            var         subscriber = new MySubscriberRowByRowObjectArr();
            EPStatement stmt       = _epService.EPAdministrator.CreateEPL(
                eventRepresentationEnum.GetAnnotationText()
                + " select TheString, IntPrimitive from SupportBean.std:unique(TheString)");

            stmt.Subscriber = subscriber;
            Assert.AreEqual(eventRepresentationEnum.GetOutputClass(),
                            stmt.EventType.UnderlyingType);

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            EPAssertionUtil.AssertEqualsAnyOrder(
                subscriber.GetAndResetIndicate()[0], new Object[]
            {
                "E1", 1
            }
                );

            _epService.EPRuntime.SendEvent(new SupportBean("E2", 10));
            EPAssertionUtil.AssertEqualsAnyOrder(
                subscriber.GetAndResetIndicate()[0], new Object[]
            {
                "E2", 10
            }
                );

            _epService.EPAdministrator.DestroyAllStatements();
        }
Ejemplo n.º 5
0
        private void RunAssertionWidening(EventRepresentationEnum eventRepresentationEnum)
        {
            var         subscriber = new MySubscriberRowByRowSpecific();
            EPStatement stmt       = _epService.EPAdministrator.CreateEPL(
                eventRepresentationEnum.GetAnnotationText()
                + " select BytePrimitive, IntPrimitive, LongPrimitive, FloatPrimitive from SupportBean(TheString='E1')");

            stmt.Subscriber = subscriber;
            Assert.AreEqual(eventRepresentationEnum.GetOutputClass(),
                            stmt.EventType.UnderlyingType);

            var bean = new SupportBean();

            bean.TheString      = "E1";
            bean.BytePrimitive  = 1;
            bean.IntPrimitive   = 2;
            bean.LongPrimitive  = 3;
            bean.FloatPrimitive = 4;
            _epService.EPRuntime.SendEvent(bean);
            EPAssertionUtil.AssertEqualsExactOrder(new Object[]
            {
                1, 2L, 3d, 4d
            }
                                                   , subscriber.GetAndResetIndicate()[0]);

            _epService.EPAdministrator.DestroyAllStatements();
        }
Ejemplo n.º 6
0
        private void RunAssertPopulateFromNamedWindow(EventRepresentationEnum type)
        {
            _epService.EPAdministrator.CreateEPL("create " + type.GetOutputTypeCreateSchemaName() + " schema Node(nid string)");
            _epService.EPAdministrator.CreateEPL("create window NodeWindow.std:unique(nid) as Node");
            _epService.EPAdministrator.CreateEPL("insert into NodeWindow select * from Node");
            _epService.EPAdministrator.CreateEPL("create " + type.GetOutputTypeCreateSchemaName() + " schema NodePlus(npid string, node Node)");

            var stmt = _epService.EPAdministrator.CreateEPL("insert into NodePlus select 'E1' as npid, n1 as node from NodeWindow n1");

            stmt.Events += _listener.Update;

            if (type.GetOutputClass() == typeof(object[]))
            {
                _epService.EPRuntime.SendEvent(new Object[] { "n1" }, "Node");
            }
            else
            {
                _epService.EPRuntime.SendEvent(Collections.SingletonDataMap("nid", "n1"), "Node");
            }
            var @event = _listener.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);

            _epService.EPAdministrator.DestroyAllStatements();
            _epService.EPAdministrator.Configuration.RemoveEventType("Node", true);
            _epService.EPAdministrator.Configuration.RemoveEventType("NodePlus", true);
            _epService.EPAdministrator.Configuration.RemoveEventType("NodeWindow", true);
        }
Ejemplo n.º 7
0
        public void RunAssertionSplitPremptiveNamedWindow(EventRepresentationEnum eventRepresentationEnum)
        {
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema TypeTwo(col2 int)");
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema TypeTrigger(trigger int)");
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window WinTwo.win:keepall() as TypeTwo");

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

            _epService.EPAdministrator.CreateEPL(stmtOrigText);

            var stmt = _epService.EPAdministrator.CreateEPL("on OtherStream select col2 from WinTwo");

            stmt.Events += _listener.Update;

            // populate WinOne
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 2));

            // fire trigger
            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.GetEventSender("TypeTrigger").SendEvent(new Object[] { null });
            }
            else
            {
                _epService.EPRuntime.GetEventSender("TypeTrigger").SendEvent(new DataMapImpl());
            }

            Assert.AreEqual(2, _listener.AssertOneGetNewAndReset().Get("col2"));

            _epService.Initialize();
        }
Ejemplo n.º 8
0
        private void RunAssertionOutputLimitNoJoin(EventRepresentationEnum eventRepresentationEnum)
        {
            var         subscriber = new MySubscriberRowByRowSpecific();
            EPStatement stmt       = _epService.EPAdministrator.CreateEPL(
                eventRepresentationEnum.GetAnnotationText()
                + " select TheString, IntPrimitive from SupportBean output every 2 events");

            stmt.Subscriber = subscriber;
            Assert.AreEqual(eventRepresentationEnum.GetOutputClass(),
                            stmt.EventType.UnderlyingType);

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            Assert.AreEqual(0, subscriber.GetAndResetIndicate().Count);
            _epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            EPAssertionUtil.AssertEqualsExactOrder(new Object[][]
            {
                new Object[]
                {
                    "E1", 1
                }
                ,
                new Object[]
                {
                    "E2", 2
                }
            }
                                                   , subscriber.GetAndResetIndicate());

            _epService.EPAdministrator.DestroyAllStatements();
        }
Ejemplo n.º 9
0
        public void RunAssertionDocExample(EventRepresentationEnum eventRepresentationEnum)
        {
            string baseModule = eventRepresentationEnum.GetAnnotationText() + " create schema OrderEvent as (orderId string, productId string, price double, quantity int, deletedFlag boolean)";

            _epService.EPAdministrator.DeploymentAdmin.ParseDeploy(baseModule, null, null, null);

            string appModuleOne = eventRepresentationEnum.GetAnnotationText() + " create schema ProductTotalRec as (productId string, totalPrice double);" +
                                  "" +
                                  eventRepresentationEnum.GetAnnotationText() + " @Name('nwProd') create window ProductWindow.std:unique(productId) as ProductTotalRec;" +
                                  "" +
                                  "on OrderEvent oe\n" +
                                  "merge ProductWindow pw\n" +
                                  "where pw.productId = oe.productId\n" +
                                  "when matched\n" +
                                  "then update set totalPrice = totalPrice + oe.price\n" +
                                  "when not matched\n" +
                                  "then insert select productId, price as totalPrice;";

            _epService.EPAdministrator.DeploymentAdmin.ParseDeploy(appModuleOne, null, null, null);

            string appModuleTwo = eventRepresentationEnum.GetAnnotationText() + " @Name('nwOrd') create window OrderWindow.win:keepall() as OrderEvent;" +
                                  "" +
                                  "on OrderEvent oe\n" +
                                  "  merge OrderWindow pw\n" +
                                  "  where pw.orderId = oe.orderId\n" +
                                  "  when not matched \n" +
                                  "    then insert select *\n" +
                                  "  when matched and oe.deletedFlag=true\n" +
                                  "    then delete\n" +
                                  "  when matched\n" +
                                  "    then update set pw.quantity = oe.quantity, pw.price = oe.price";

            _epService.EPAdministrator.DeploymentAdmin.ParseDeploy(appModuleTwo, null, null, null);

            SendOrderEvent(eventRepresentationEnum, "O1", "P1", 10, 100, false);
            SendOrderEvent(eventRepresentationEnum, "O1", "P1", 11, 200, false);
            SendOrderEvent(eventRepresentationEnum, "O2", "P2", 3, 300, false);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(_epService.EPAdministrator.GetStatement("nwProd").GetEnumerator(), "productId,totalPrice".Split(','), new object[][] { new object[] { "P1", 21d }, new object[] { "P2", 3d } });
            EPAssertionUtil.AssertPropsPerRowAnyOrder(_epService.EPAdministrator.GetStatement("nwOrd").GetEnumerator(), "orderId,quantity".Split(','), new object[][] { new object[] { "O1", 200 }, new object[] { "O2", 300 } });

            string module = "create schema StreetCarCountSchema (streetid string, carcount int);" +
                            "    create schema StreetChangeEvent (streetid string, action string);" +
                            "    create window StreetCarCountWindow.std:unique(streetid) as StreetCarCountSchema;" +
                            "    on StreetChangeEvent ce merge StreetCarCountWindow w where ce.streetid = w.streetid\n" +
                            "    when not matched and ce.action = 'ENTER' then insert select streetid, 1 as carcount\n" +
                            "    when matched and ce.action = 'ENTER' then update set StreetCarCountWindow.carcount = carcount + 1\n" +
                            "    when matched and ce.action = 'LEAVE' then update set StreetCarCountWindow.carcount = carcount - 1;" +
                            "    select * from StreetCarCountWindow;";

            _epService.EPAdministrator.DeploymentAdmin.ParseDeploy(module, null, null, null);

            _epService.EPAdministrator.DestroyAllStatements();
            foreach (string name in "OrderEvent,OrderWindow,StreetCarCountSchema,StreetCarCountWindow,StreetChangeEvent,ProductWindow,ProductTotalRec".Split(','))
            {
                _epService.EPAdministrator.Configuration.RemoveEventType(name, true);
            }
        }
Ejemplo n.º 10
0
        public void RunAssertionFragment(EventRepresentationEnum eventRepresentationEnum)
        {
            _epService.EPAdministrator.CreateEPL(
                eventRepresentationEnum.GetAnnotationText()
                + " create schema InnerSchema as (key string)");
            _epService.EPAdministrator.CreateEPL(
                eventRepresentationEnum.GetAnnotationText()
                + " create schema MySchema as (inside InnerSchema, insidearr InnerSchema[])");

            var    fields   = new String[] { "t0", "t1" };
            String stmtText = eventRepresentationEnum.GetAnnotationText()
                              + " select Typeof(s0.inside) as t0, Typeof(s0.insidearr) as t1 from MySchema as s0";
            EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText);

            stmt.Events += _listener.Update;

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(new Object[2], "MySchema");
            }
            else
            {
                _epService.EPRuntime.SendEvent(new Dictionary <String, Object>(),
                                               "MySchema");
            }
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null, null });

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(new Object[] { new Object[2], null }, "MySchema");
            }
            else
            {
                var theEvent = new Dictionary <String, Object>();
                theEvent["inside"] = new Dictionary <String, Object>();
                _epService.EPRuntime.SendEvent(theEvent, "MySchema");
            }
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "InnerSchema", null });

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(new Object[] { null, new Object[2][] }, "MySchema");
            }
            else
            {
                var theEvent = new Dictionary <String, Object>();
                theEvent["insidearr"] = new IDictionary <string, object> [0];
                _epService.EPRuntime.SendEvent(theEvent, "MySchema");
            }

            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null, "InnerSchema[]" });

            _epService.EPAdministrator.DestroyAllStatements();
            _epService.EPAdministrator.Configuration.RemoveEventType("InnerSchema", true);
            _epService.EPAdministrator.Configuration.RemoveEventType("MySchema", true);
        }
Ejemplo n.º 11
0
        private void RunAssertionPerformance(bool namedWindow, EventRepresentationEnum outputType)
        {
            string eplCreate = namedWindow ?
                               outputType.GetAnnotationText() + " create window MyWindow.win:keepall() as (c1 string, c2 int)" :
                               "create table MyWindow(c1 string primary key, c2 int)";
            EPStatement stmtNamedWindow = _epService.EPAdministrator.CreateEPL(eplCreate);

            Assert.AreEqual(outputType.GetOutputClass(), stmtNamedWindow.EventType.UnderlyingType);

            // preload events
            EPStatement stmt         = _epService.EPAdministrator.CreateEPL("insert into MyWindow select TheString as c1, IntPrimitive as c2 from SupportBean");
            int         totalUpdated = 5000;

            for (int i = 0; i < totalUpdated; i++)
            {
                _epService.EPRuntime.SendEvent(new SupportBean("E" + i, 0));
            }
            stmt.Dispose();

            string epl = "on SupportBean sb merge MyWindow nw where nw.c1 = sb.TheString " +
                         "when matched then update set nw.c2=sb.IntPrimitive";

            stmt = _epService.EPAdministrator.CreateEPL(epl);
            stmt.AddListener(_mergeListener);

            // prime
            for (int i = 0; i < 100; i++)
            {
                _epService.EPRuntime.SendEvent(new SupportBean("E" + i, 1));
            }
            var delta = PerformanceObserver.TimeMillis(
                () =>
            {
                for (int i = 0; i < totalUpdated; i++)
                {
                    _epService.EPRuntime.SendEvent(new SupportBean("E" + i, 1));
                }
            });

            // verify
            IEnumerator <EventBean> events = stmtNamedWindow.GetEnumerator();
            int count = 0;

            while (events.MoveNext())
            {
                EventBean next = events.Current;
                Assert.AreEqual(1, next.Get("c2"));
                count++;
            }
            Assert.AreEqual(totalUpdated, count);
            Assert.IsTrue(delta < 500, "Delta=" + delta);

            _epService.EPAdministrator.DestroyAllStatements();
            _epService.EPAdministrator.Configuration.RemoveEventType("MyWindow", true);
        }
Ejemplo n.º 12
0
 private void SendMyEvent(EventRepresentationEnum eventRepresentationEnum, string in1, int in2) {
     IDictionary<String, object> theEvent = new LinkedHashMap<string, object>();
     theEvent.Put("in1", in1);
     theEvent.Put("in2", in2);
     if (eventRepresentationEnum.IsObjectArrayEvent()) {
         _epService.EPRuntime.SendEvent(theEvent.Values.ToArray(), "MyEvent");
     }
     else {
         _epService.EPRuntime.SendEvent(theEvent, "MyEvent");
     }
 }
Ejemplo n.º 13
0
        public static void AddAnnotation(this EventRepresentationEnum value, EPStatementObjectModel model)
        {
            if (value == EventRepresentationEnum.DEFAULT)
            {
                return;
            }
            AnnotationPart part = new AnnotationPart(typeof(EventRepresentation).Name);

            part.AddValue("Array", value == EventRepresentationEnum.OBJECTARRAY);
            model.Annotations = Collections.SingletonList(part);
        }
Ejemplo n.º 14
0
        private void RunAssertionFields(EventRepresentationEnum representationEnum, bool eventbean)
        {
            EPDataFlowInstantiationOptions options;

            _epService.EPAdministrator.CreateEPL("create " + representationEnum.GetOutputTypeCreateSchemaName() + " schema MyEvent(p0 string, p1 long, p2 double)");
            var stmtGraph = _epService.EPAdministrator.CreateEPL("create dataflow MyDataFlowOne " +
                                                                 "" +
                                                                 "BeaconSource -> BeaconStream<" + (eventbean ? "EventBean<MyEvent>" : "MyEvent") + "> {" +
                                                                 "  iterations : 3," +
                                                                 "  p0 : 'abc'," +
                                                                 "  p1 : MyMath.Round(MyMath.Random() * 10) + 1," +
                                                                 "  p2 : 1d," +
                                                                 "}" +
                                                                 "DefaultSupportCaptureOp(BeaconStream) {}");

            var future = new DefaultSupportCaptureOp(3);

            options = new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProvider(future));
            var df = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

            df.Start();
            Object[] output = future.GetValue(TimeSpan.FromSeconds(2));
            Assert.AreEqual(3, output.Length);
            for (var i = 0; i < 3; i++)
            {
                if (!eventbean)
                {
                    if (representationEnum.IsObjectArrayEvent())
                    {
                        var row = (Object[])output[i];
                        Assert.AreEqual("abc", row[0]);
                        long val = row[1].AsLong();
                        Assert.IsTrue(val >= 0 && val <= 11, "val=" + val);
                        Assert.AreEqual(1d, row[2]);
                    }
                    else
                    {
                        var row = (DataMap)output[i];
                        Assert.AreEqual("abc", row.Get("p0"));
                        long val = row.Get("p1").AsLong();
                        Assert.IsTrue(val >= 0 && val <= 11, "val=" + val);
                        Assert.AreEqual(1d, row.Get("p2"));
                    }
                }
                else
                {
                    var row = (EventBean)output[i];
                    Assert.AreEqual("abc", row.Get("p0"));
                }
            }

            stmtGraph.Dispose();
            _epService.EPAdministrator.Configuration.RemoveEventType("MyEvent", true);
        }
Ejemplo n.º 15
0
 private void SendSentenceEvent(EventRepresentationEnum eventRepresentationEnum, string sentence)
 {
     if (eventRepresentationEnum.IsObjectArrayEvent())
     {
         _epService.EPRuntime.SendEvent(new object[] { sentence }, "SentenceEvent");
     }
     else
     {
         _epService.EPRuntime.SendEvent(
             Collections.SingletonDataMap("sentence", sentence), "SentenceEvent");
     }
 }
Ejemplo n.º 16
0
        private void RunAssertionCreateStreamTwo(EventRepresentationEnum eventRepresentationEnum)
        {
            _epService.EPAdministrator.CreateEPL(
                eventRepresentationEnum.GetAnnotationText()
                + " create schema MyEvent(myId int)");
            _epService.EPAdministrator.CreateEPL(
                eventRepresentationEnum.GetAnnotationText()
                + " create schema AllMyEvent as (myEvent MyEvent, class String, reverse boolean)");
            _epService.EPAdministrator.CreateEPL(
                eventRepresentationEnum.GetAnnotationText()
                + " create schema SuspectMyEvent as (myEvent MyEvent, class String)");

            var stmtOne = _epService.EPAdministrator.CreateEPL(
                "insert into AllMyEvent "
                + "select c as myEvent, 'test' as class, false as reverse "
                + "from MyEvent(myId=1) c");

            stmtOne.Events += _listener.Update;
            Assert.AreEqual(eventRepresentationEnum.GetOutputClass(),
                            stmtOne.EventType.UnderlyingType);

            var stmtTwo = _epService.EPAdministrator.CreateEPL(
                "insert into SuspectMyEvent "
                + "select c.myEvent as myEvent, class "
                + "from AllMyEvent(not reverse) c");
            var listenerTwo = new SupportUpdateListener();

            stmtTwo.Events += listenerTwo.Update;

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(MakeEvent(1).Values.ToArray(), "MyEvent");
            }
            else
            {
                _epService.EPRuntime.SendEvent(MakeEvent(1), "MyEvent");
            }

            var resultOne = _listener.AssertOneGetNewAndReset();

            Assert.IsTrue(resultOne.Get("myEvent") is EventBean);
            Assert.AreEqual(1, ((EventBean)resultOne.Get("myEvent")).Get("myId"));
            Assert.NotNull(stmtOne.EventType.GetFragmentType("myEvent"));

            var resultTwo = listenerTwo.AssertOneGetNewAndReset();

            Assert.IsTrue(resultTwo.Get("myEvent") is EventBean);
            Assert.AreEqual(1, ((EventBean)resultTwo.Get("myEvent")).Get("myId"));
            Assert.NotNull(stmtTwo.EventType.GetFragmentType("myEvent"));

            _epService.Initialize();
        }
Ejemplo n.º 17
0
        private void RunAssertionInsertWhereOMStaggered(EventRepresentationEnum eventRepresentationEnum)
        {
            IDictionary <String, object> dataType = MakeMap(new object[][] { new object[] { "a", typeof(string) }, new object[] { "b", typeof(int) } });

            epService.EPAdministrator.Configuration.AddEventType("MyMap", dataType);

            string      stmtTextCreateOne = eventRepresentationEnum.GetAnnotationText() + " create window MyWindow.win:keepall() as select a, b from MyMap";
            EPStatement stmtCreateOne     = epService.EPAdministrator.CreateEPL(stmtTextCreateOne);

            Assert.AreEqual(eventRepresentationEnum.GetOutputClass(), stmtCreateOne.EventType.UnderlyingType);
            stmtCreateOne.AddListener(listeners[0]);

            // create insert into
            string stmtTextInsertOne = "insert into MyWindow select a, b from MyMap";

            epService.EPAdministrator.CreateEPL(stmtTextInsertOne);

            // populate some data
            epService.EPRuntime.SendEvent(MakeMap(new object[][] { new object[] { "a", "E1" }, new object[] { "b", 2 } }), "MyMap");
            epService.EPRuntime.SendEvent(MakeMap(new object[][] { new object[] { "a", "E2" }, new object[] { "b", 10 } }), "MyMap");
            epService.EPRuntime.SendEvent(MakeMap(new object[][] { new object[] { "a", "E3" }, new object[] { "b", 10 } }), "MyMap");

            // create window with keep-all using OM
            EPStatementObjectModel model = new EPStatementObjectModel();

            eventRepresentationEnum.AddAnnotation(model);
            Expression where   = Expressions.Eq("b", 10);
            model.CreateWindow = CreateWindowClause.Create("MyWindowTwo", View.Create("win", "keepall")).SetInsert(true).SetInsertWhereClause(where);
            model.SelectClause = SelectClause.CreateWildcard();
            model.FromClause   = FromClause.Create(FilterStream.Create("MyWindow"));
            string text = eventRepresentationEnum.GetAnnotationText() + " create window MyWindowTwo.win:keepall() as select * from MyWindow insert where b=10";

            Assert.AreEqual(text.Trim(), model.ToEPL());

            EPStatementObjectModel modelTwo = epService.EPAdministrator.CompileEPL(text);

            Assert.AreEqual(text.Trim(), modelTwo.ToEPL());

            EPStatement stmt = epService.EPAdministrator.Create(modelTwo);

            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), "a,b".Split(','), new object[][] { new object[] { "E2", 10 }, new object[] { "E3", 10 } });

            // test select individual fields and from an insert-from named window
            stmt = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window MyWindowThree.win:keepall() as select a from MyWindowTwo insert where a = 'E2'");
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), "a".Split(','), new object[][] { new object[] { "E2" } });

            epService.EPAdministrator.DestroyAllStatements();
            epService.EPAdministrator.Configuration.RemoveEventType("MyWindow", true);
            epService.EPAdministrator.Configuration.RemoveEventType("MyWindowTwo", true);
            epService.EPAdministrator.Configuration.RemoveEventType("MyWindowThree", true);
        }
Ejemplo n.º 18
0
        private void RunAssertionMapTranspose(EventRepresentationEnum eventRepresentationEnum)
        {
            IDictionary <String, object> innerTypeOne = new Dictionary <string, object>();

            innerTypeOne.Put("i1", typeof(int));
            IDictionary <String, object> innerTypeTwo = new Dictionary <string, object>();

            innerTypeTwo.Put("i2", typeof(int));
            IDictionary <String, object> outerType = new Dictionary <string, object>();

            outerType.Put("one", "T1");
            outerType.Put("two", "T2");
            _epService.EPAdministrator.Configuration.AddEventType("T1", innerTypeOne);
            _epService.EPAdministrator.Configuration.AddEventType("T2", innerTypeTwo);
            _epService.EPAdministrator.Configuration.AddEventType("OuterType", outerType);

            // create window
            var stmtTextCreate = eventRepresentationEnum.GetAnnotationText() + " create window MyWindow.win:keepall() as select one, two from OuterType";
            var stmtCreate     = _epService.EPAdministrator.CreateEPL(stmtTextCreate);

            Assert.AreEqual(eventRepresentationEnum.GetOutputClass(), stmtCreate.EventType.UnderlyingType);
            stmtCreate.AddListener(_listenerWindow);
            EPAssertionUtil.AssertEqualsAnyOrder(stmtCreate.EventType.PropertyNames, new string[] { "one", "two" });
            var eventType = stmtCreate.EventType;

            Assert.AreEqual("T1", eventType.GetFragmentType("one").FragmentType.Name);
            Assert.AreEqual("T2", eventType.GetFragmentType("two").FragmentType.Name);

            // create insert into
            var stmtTextInsertOne = "insert into MyWindow select one, two from OuterType";

            _epService.EPAdministrator.CreateEPL(stmtTextInsertOne);

            IDictionary <String, object> innerDataOne = new Dictionary <string, object>();

            innerDataOne.Put("i1", 1);
            IDictionary <String, object> innerDataTwo = new Dictionary <string, object>();

            innerDataTwo.Put("i2", 2);
            IDictionary <String, object> outerData = new Dictionary <string, object>();

            outerData.Put("one", innerDataOne);
            outerData.Put("two", innerDataTwo);

            _epService.EPRuntime.SendEvent(outerData, "OuterType");
            EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), "one.i1,two.i2".Split(','), new object[] { 1, 2 });

            _epService.EPAdministrator.DestroyAllStatements();
            _epService.EPAdministrator.Configuration.RemoveEventType("MyWindow", true);
        }
Ejemplo n.º 19
0
 private void SendOrderEvent(EventRepresentationEnum eventRepresentationEnum, string orderId, string productId, double price, int quantity, bool deletedFlag) {
     IDictionary<String, object> theEvent = new LinkedHashMap<string, object>();
     theEvent.Put("orderId", orderId);
     theEvent.Put("productId", productId);
     theEvent.Put("price", price);
     theEvent.Put("quantity", quantity);
     theEvent.Put("deletedFlag", deletedFlag);
     if (eventRepresentationEnum.IsObjectArrayEvent()) {
         _epService.EPRuntime.SendEvent(theEvent.Values.ToArray(), "OrderEvent");
     }
     else {
         _epService.EPRuntime.SendEvent(theEvent, "OrderEvent");
     }
 }
Ejemplo n.º 20
0
        private void SendEventOne(EPServiceProvider epService, EventRepresentationEnum eventRepresentationEnum, String id)
        {
            IDictionary <String, Object> theEvent = new LinkedHashMap <String, Object>();

            theEvent.Put("id", id);
            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                epService.EPRuntime.SendEvent(theEvent.Values.ToArray(), "EventOne");
            }
            else
            {
                epService.EPRuntime.SendEvent(theEvent, "EventOne");
            }
        }
Ejemplo n.º 21
0
        public static bool IsObjectArrayEvent(this EventRepresentationEnum value)
        {
            switch (value)
            {
            case EventRepresentationEnum.OBJECTARRAY:
                return(true);

            case EventRepresentationEnum.MAP:
                return(false);

            default:
                return(false);
            }
        }
Ejemplo n.º 22
0
        public static string GetOutputTypeCreateSchemaName(this EventRepresentationEnum value)
        {
            switch (value)
            {
            case EventRepresentationEnum.OBJECTARRAY:
                return(" objectarray");

            case EventRepresentationEnum.MAP:
                return(" map");

            default:
                return(null);
            }
        }
Ejemplo n.º 23
0
        public static string GetAnnotationText(this EventRepresentationEnum value)
        {
            switch (value)
            {
            case EventRepresentationEnum.OBJECTARRAY:
                return("@EventRepresentation(Array=True)");

            case EventRepresentationEnum.MAP:
                return("@EventRepresentation(Array=False)");

            default:
                return(string.Empty);
            }
        }
Ejemplo n.º 24
0
        public void RunAssertionNestableMapArray(EventRepresentationEnum eventRepresentationEnum)
        {
            EPStatement stmtInner = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyInnerType as (col1 string[], col2 int[])");
            EventType   inner     = stmtInner.EventType;

            Assert.AreEqual(typeof(string[]), inner.GetPropertyType("col1"));
            Assert.IsTrue(inner.GetPropertyDescriptor("col1").IsIndexed);
            Assert.AreEqual(typeof(int[]), inner.GetPropertyType("col2"));
            Assert.IsTrue(inner.GetPropertyDescriptor("col2").IsIndexed);
            Assert.AreEqual(eventRepresentationEnum.GetOutputClass(), inner.UnderlyingType);

            EPStatement       stmtOuter = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyOuterType as (col1 MyInnerType, col2 MyInnerType[])");
            FragmentEventType type      = stmtOuter.EventType.GetFragmentType("col1");

            Assert.AreEqual("MyInnerType", type.FragmentType.Name);
            Assert.IsFalse(type.IsIndexed);
            Assert.IsFalse(type.IsNative);
            type = stmtOuter.EventType.GetFragmentType("col2");
            Assert.AreEqual("MyInnerType", type.FragmentType.Name);
            Assert.IsTrue(type.IsIndexed);
            Assert.IsFalse(type.IsNative);

            EPStatement stmtSelect = _epService.EPAdministrator.CreateEPL("select * from MyOuterType");

            stmtSelect.Events += _listener.Update;
            Assert.AreEqual(eventRepresentationEnum.GetOutputClass(), stmtSelect.EventType.UnderlyingType);

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                Object[] innerData = { "abc,def".Split(','), new int[] { 1, 2 } };
                Object[] outerData = { innerData, new Object[] { innerData, innerData } };
                _epService.EPRuntime.SendEvent(outerData, "MyOuterType");
            }
            else
            {
                IDictionary <String, Object> innerData = new Dictionary <String, Object>();
                innerData.Put("col1", "abc,def".Split(','));
                innerData.Put("col2", new int[] { 1, 2 });
                IDictionary <String, Object> outerData = new Dictionary <String, Object>();
                outerData.Put("col1", innerData);
                outerData.Put("col2", new DataMap[] { innerData, innerData });
                _epService.EPRuntime.SendEvent(outerData, "MyOuterType");
            }
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "col1.col1[1],col2[1].col2[1]".Split(','), new Object[] { "def", 2 });

            _epService.EPAdministrator.Configuration.RemoveEventType("MyInnerType", true);
            _epService.EPAdministrator.Configuration.RemoveEventType("MyOuterType", true);
            _epService.EPAdministrator.DestroyAllStatements();
        }
Ejemplo n.º 25
0
        private void RunAssertionObjectArrayDelivery(EventRepresentationEnum eventRepresentationEnum, SupportSubscriberRowByRowObjectArrayBase subscriber)
        {
            var stmt = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " select TheString, IntPrimitive from SupportBean.std:unique(TheString)");

            stmt.Subscriber = subscriber;
            Assert.AreEqual(eventRepresentationEnum.GetOutputClass(), stmt.EventType.UnderlyingType);

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            subscriber.AssertOneAndReset(stmt, new object[] { "E1", 1 });

            _epService.EPRuntime.SendEvent(new SupportBean("E2", 10));
            subscriber.AssertOneAndReset(stmt, new object[] { "E2", 10 });

            stmt.Dispose();
        }
Ejemplo n.º 26
0
        private void RunAssertionOutputLimitNoJoin(EventRepresentationEnum eventRepresentationEnum, SupportSubscriberRowByRowSpecificBase subscriber)
        {
            var stmt = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " select TheString, IntPrimitive from SupportBean output every 2 events");

            stmt.Subscriber = subscriber;
            Assert.AreEqual(eventRepresentationEnum.GetOutputClass(), stmt.EventType.UnderlyingType);

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            subscriber.AssertNoneReceived();

            _epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            subscriber.AssertMultipleReceivedAndReset(stmt, new object[][] { new object[] { "E1", 1 }, new object[] { "E2", 2 } });

            stmt.Dispose();
        }
Ejemplo n.º 27
0
        private void SendPortfolio(EventRepresentationEnum eventRepresentationEnum, string portfolio, string product)
        {
            IDictionary <String, object> theEvent = new LinkedHashMap <string, object>();

            theEvent.Put("portfolio", portfolio);
            theEvent.Put("product", product);
            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(theEvent.Values.ToArray(), "Portfolio");
            }
            else
            {
                _epService.EPRuntime.SendEvent(theEvent, "Portfolio");
            }
        }
Ejemplo n.º 28
0
        public static Type GetOutputClass(this EventRepresentationEnum value)
        {
            switch (value)
            {
            case EventRepresentationEnum.OBJECTARRAY:
                return(typeof(object[]));

            case EventRepresentationEnum.MAP:
                return(typeof(IDictionary <string, object>));

            default:
                return(EventRepresentationExtensions.Default == EventRepresentation.OBJECTARRAY
                               ? typeof(object[])
                               : typeof(IDictionary <string, object>));
            }
        }
Ejemplo n.º 29
0
        private void MakeSendScoreEvent(String typeName, EventRepresentationEnum eventRepresentationEnum, String userId, String keyword, String productId, long score)
        {
            IDictionary <String, Object> theEvent = new LinkedHashMap <String, Object>();

            theEvent.Put("userId", userId);
            theEvent.Put("keyword", keyword);
            theEvent.Put("productId", productId);
            theEvent.Put("score", score);
            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(theEvent.Values.ToArray(), typeName);
            }
            else
            {
                _epService.EPRuntime.SendEvent(theEvent, typeName);
            }
        }
Ejemplo n.º 30
0
        private void RunAssertionGetDynamicWObjectArr(EventRepresentationEnum eventRepresentationEnum)
        {
            String stmtText = eventRepresentationEnum.GetAnnotationText()
                              + " select item.id? as myid from "
                              + typeof (SupportBeanDynRoot).FullName;
            using (var stmt = _epService.EPAdministrator.CreateEPL(stmtText))
            {

                stmt.Events += _listener.Update;

                // check type
                Assert.AreEqual(typeof (object), stmt.EventType.GetPropertyType("myid"));

                // check value with an object that has the property as an int
                var runtime = _epService.EPRuntime;
                runtime.SendEvent(
                    new SupportBeanDynRoot(new SupportBean_S0(101)));
                Assert.AreEqual(101, _listener.AssertOneGetNewAndReset().Get("myid"));

                // check value with an object that doesn't have the property
                runtime.SendEvent(new SupportBeanDynRoot("abc"));
                Assert.AreEqual(null, _listener.AssertOneGetNewAndReset().Get("myid"));

                // check value with an object that has the property as a string
                runtime.SendEvent(
                    new SupportBeanDynRoot(new SupportBean_A("e1")));
                Assert.AreEqual("e1", _listener.AssertOneGetNewAndReset().Get("myid"));

                runtime.SendEvent(
                    new SupportBeanDynRoot(new SupportBean_B("e2")));
                Assert.AreEqual("e2", _listener.AssertOneGetNewAndReset().Get("myid"));

                runtime.SendEvent(
                    new SupportBeanDynRoot(new SupportBean_S1(102)));
                Assert.AreEqual(102, _listener.AssertOneGetNewAndReset().Get("myid"));

                if (eventRepresentationEnum.IsObjectArrayEvent())
                {
                    Assert.AreEqual(typeof (object[]), stmt.EventType.UnderlyingType);
                }
                else
                {
                    Assert.AreEqual(typeof (IDictionary<string, object>), stmt.EventType.UnderlyingType);
                }
            }
        }