Exemple #1
0
            public void Run(RegressionEnvironment env)
            {
                var epl = "@Name('s0') insert into AvroExistingType select " +
                          "1 as MyLong," +
                          "{1L, 2L} as MyLongArray," +
                          typeof(EPLInsertIntoPopulateCreateStreamAvro).Name +
                          ".MakeByteArray() as MyByteArray, " +
                          typeof(EPLInsertIntoPopulateCreateStreamAvro).Name +
                          ".MakeMapStringString() as MyMap " +
                          "from SupportBean";
                env.CompileDeploy(epl).AddListener("s0");

                env.SendEventBean(new SupportBean());
                var @event = env.Listener("s0").AssertOneGetNewAndReset();
                SupportAvroUtil.AvroToJson(@event);
                Assert.AreEqual(1L, @event.Get("MyLong"));
                EPAssertionUtil.AssertEqualsExactOrder(
                    new[] {1L, 2L},
                    @event.Get("MyLongArray").UnwrapIntoArray<long>());

                CollectionAssert.AreEqual(
                    new byte[] {1, 2, 3},
                    (byte[]) @event.Get("MyByteArray"));

                Assert.AreEqual("{\"k1\"=\"v1\"}", @event.Get("MyMap").RenderAny());

                env.UndeployAll();
            }
Exemple #2
0
        public void TestPopulate()
        {
            MySupportBeanWidener.supportBeanSchema = SchemaBuilder.Record("SupportBeanSchema",
                                                                          TypeBuilder.Field("theString", "string"),
                                                                          TypeBuilder.Field("intPrimitive", "int"));

            //MySupportBeanWidener.supportBeanSchema = SchemaExtensions.Record("SupportBeanSchema")
            //    .Fields()
            //    .RequiredString("theString")
            //    .RequiredInt("intPrimitive").EndRecord();

            var schema = SchemaBuilder.Record("MyEventSchema",
                                              TypeBuilder.Field("sb", MySupportBeanWidener.supportBeanSchema));

            //Schema schema = SchemaExtensions.Record("MyEventSchema")
            //    .Fields().Name("sb")
            //    .Type(MySupportBeanWidener.supportBeanSchema)
            //    .NoDefault()
            //    .EndRecord();

            _epService.EPAdministrator.Configuration.AddEventTypeAvro("MyEvent", new ConfigurationEventTypeAvro(schema));

            var epl      = "insert into MyEvent(sb) select " + this.GetType().FullName + ".MakeSupportBean() from SupportBean_S0 as e1";
            var stmt     = _epService.EPAdministrator.CreateEPL(epl);
            var listener = new SupportUpdateListener();

            stmt.AddListener(listener);

            _epService.EPRuntime.SendEvent(new SupportBean_S0(10));
            var @event = listener.AssertOneGetNewAndReset();

            Assert.AreEqual("{\"sb\":{\"theString\":\"E1\",\"intPrimitive\":10}}", SupportAvroUtil.AvroToJson(@event));
        }
        private void RunAssertionCompatExisting()
        {
            string epl = "insert into AvroExistingType select 1 as myLong," +
                         "{1L, 2L} as myLongArray," +
                         this.GetType().FullName + ".MakeByteArray() as myByteArray, " +
                         this.GetType().FullName + ".MakeMapStringString() as myMap " +
                         "from SupportBean";

            Schema schema = SchemaBuilder.Record("name",
                                                 TypeBuilder.RequiredLong("myLong"),
                                                 TypeBuilder.Field("myLongArray", TypeBuilder.Array(TypeBuilder.Long())),
                                                 TypeBuilder.Field("myByteArray", TypeBuilder.Bytes()),
                                                 TypeBuilder.Field("myMap", TypeBuilder.Map(TypeBuilder.String(
                                                                                                TypeBuilder.Property(AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE)))));

            _epService.EPAdministrator.Configuration.AddEventTypeAvro("AvroExistingType", new ConfigurationEventTypeAvro(schema));

            EPStatement           statement = _epService.EPAdministrator.CreateEPL(epl);
            SupportUpdateListener listener  = new SupportUpdateListener();

            statement.AddListener(listener);

            _epService.EPRuntime.SendEvent(new SupportBean());
            EventBean @event = listener.AssertOneGetNewAndReset();

            SupportAvroUtil.AvroToJson(@event);
            Assert.AreEqual(1L, @event.Get("myLong"));
            EPAssertionUtil.AssertEqualsExactOrder(new long[] { 1L, 2L }, @event.Get("myLongArray").UnwrapIntoArray <long>());
            Assert.IsTrue(CompatExtensions.IsEqual(new byte[] { 1, 2, 3 }, ((byte[])@event.Get("myByteArray"))));
            Assert.AreEqual("[k1=v1]", CompatExtensions.Render(@event.Get("myMap").AsStringDictionary()));

            statement.Dispose();
        }
