Exemplo n.º 1
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);
        }
        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();
        }
        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);
        }
Exemplo n.º 4
0
        private void RunAssertionColDefPlain(EventRepresentationEnum eventRepresentationEnum)
        {
            EPStatement stmtCreate = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEventType as (col1 string, col2 int, sbean " + typeof(SupportBean).FullName + ", col3.col4 int)");

            AssertTypeColDef(stmtCreate.EventType);
            EPStatement stmtSelect = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " select * from MyEventType");

            AssertTypeColDef(stmtSelect.EventType);

            stmtSelect.Dispose();
            stmtCreate.Dispose();

            // destroy and create differently
            stmtCreate = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEventType as (col3 string, col4 int)");
            Assert.AreEqual(typeof(int), stmtCreate.EventType.GetPropertyType("col4"));
            Assert.AreEqual(2, stmtCreate.EventType.PropertyDescriptors.Count);

            stmtCreate.Stop();

            // destroy and create differently
            stmtCreate = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEventType as (col5 string, col6 int)");
            Assert.AreEqual(stmtCreate.EventType.UnderlyingType, eventRepresentationEnum.GetOutputClass());
            Assert.AreEqual(typeof(int), stmtCreate.EventType.GetPropertyType("col6"));
            Assert.AreEqual(2, stmtCreate.EventType.PropertyDescriptors.Count);
            stmtSelect         = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " select * from MyEventType");
            stmtSelect.Events += _listener.Update;
            Assert.AreEqual(stmtSelect.EventType.UnderlyingType, eventRepresentationEnum.GetOutputClass());

            // send event
            IDictionary <String, Object> data = new LinkedHashMap <String, Object>();

            data.Put("col5", "abc");
            data.Put("col6", 1);
            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(data.Values.ToArray(), "MyEventType");
            }
            else
            {
                _epService.EPRuntime.SendEvent(data, "MyEventType");
            }
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "col5,col6".Split(','), new Object[] { "abc", 1 });

            // assert type information
            EventTypeSPI typeSPI = (EventTypeSPI)stmtSelect.EventType;

            Assert.AreEqual(TypeClass.APPLICATION, typeSPI.Metadata.TypeClass);
            Assert.AreEqual(typeSPI.Name, typeSPI.Metadata.PublicName);
            Assert.IsTrue(typeSPI.Metadata.IsApplicationConfigured);
            Assert.IsFalse(typeSPI.Metadata.IsApplicationPreConfigured);
            Assert.IsFalse(typeSPI.Metadata.IsApplicationPreConfiguredStatic);
            Assert.AreEqual(typeSPI.Name, typeSPI.Metadata.PrimaryName);

            // test non-enum create-schema
            String      epl           = "create" + eventRepresentationEnum.GetOutputTypeCreateSchemaName() + " schema MyEventTypeTwo as (col1 string, col2 int, sbean " + typeof(SupportBean).FullName + ", col3.col4 int)";
            EPStatement stmtCreateTwo = _epService.EPAdministrator.CreateEPL(epl);

            AssertTypeColDef(stmtCreateTwo.EventType);
            Assert.AreEqual(eventRepresentationEnum.GetOutputClass(), stmtCreateTwo.EventType.UnderlyingType);
            stmtCreateTwo.Dispose();
            _epService.EPAdministrator.Configuration.RemoveEventType("MyEventTypeTwo", true);

            EPStatementObjectModel model = _epService.EPAdministrator.CompileEPL(epl);

            Assert.AreEqual(model.ToEPL(), epl);
            stmtCreateTwo = _epService.EPAdministrator.Create(model);
            AssertTypeColDef(stmtCreateTwo.EventType);
            Assert.AreEqual(eventRepresentationEnum.GetOutputClass(), stmtCreateTwo.EventType.UnderlyingType);

            _epService.Initialize();
        }