Exemple #4
0
        private void RunAssertionNewWRepresentation(EventRepresentationChoice rep)
        {
            string epl = rep.GetAnnotationText() + "select new { theString = 'x' || theString || 'x', intPrimitive = intPrimitive + 2} as val0 from SupportBean as sb";

            EPStatement stmt = _epService.EPAdministrator.CreateEPL(epl);

            stmt.AddListener(_listener);

            Assert.AreEqual(rep.IsAvroEvent() ? typeof(GenericRecord) : typeof(Map), stmt.EventType.GetPropertyType("val0"));
            FragmentEventType fragType = stmt.EventType.GetFragmentType("val0");

            Assert.IsFalse(fragType.IsIndexed);
            Assert.IsFalse(fragType.IsNative);
            Assert.AreEqual(typeof(string), fragType.FragmentType.GetPropertyType("theString"));
            Assert.AreEqual(typeof(int?), TypeHelper.GetBoxedType(fragType.FragmentType.GetPropertyType("intPrimitive")));

            string[] fieldsInner = "theString,intPrimitive".Split(',');
            _epService.EPRuntime.SendEvent(new SupportBean("E1", -5));
            EventBean @event = _listener.AssertOneGetNewAndReset();

            if (rep.IsAvroEvent())
            {
                SupportAvroUtil.AvroToJson(@event);
                var inner = (GenericRecord)@event.Get("val0");
                Assert.AreEqual("xE1x", inner.Get("theString"));
                Assert.AreEqual(-3, inner.Get("intPrimitive"));
            }
            else
            {
                EPAssertionUtil.AssertPropsMap((Map)@event.Get("val0"), fieldsInner, new Object[] { "xE1x", -3 });
            }

            stmt.Dispose();
        }
Exemple #5
0
        private void RunAssertionArrayAvroResult()
        {
            _epService.EPAdministrator.Configuration.AddEventType(typeof(SupportBean));

            Schema intArraySchema   = SchemaBuilder.Array(TypeBuilder.Int());
            Schema mixedArraySchema = SchemaBuilder.Array(TypeBuilder.Union(TypeBuilder.Int(), TypeBuilder.String(), TypeBuilder.Double()));
            Schema nullArraySchema  = SchemaBuilder.Array(TypeBuilder.Null());

            string stmtText =
                "@AvroSchemaField(Name='emptyArray', Schema='" + intArraySchema.ToString() + "')" +
                "@AvroSchemaField(Name='mixedArray', Schema='" + mixedArraySchema.ToString() + "')" +
                "@AvroSchemaField(Name='nullArray', Schema='" + nullArraySchema.ToString() + "')" +
                EventRepresentationChoice.AVRO.GetAnnotationText() +
                " " +
                "select {'a', 'b'} as stringArray," +
                "{} as emptyArray," +
                "{1} as oneEleArray," +
                "{1,2,3} as intArray," +
                "{1,null} as intNullArray," +
                "{1L,10L} as longArray," +
                "{'a',1, 1e20} as mixedArray," +
                "{1, 1.1d, 1e20} as doubleArray," +
                "{5, 6L} as intLongArray," +
                "{null} as nullArray," +
                "{true, false} as boolArray" +
                " from " + typeof(SupportBean).Name;

            EPStatement stmt     = _epService.EPAdministrator.CreateEPL(stmtText);
            var         listener = new SupportUpdateListener();

            stmt.AddListener(listener);
            _epService.EPRuntime.SendEvent(new SupportBean());

            EventBean theEvent = listener.AssertOneGetNewAndReset();

            SupportAvroUtil.AvroToJson(theEvent);

            CompareColl(theEvent, "stringArray", new string[] { "a", "b" });
            CompareColl(theEvent, "emptyArray", new object[0]);
            CompareColl(theEvent, "oneEleArray", new int[] { 1 });
            CompareColl(theEvent, "intArray", new int[] { 1, 2, 3 });
            CompareColl(theEvent, "intNullArray", new int?[] { 1, null });
            CompareColl(theEvent, "longArray", new long[] { 1L, 10L });
            CompareColl(theEvent, "mixedArray", new object[] { "a", 1, 1e20 });
            CompareColl(theEvent, "doubleArray", new double[] { 1d, 1.1, 1e20 });
            CompareColl(theEvent, "intLongArray", new long[] { 5L, 6L });
            CompareColl(theEvent, "nullArray", new object[] { null });
            CompareColl(theEvent, "boolArray", new bool[] { true, false });

            stmt.Dispose();
        }
Exemple #6
0
        private void RunAssertionArrayAvroResult(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddEventType <SupportBean>();

            Schema intArraySchema   = SchemaBuilder.Array(IntType());
            Schema mixedArraySchema = SchemaBuilder.Array(Union(IntType(), StringType(), DoubleType()));
            Schema nullArraySchema  = SchemaBuilder.Array(NullType());

            var stmtText =
                "@AvroSchemaField(Name='emptyArray', Schema='" + intArraySchema + "')" +
                "@AvroSchemaField(Name='mixedArray', Schema='" + mixedArraySchema + "')" +
                "@AvroSchemaField(Name='nullArray', Schema='" + nullArraySchema + "')" +
                EventRepresentationChoice.AVRO.GetAnnotationText() +
                "select {'a', 'b'} as stringArray," +
                "{} as emptyArray," +
                "{1} as oneEleArray," +
                "{1,2,3} as intArray," +
                "{1,null} as intNullArray," +
                "{1L,10L} as longArray," +
                "{'a',1, 1e20} as mixedArray," +
                "{1, 1.1d, 1e20} as doubleArray," +
                "{5, 6L} as intLongArray," +
                "{null} as nullArray," +
                "{true, false} as boolArray" +
                " from " + typeof(SupportBean).FullName;

            var stmt     = epService.EPAdministrator.CreateEPL(stmtText);
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;
            epService.EPRuntime.SendEvent(new SupportBean());

            var theEvent = listener.AssertOneGetNewAndReset();

            SupportAvroUtil.AvroToJson(theEvent);

            CompareColl(theEvent, "stringArray", new object[] { "a", "b" });
            CompareColl(theEvent, "emptyArray", new object[0]);
            CompareColl(theEvent, "oneEleArray", new object[] { 1 });
            CompareColl(theEvent, "intArray", new object[] { 1, 2, 3 });
            CompareColl(theEvent, "intNullArray", new object[] { 1, null });
            CompareColl(theEvent, "longArray", new object[] { 1L, 10L });
            CompareColl(theEvent, "mixedArray", new object[] { "a", 1, 1e20 });
            CompareColl(theEvent, "doubleArray", new object[] { 1d, 1.1, 1e20 });
            CompareColl(theEvent, "intLongArray", new object[] { 5L, 6L });
            CompareColl(theEvent, "nullArray", new object[] { null });
            CompareColl(theEvent, "boolArray", new object[] { true, false });

            stmt.Dispose();
        }
Exemple #7
0
            public void Run(RegressionEnvironment env)
            {
                var epl = "@Name('s0') insert into MyEventPopulate(sb) select " +
                          typeof(EventAvroHook).FullName +
                          ".MakeSupportBean() from SupportBean_S0 as e1";
                env.CompileDeploy(epl).AddListener("s0");

                env.SendEventBean(new SupportBean_S0(10));
                var @event = env.Listener("s0").AssertOneGetNewAndReset();
                Assert.AreEqual(
                    "{\"sb\":{\"TheString\":\"E1\",\"IntPrimitive\":10}}",
                    SupportAvroUtil.AvroToJson(@event));

                env.UndeployAll();
            }
Exemple #8
0
            public void Run(RegressionEnvironment env)
            {
                var intArraySchema   = SchemaBuilder.Array(IntType());
                var mixedArraySchema = SchemaBuilder.Array(Union(IntType(), StringType(), DoubleType()));
                var nullArraySchema  = SchemaBuilder.Array(NullType());

                var stmtText =
                    "@Name('s0') " +
                    "@AvroSchemaField(Name='EmptyArray', Schema='" + intArraySchema + "')" +
                    "@AvroSchemaField(Name='MixedArray', Schema='" + mixedArraySchema + "')" +
                    "@AvroSchemaField(Name='NullArray', Schema='" + nullArraySchema + "')" +
                    EventRepresentationChoice.AVRO.GetAnnotationText() +
                    "select {'a', 'b'} as StringArray," +
                    "{} as EmptyArray," +
                    "{1} as OneEleArray," +
                    "{1,2,3} as IntArray," +
                    "{1,null} as IntNullArray," +
                    "{1L,10L} as LongArray," +
                    "{'a',1, 1e20} as MixedArray," +
                    "{1, 1.1d, 1e20} as DoubleArray," +
                    "{5, 6L} as IntLongArray," +
                    "{null} as NullArray," +
                    "{true, false} as BoolArray" +
                    " from SupportBean";

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

                env.SendEventBean(new SupportBean());

                var theEvent = env.Listener("s0").AssertOneGetNewAndReset();

                SupportAvroUtil.AvroToJson(theEvent);

                CompareColl(theEvent, "StringArray", new[] { "a", "b" });
                CompareColl(theEvent, "EmptyArray", new object[0]);
                CompareColl(theEvent, "OneEleArray", new int?[] { 1 });
                CompareColl(theEvent, "IntArray", new int?[] { 1, 2, 3 });
                CompareColl(theEvent, "IntNullArray", new int?[] { 1, null });
                CompareColl(theEvent, "LongArray", new long?[] { 1L, 10L });
                CompareColl(theEvent, "MixedArray", new object[] { "a", 1, 1e20 });
                CompareColl(theEvent, "DoubleArray", new double?[] { 1d, 1.1, 1e20 });
                CompareColl(theEvent, "IntLongArray", new long?[] { 5L, 6L });
                CompareColl(theEvent, "NullArray", new object[] { null });
                CompareColl(theEvent, "BoolArray", new bool?[] { true, false });

                env.UndeployAll();
            }
Exemple #9
0
        private static void TryAssertionNewWRepresentation(
            RegressionEnvironment env,
            EventRepresentationChoice rep,
            AtomicLong milestone)
        {
            var epl = rep.GetAnnotationTextWJsonProvided <MyLocalJsonProvided>() +
                      "@Name('s0') select new { TheString = 'x' || TheString || 'x', IntPrimitive = IntPrimitive + 2} as val0 from SupportBean as sb";

            env.CompileDeploy(epl).AddListener("s0").Milestone(milestone.GetAndIncrement());

            Assert.AreEqual(
                rep.IsAvroEvent() ? typeof(GenericRecord) : typeof(IDictionary <string, object>),
                env.Statement("s0").EventType.GetPropertyType("val0"));
            var fragType = env.Statement("s0").EventType.GetFragmentType("val0");

            if (rep == EventRepresentationChoice.JSONCLASSPROVIDED)
            {
                Assert.IsNull(fragType);
            }
            else
            {
                Assert.IsFalse(fragType.IsIndexed);
                Assert.IsFalse(fragType.IsNative);
                Assert.AreEqual(typeof(string), fragType.FragmentType.GetPropertyType("TheString"));
                Assert.AreEqual(typeof(int?), Boxing.GetBoxedType(fragType.FragmentType.GetPropertyType("IntPrimitive")));
            }

            var fieldsInner = "TheString,IntPrimitive".SplitCsv();

            env.SendEventBean(new SupportBean("E1", -5));
            var @event = env.Listener("s0").AssertOneGetNewAndReset();

            if (rep.IsAvroEvent())
            {
                SupportAvroUtil.AvroToJson(@event);
                GenericRecord inner = (GenericRecord)@event.Get("val0");
                Assert.AreEqual("xE1x", inner.Get("TheString"));
                Assert.AreEqual(-3, inner.Get("IntPrimitive"));
            }
            else
            {
                EPAssertionUtil.AssertPropsMap((IDictionary <string, object>)@event.Get("val0"), fieldsInner, "xE1x", -3);
            }

            env.UndeployAll();
        }
Exemple #10
0
        public void TestSchemaFromClass()
        {
            var epl      = EventRepresentationChoice.AVRO.GetAnnotationText() + "insert into MyEvent select " + this.GetType().FullName + ".MakeDateTime() as isodate from SupportBean as e1";
            var stmt     = _epService.EPAdministrator.CreateEPL(epl);
            var listener = new SupportUpdateListener();

            stmt.AddListener(listener);

            Schema schema = SupportAvroUtil.GetAvroSchema(stmt.EventType);

            Assert.AreEqual("{\"type\":\"record\",\"name\":\"MyEvent\",\"fields\":[{\"name\":\"isodate\",\"type\":\"string\"}]}", schema.ToString());

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 10));
            var @event = listener.AssertOneGetNewAndReset();

            SupportAvroUtil.AvroToJson(@event);
            Assert.IsTrue(@event.Get("isodate").ToString().Length > 10);
        }
        /// <summary>Mapping of Type to GenericRecord</summary>
        private void RunAssertionPopulate(EPServiceProvider epService)
        {
            MySupportBeanWidener.supportBeanSchema = SchemaBuilder.Record("SupportBeanSchema",
                                                                          TypeBuilder.Field("TheString", "string"),
                                                                          TypeBuilder.Field("IntPrimitive", "int"));
            var schema = SchemaBuilder.Record("MyEventSchema",
                                              TypeBuilder.Field("sb", MySupportBeanWidener.supportBeanSchema));

            epService.EPAdministrator.Configuration.AddEventTypeAvro("MyEventPopulate", new ConfigurationEventTypeAvro(schema));

            string      epl      = "insert into MyEventPopulate(sb) select " + GetType().FullName + ".MakeSupportBean() from SupportBean_S0 as e1";
            EPStatement stmt     = epService.EPAdministrator.CreateEPL(epl);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean_S0(10));
            EventBean @event = listener.AssertOneGetNewAndReset();

            Assert.AreEqual("{\"sb\":{\"TheString\":\"E1\",\"IntPrimitive\":10}}", SupportAvroUtil.AvroToJson(@event));
        }
Exemple #12
0
            public void Run(RegressionEnvironment env)
            {
                var epl = "@Name('s0') " +
                          EventRepresentationChoice.AVRO.GetAnnotationText() +
                          "insert into MyEventOut select " +
                          typeof(EventAvroHook).FullName +
                          ".MakeDateTimeOffset() as isodate from SupportBean as e1";
                env.CompileDeploy(epl).AddListener("s0");

                var schema = SupportAvroUtil.GetAvroSchema(env.Statement("s0").EventType);
                Assert.AreEqual(
                    "{\"type\":\"record\",\"name\":\"MyEventOut\",\"fields\":[{\"name\":\"isodate\",\"type\":\"string\"}]}",
                    schema.ToString());

                env.SendEventBean(new SupportBean("E1", 10));
                var @event = env.Listener("s0").AssertOneGetNewAndReset();
                SupportAvroUtil.AvroToJson(@event);
                Assert.IsTrue(@event.Get("isodate").ToString().Length > 10);

                env.UndeployAll();
            }
Exemple #13
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                env.CompileDeploy("@Name('NamedWindow') create window MyWindow#keepall as MyEventWSchema", path);
                env.CompileDeploy("insert into MyWindow select * from MyEventWSchema", path);
                env.CompileDeploy("on SupportBean thebean update MyWindow set sb = thebean", path);

                var schema = AvroSchemaUtil
                    .ResolveAvroSchema(env.Runtime.EventTypeService.GetEventTypePreconfigured("MyEventWSchema"))
                    .AsRecordSchema();
                var @event = new GenericRecord(schema);
                env.SendEventAvro(@event, "MyEventWSchema");
                env.SendEventBean(new SupportBean("E1", 10));

                var eventBean = env.GetEnumerator("NamedWindow").Advance();
                Assert.AreEqual(
                    "{\"sb\":{\"SupportBeanSchema\":{\"TheString\":\"E1\",\"IntPrimitive\":10}}}",
                    SupportAvroUtil.AvroToJson(eventBean));

                env.UndeployAll();
            }
        /// <summary>Schema-from-Type</summary>
        private void RunAssertionSchemaFromClass(EPServiceProvider epService)
        {
            string epl = EventRepresentationChoice.AVRO.GetAnnotationText() +
                         "insert into MyEventOut select " + GetType().FullName +
                         ".MakeDateTime() as isodate from SupportBean as e1";
            EPStatement stmt     = epService.EPAdministrator.CreateEPL(epl);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            Schema schema = SupportAvroUtil.GetAvroSchema(stmt.EventType);

            Assert.AreEqual("{\"type\":\"record\",\"name\":\"MyEventOut\",\"fields\":[{\"name\":\"isodate\",\"type\":\"string\"}]}", schema.ToString());

            epService.EPRuntime.SendEvent(new SupportBean("E1", 10));
            EventBean @event = listener.AssertOneGetNewAndReset();

            SupportAvroUtil.AvroToJson(@event);
            Assert.IsTrue(@event.Get("isodate").ToString().Length > 10);

            stmt.Dispose();
        }
        private void RunAssertionNewSchema()
        {
            string epl = EventRepresentationChoice.AVRO.GetAnnotationText() + " select 1 as myInt," +
                         "{1L, 2L} as myLongArray," +
                         this.GetType().FullName + ".MakeByteArray() as myByteArray, " +
                         this.GetType().FullName + ".MakeMapStringString() as myMap " +
                         "from SupportBean";

            EPStatement           statement = _epService.EPAdministrator.CreateEPL(epl);
            SupportUpdateListener listener  = new SupportUpdateListener();

            statement.AddListener(listener);

            _epService.EPRuntime.SendEvent(new SupportBean());
            EventBean @event = listener.AssertOneGetNewAndReset();
            string    json   = SupportAvroUtil.AvroToJson(@event);

            Console.WriteLine(json);
            Assert.AreEqual(1, @event.Get("myInt"));
            EPAssertionUtil.AssertEqualsExactOrder(new long[] { 1L, 2L }, @event.Get("myLongArray").UnwrapIntoArray <long>());
            Assert.IsTrue(CompatExtensions.IsEqual(new byte[] { 1, 2, 3 }, ((byte[])@event.Get("myByteArray"))));
            Assert.AreEqual("[k1=v1]", CompatExtensions.Render(@event.Get("myMap").AsStringDictionary()));

            var designSchema = SchemaBuilder.Record("name",
                                                    TypeBuilder.RequiredInt("myInt"),
                                                    TypeBuilder.Field("myLongArray", TypeBuilder.Array(TypeBuilder.Union(TypeBuilder.Null(), TypeBuilder.Long()))),
                                                    TypeBuilder.Field("myByteArray", TypeBuilder.Bytes()),
                                                    TypeBuilder.Field("myMap", TypeBuilder.Map(
                                                                          TypeBuilder.String(TypeBuilder.Property(AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE)))));

            var assembledSchema = ((AvroEventType)@event.EventType).SchemaAvro;
            var compareMsg      = SupportAvroUtil.CompareSchemas(designSchema, assembledSchema);

            Assert.IsNull(compareMsg, compareMsg);

            statement.Dispose();
        }
        private void RunAssertionNewSchema(EPServiceProvider epService)
        {
            string epl = EventRepresentationChoice.AVRO.GetAnnotationText() + " select 1 as myInt," +
                         "{1L, 2L} as myLongArray," +
                         GetType().FullName + ".MakeByteArray() as myByteArray, " +
                         GetType().FullName + ".MakeMapStringString() as myMap " +
                         "from SupportBean";

            EPStatement statement = epService.EPAdministrator.CreateEPL(epl);
            var         listener  = new SupportUpdateListener();

            statement.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean());
            EventBean @event = listener.AssertOneGetNewAndReset();
            string    json   = SupportAvroUtil.AvroToJson(@event);

            Assert.AreEqual(1, @event.Get("myInt"));
            EPAssertionUtil.AssertEqualsExactOrder(new long[] { 1L, 2L }, @event.Get("myLongArray").UnwrapIntoArray <long>());
            Assert.IsTrue(Collections.AreEqual(new byte[] { 1, 2, 3 }, @event.Get("myByteArray").UnwrapIntoArray <byte>()));
            Assert.AreEqual("[k1=v1]", @event.Get("myMap").UnwrapStringDictionary().Render());

            var designSchema = SchemaBuilder.Record(
                "name",
                RequiredInt("myInt"),
                Field("myLongArray", Array(Union(NullType(), LongType()))),
                Field("myByteArray", BytesType()),
                Field("myMap", Map(StringType(Property(AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE))))
                );
            Schema assembledSchema = ((AvroEventType)@event.EventType).SchemaAvro;
            string compareMsg      = SupportAvroUtil.CompareSchemas(designSchema, assembledSchema);

            Assert.IsNull(compareMsg, compareMsg);

            statement.Dispose();
        }
Exemple #17
0
            public void Run(RegressionEnvironment env)
            {
                var insertInto = typeof(EPLInsertIntoPopulateCreateStreamAvro).FullName;
                var epl = "@Name('s0') " +
                          EventRepresentationChoice.AVRO.GetAnnotationText() +
                          " select 1 as myInt," +
                          "{1L, 2L} as myLongArray," +
                          $"{insertInto}.MakeByteArray() as myByteArray, " +
                          $"{insertInto}.MakeMapStringString() as myMap " +
                          "from SupportBean";
                env.CompileDeploy(epl).AddListener("s0");

                env.SendEventBean(new SupportBean());
                var @event = env.Listener("s0").AssertOneGetNewAndReset();
                var json = SupportAvroUtil.AvroToJson(@event);
                Console.Out.WriteLine(json);
                Assert.AreEqual(1, @event.Get("myInt"));
                EPAssertionUtil.AssertEqualsExactOrder(
                    new[] {1L, 2L},
                    @event.Get("myLongArray").UnwrapIntoArray<long>());
                CollectionAssert.AreEqual(new byte[] {1, 2, 3}, (byte[]) @event.Get("myByteArray"));
                Assert.AreEqual("{\"k1\"=\"v1\"}", @event.Get("myMap").RenderAny());

                var designSchema = SchemaBuilder.Record(
                    "name",
                    RequiredInt("myInt"),
                    Field("myLongArray", Array(LongType())),
                    Field("myByteArray", BytesType()),
                    Field("myMap", Map(StringType(Property(AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE)))));

                var assembledSchema = ((AvroEventType) @event.EventType).SchemaAvro;
                var compareMsg = SupportAvroUtil.CompareSchemas(designSchema, assembledSchema);
                Assert.IsNull(compareMsg, compareMsg);

                env.UndeployAll();
            }
        private void RunAssertionNamedWindowPropertyAssignment(EPServiceProvider epService)
        {
            MySupportBeanWidener.supportBeanSchema = SchemaBuilder.Record("SupportBeanSchema",
                                                                          TypeBuilder.Field("TheString", "string"),
                                                                          TypeBuilder.Field("IntPrimitive", "int"));
            var schema = SchemaBuilder.Record("MyEventSchema",
                                              TypeBuilder.Field((string)"sb", TypeBuilder.Union(
                                                                    TypeBuilder.NullType(), MySupportBeanWidener.supportBeanSchema)));

            epService.EPAdministrator.Configuration.AddEventTypeAvro("MyEventWSchema", new ConfigurationEventTypeAvro(schema));

            epService.EPAdministrator.CreateEPL("@Name('NamedWindow') create window MyWindow#keepall as MyEventWSchema");
            epService.EPAdministrator.CreateEPL("insert into MyWindow select * from MyEventWSchema");
            epService.EPAdministrator.CreateEPL("on SupportBean thebean update MyWindow set sb = thebean");

            GenericRecord @event = new GenericRecord(schema);

            epService.EPRuntime.SendEventAvro(@event, "MyEventWSchema");
            epService.EPRuntime.SendEvent(new SupportBean("E1", 10));

            EventBean eventBean = epService.EPAdministrator.GetStatement("NamedWindow").First();

            Assert.AreEqual("{\"sb\":{\"SupportBeanSchema\":{\"TheString\":\"E1\",\"IntPrimitive\":10}}}", SupportAvroUtil.AvroToJson(eventBean));
        }
Exemple #19
0
        public void TestNamedWindowPropertyAssignment()
        {
            MySupportBeanWidener.supportBeanSchema = SchemaBuilder.Record("SupportBeanSchema",
                                                                          TypeBuilder.Field("theString", "string"),
                                                                          TypeBuilder.Field("intPrimitive", "int"));

            //MySupportBeanWidener.supportBeanSchema = SchemaExtensions.Record("SupportBeanSchema")
            //    .Fields()
            //    .RequiredString("theString")
            //    .RequiredInt("intPrimitive").EndRecord();

            var schema = SchemaBuilder.Record("MyEventSchema",
                                              TypeBuilder.Field((string)"sb", TypeBuilder.Union(
                                                                    TypeBuilder.Null(), MySupportBeanWidener.supportBeanSchema)));

            //Schema schema = SchemaExtensions.Record("MyEventSchema")
            //    .Fields().Name("sb")
            //    .Type(Union().NullType().And().Type(MySupportBeanWidener.supportBeanSchema).EndUnion())
            //    .NoDefault()
            //    .EndRecord();

            _epService.EPAdministrator.Configuration.AddEventTypeAvro("MyEvent", new ConfigurationEventTypeAvro(schema));

            _epService.EPAdministrator.CreateEPL("@Name('NamedWindow') create window MyWindow#keepall as MyEvent");
            _epService.EPAdministrator.CreateEPL("insert into MyWindow select * from MyEvent");
            _epService.EPAdministrator.CreateEPL("on SupportBean thebean update MyWindow set sb = thebean");

            var @event = new GenericRecord(schema);

            _epService.EPRuntime.SendEventAvro(@event, "MyEvent");
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 10));

            EventBean eventBean = _epService.EPAdministrator.GetStatement("NamedWindow").First();

            Assert.AreEqual("{\"sb\":{\"SupportBeanSchema\":{\"theString\":\"E1\",\"intPrimitive\":10}}}", SupportAvroUtil.AvroToJson(eventBean));
        }