public void Run(RegressionEnvironment env) { var fields = "c0,c1,c2,c3,c4,c5".SplitCsv(); var builder = new SupportEvalBuilder("SupportCollection"); builder.WithExpression(fields[0], "Strvals.minBy(v => extractNum(v))"); builder.WithExpression(fields[1], "Strvals.maxBy(v => extractNum(v))"); builder.WithExpression(fields[2], "Strvals.minBy( (v, i) => extractNum(v) + i*10)"); builder.WithExpression(fields[3], "Strvals.maxBy( (v, i) => extractNum(v) + i*10)"); builder.WithExpression(fields[4], "Strvals.minBy( (v, i, s) => extractNum(v) + (case when s > 2 then i*10 else 0 end))"); builder.WithExpression(fields[5], "Strvals.maxBy( (v, i, s) => extractNum(v) + (case when s > 2 then i*10 else 0 end))"); builder.WithStatementConsumer(stmt => AssertTypesAllSame(stmt.EventType, fields, typeof(String))); builder.WithAssertion(SupportCollection.MakeString("E2,E1,E5,E4")).Expect(fields, "E1", "E5", "E2", "E4", "E2", "E4"); builder.WithAssertion(SupportCollection.MakeString("E1")).Expect(fields, "E1", "E1", "E1", "E1", "E1", "E1"); builder.WithAssertion(SupportCollection.MakeString(null)).Expect(fields, null, null, null, null, null, null); builder.WithAssertion(SupportCollection.MakeString("")).Expect(fields, null, null, null, null, null, null); builder.WithAssertion(SupportCollection.MakeString("E8,E2")).Expect(fields, "E2", "E8", "E8", "E2", "E2", "E8"); builder.Run(env); }
public void TestAllOfAnyOfScalar() { String[] fields = "val0,val1".Split(','); String eplFragment = "select " + "Strvals.allof(x => x='E2') as val0," + "Strvals.anyof(x => x='E2') as val1 " + "from SupportCollection"; EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment); stmtFragment.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, fields, new Type[] { typeof(bool), typeof(bool) }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,E3")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { false, true }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString(null)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null, null }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E2")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, true }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { false, false }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, false }); }
private static void SendAssert( RegressionEnvironment env, string expected, string csv) { env.SendEventBean(SupportCollection.MakeString(csv)); EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), "c0".SplitCsv(), new object[] { expected }); }
public void TestSumOfScalar() { String[] fields = "val0,val1".Split(','); String eplFragment = "select " + "Intvals.sumOf() as val0, " + "Bdvals.sumOf() as val1 " + "from SupportCollection"; EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment); stmtFragment.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, fields, new Type[] { typeof(int?), typeof(decimal?) }); _epService.EPRuntime.SendEvent(SupportCollection.MakeNumeric("1,4,5")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 1 + 4 + 5, 1m + 4m + 5m }); _epService.EPRuntime.SendEvent(SupportCollection.MakeNumeric("3,4")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 3 + 4, 3m + 4m }); _epService.EPRuntime.SendEvent(SupportCollection.MakeNumeric("3")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 3, 3m }); _epService.EPRuntime.SendEvent(SupportCollection.MakeNumeric("")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null, null }); _epService.EPRuntime.SendEvent(SupportCollection.MakeNumeric(null)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null, null }); stmtFragment.Dispose(); // test average with lambda _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractNum", typeof(TestEnumMinMax.MyService).FullName, "ExtractNum"); _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractDecimal", typeof(TestEnumMinMax.MyService).FullName, "ExtractDecimal"); // lambda with string-array input String[] fieldsLambda = "val0,val1".SplitCsv(); String eplLambda = "select " + "Strvals.sumOf(v => extractNum(v)) as val0, " + "Strvals.sumOf(v => extractDecimal(v)) as val1 " + "from SupportCollection"; EPStatement stmtLambda = _epService.EPAdministrator.CreateEPL(eplLambda); stmtLambda.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtLambda.EventType, fieldsLambda, new [] { typeof(int?), typeof(decimal?) }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E5,E4")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsLambda, new Object[] { 2 + 1 + 5 + 4, new decimal(2 + 1 + 5 + 4) }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsLambda, new Object[] { 1, new decimal(1) }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString(null)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsLambda, new Object[] { null, null }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsLambda, new Object[] { null, null }); }
private void RunAssertionKeySelectorOnly(EPServiceProvider epService) { // - duplicate key allowed, creates a list of values // - null key & value allowed var eplFragment = "select Contained.GroupBy(c => id) as val from Bean"; var stmtFragment = epService.EPAdministrator.CreateEPL(eplFragment); var listener = new SupportUpdateListener(); stmtFragment.Events += listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, "val".Split(','), new[] { typeof(IDictionary<object, ICollection<object>>) }); var extractorEvents = new EPAssertionUtil.ProxyAssertionCollectionValueString { ProcExtractValue = collectionItem => { var p00 = ((SupportBean_ST0) collectionItem).P00; return Convert.ToString(p00); } }; epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value("E1,1", "E1,2", "E2,5")); EPAssertionUtil.AssertMapOfCollection( (IDictionary<object, ICollection<object>>) listener.AssertOneGetNewAndReset().Get("val"), "E1,E2".Split(','), new[] {"1,2", "5"}, extractorEvents); epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value(null)); Assert.IsNull(listener.AssertOneGetNewAndReset().Get("val")); epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value()); Assert.AreEqual(0, listener.AssertOneGetNewAndReset().Get("val").UnwrapEnumerable<object>().Count()); stmtFragment.Dispose(); // test scalar var eplScalar = "select Strvals.GroupBy(c => extractAfterUnderscore(c)) as val from SupportCollection"; var stmtScalar = epService.EPAdministrator.CreateEPL(eplScalar); stmtScalar.Events += listener.Update; LambdaAssertionUtil.AssertTypes(stmtScalar.EventType, "val".Split(','), new[] { typeof(IDictionary<object, ICollection<object>>) }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1_2,E2_1,E3_2")); EPAssertionUtil.AssertMapOfCollection( listener.AssertOneGetNewAndReset().Get("val").UnwrapStringDictionary(), "2,1".Split(','), new[] {"E1_2,E3_2", "E2_1"}, GetExtractorScalar()); epService.EPRuntime.SendEvent(SupportCollection.MakeString(null)); Assert.IsNull(listener.AssertOneGetNewAndReset().Get("val")); epService.EPRuntime.SendEvent(SupportCollection.MakeString("")); Assert.AreEqual(0, listener.AssertOneGetNewAndReset().Get("val").Unwrap<object>().Count); stmtScalar.Dispose(); }
private void RunAssertionTwoProperties(EPServiceProvider epService) { string[] fields = "val0".Split(','); string eplFragment = "select " + "Strvals.sequenceEqual(strvalstwo) as val0 " + "from SupportCollection"; EPStatement stmtFragment = epService.EPAdministrator.CreateEPL(eplFragment); var listener = new SupportUpdateListener(); stmtFragment.Events += listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, "val0".Split(','), new Type[] { typeof(bool) }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,E3", "E1,E2,E3")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { true }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E3", "E1,E2,E3")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { false }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E3", "E1,E3")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { true }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,E3", "E1,E3")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { false }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,null,E3", "E1,E2,null,E3")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { true }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,E3", "E1,E2,null")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { false }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,null", "E1,E2,E3")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { false }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1", "")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { false }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("", "E1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { false }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1", "E1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { true }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("", "")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { true }); epService.EPRuntime.SendEvent(SupportCollection.MakeString(null, "")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("", null)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { false }); epService.EPRuntime.SendEvent(SupportCollection.MakeString(null, null)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null }); stmtFragment.Dispose(); }
private void RunAssertionSelect(EPServiceProvider epService) { string eplFragment = "select " + "Contained.selectFrom(x => id) as val0 " + "from Bean"; EPStatement stmtFragment = epService.EPAdministrator.CreateEPL(eplFragment); var listener = new SupportUpdateListener(); stmtFragment.Events += listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, "val0".Split(','), new Type[] { typeof(ICollection <string>) }); epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value("E1,12", "E2,11", "E3,2")); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", "E1", "E2", "E3"); listener.Reset(); epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value(null)); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", null); listener.Reset(); epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value()); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", new string[0]); listener.Reset(); stmtFragment.Dispose(); // test scalar-coll with lambda string[] fields = "val0".Split(','); epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractNum", typeof(ExecEnumMinMax.MyService), "ExtractNum"); string eplLambda = "select " + "Strvals.selectFrom(v => extractNum(v)) as val0 " + "from SupportCollection"; EPStatement stmtLambda = epService.EPAdministrator.CreateEPL(eplLambda); stmtLambda.Events += listener.Update; LambdaAssertionUtil.AssertTypes(stmtLambda.EventType, fields, new Type[] { typeof(ICollection <int>), typeof(ICollection <int>) }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E5,E4")); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", 2, 1, 5, 4); listener.Reset(); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1")); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", 1); listener.Reset(); epService.EPRuntime.SendEvent(SupportCollection.MakeString(null)); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", null); listener.Reset(); epService.EPRuntime.SendEvent(SupportCollection.MakeString("")); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0"); stmtLambda.Dispose(); }
private void SendAssert( RegressionEnvironment env, string[] fields, double?c0, double?c1, double?c2, string csv) { env.SendEventBean(SupportCollection.MakeString(csv)); EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), fields, new object[] { c0, c1, c2 }); }
public override void Run(EPServiceProvider epService) { // - duplicate value allowed, latest value wins // - null key & value allowed string eplFragment = "select Contained.ToMap(c => id, c=> p00) as val from Bean"; EPStatement stmtFragment = epService.EPAdministrator.CreateEPL(eplFragment); var listener = new SupportUpdateListener(); stmtFragment.Events += listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, "val".Split(','), new Type[] { typeof(IDictionary <object, object>) }); epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value("E1,1", "E3,12", "E2,5")); EPAssertionUtil.AssertPropsMap(listener.AssertOneGetNewAndReset().Get("val").UnwrapStringDictionary(), "E1,E2,E3".Split(','), new object[] { 1, 5, 12 }); epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value("E1,1", "E3,12", "E2,12", "E1,2")); EPAssertionUtil.AssertPropsMap(listener.AssertOneGetNewAndReset().Get("val").UnwrapStringDictionary(), "E1,E2,E3".Split(','), new object[] { 2, 12, 12 }); epService.EPRuntime.SendEvent(new SupportBean_ST0_Container(Collections.SingletonList(new SupportBean_ST0(null, null)))); EPAssertionUtil.AssertPropsMap(listener.AssertOneGetNewAndReset().Get("val").UnwrapStringDictionary(), "E1,E2,E3".Split(','), new object[] { null, null, null }); stmtFragment.Dispose(); // test scalar-coll with lambda string[] fields = "val0".Split(','); epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractNum", typeof(ExecEnumMinMax.MyService), "ExtractNum"); string eplLambda = "select " + "Strvals.ToMap(c => c, c => extractNum(c)) as val0 " + "from SupportCollection"; EPStatement stmtLambda = epService.EPAdministrator.CreateEPL(eplLambda); stmtLambda.Events += listener.Update; LambdaAssertionUtil.AssertTypes(stmtLambda.EventType, fields, new Type[] { typeof(IDictionary <object, object>) }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E3")); EPAssertionUtil.AssertPropsMap( listener.AssertOneGetNewAndReset().Get("val0").UnwrapDictionary(), "E1,E2,E3".Split(','), new object[] { 1, 2, 3 }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1")); EPAssertionUtil.AssertPropsMap( listener.AssertOneGetNewAndReset().Get("val0").UnwrapDictionary(), "E1".Split(','), new object[] { 1 }); epService.EPRuntime.SendEvent(SupportCollection.MakeString(null)); Assert.IsNull(listener.AssertOneGetNewAndReset().Get("val0")); epService.EPRuntime.SendEvent(SupportCollection.MakeString("")); Assert.AreEqual(0, listener.AssertOneGetNewAndReset().Get("val0").Unwrap <object>().Count); }
public void TestTwoProperties() { String[] fields = "val0".Split(','); String eplFragment = "select " + "Strvals.sequenceEqual(strvalstwo) as val0 " + "from SupportCollection"; EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment); stmtFragment.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, "val0".Split(','), new Type[] { typeof(bool) }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,E3", "E1,E2,E3")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E3", "E1,E2,E3")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { false }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E3", "E1,E3")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,E3", "E1,E3")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { false }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,null,E3", "E1,E2,null,E3")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,E3", "E1,E2,null")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { false }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,null", "E1,E2,E3")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { false }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1", "")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { false }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("", "E1")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { false }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1", "E1")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("", "")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString(null, "")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("", null)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { false }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString(null, null)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null }); }
private void RunAssertionScalarReturn(string epl) { var stmt = _epService.EPAdministrator.CreateEPL(epl); stmt.AddListener(_listener); LambdaAssertionUtil.AssertTypes(stmt.EventType, "val1".Split(','), new Type[] { typeof(ICollection <object>) }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,E3,E4")); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val1", "E3", "E4"); _listener.Reset(); _epService.EPAdministrator.DestroyAllStatements(); }
public void Run(RegressionEnvironment env) { var path = new RegressionPath(); env.CompileDeploy("create expression string js:myscript(p1) [return \"--\"+p1+\"--\"]", path); env.CompileDeploy("create expression myexpr {sb => '--'||TheString||'--'}", path); // test mapped property syntax var eplMapped = "@Name('s0') select myscript('x') as c0, myexpr(sb) as c1 from SupportBean as sb"; env.CompileDeploy(eplMapped, path).AddListener("s0"); env.SendEventBean(new SupportBean("E1", 1)); EPAssertionUtil.AssertProps( env.Listener("s0").AssertOneGetNewAndReset(), new[] {"c0", "c1"}, new object[] {"--x--", "--E1--"}); env.UndeployModuleContaining("s0"); // test expression chained syntax var eplExpr = "" + "create expression scalarfilter {s => " + " Strvals.where(y => y != 'E1') " + "}"; env.CompileDeploy(eplExpr, path); var eplSelect = "@Name('s0') select scalarfilter(t).where(x => x != 'E2') as val1 from SupportCollection as t"; env.CompileDeploy(eplSelect, path).AddListener("s0"); AssertStatelessStmt(env, "s0", true); env.SendEventBean(SupportCollection.MakeString("E1,E2,E3,E4")); LambdaAssertionUtil.AssertValuesArrayScalar(env.Listener("s0"), "val1", "E3", "E4"); env.UndeployAll(); // test script chained syntax var supportBean = typeof(SupportBean).FullName; var eplScript = $"create expression {typeof(SupportBean).MaskTypeName()} " + "js:callIt() [ " + $" return host.newObj(host.resolveType('{supportBean}'), 'E1', 10); " + "]"; env.CompileDeploy(eplScript, path); env.CompileDeploy( "@Name('s0') select callIt() as val0, callIt().GetTheString() as val1 from SupportBean as sb", path) .AddListener("s0"); env.SendEventBean(new SupportBean()); EPAssertionUtil.AssertProps( env.Listener("s0").AssertOneGetNewAndReset(), new[] {"val0.TheString", "val0.IntPrimitive", "val1"}, new object[] {"E1", 10, "E1"}); env.UndeployAll(); }
private void RunAssertionAverageScalar(EPServiceProvider epService) { var fields = "val0,val1".Split(','); var eplFragment = "select " + "Intvals.average() as val0," + "Bdvals.average() as val1 " + "from SupportCollection"; var stmtFragment = epService.EPAdministrator.CreateEPL(eplFragment); var listener = new SupportUpdateListener(); stmtFragment.Events += listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, fields, new Type[] { typeof(double?), typeof(decimal?) }); epService.EPRuntime.SendEvent(SupportCollection.MakeNumeric("1,2,3")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 2d, 2m }); epService.EPRuntime.SendEvent(SupportCollection.MakeNumeric("1,null,3")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 2d, 2m }); epService.EPRuntime.SendEvent(SupportCollection.MakeNumeric("4")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 4d, 4m }); stmtFragment.Dispose(); // test average with lambda epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractNum", typeof(ExecEnumMinMax.MyService), "ExtractNum"); epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractDecimal", typeof(ExecEnumMinMax.MyService), "ExtractDecimal"); var fieldsLambda = "val0,val1".Split(','); var eplLambda = "select " + "Strvals.average(v => extractNum(v)) as val0, " + "Strvals.average(v => extractDecimal(v)) as val1 " + "from SupportCollection"; var stmtLambda = epService.EPAdministrator.CreateEPL(eplLambda); stmtLambda.Events += listener.Update; LambdaAssertionUtil.AssertTypes(stmtLambda.EventType, fieldsLambda, new Type[] { typeof(double?), typeof(decimal?) }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E5,E4")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fieldsLambda, new object[] { (2 + 1 + 5 + 4) / 4d, (decimal)((2 + 1 + 5 + 4) / 4d) }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fieldsLambda, new object[] { 1d, 1m }); epService.EPRuntime.SendEvent(SupportCollection.MakeString(null)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fieldsLambda, new object[] { null, null }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fieldsLambda, new object[] { null, null }); stmtLambda.Dispose(); }
public void TestSelect() { String eplFragment = "select " + "contained.selectFrom(x => id) as val0 " + "from Bean"; EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment); stmtFragment.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, "val0".Split(','), new Type[] { typeof(ICollection <object>) }); _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value("E1,12", "E2,11", "E3,2")); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", "E1", "E2", "E3"); _listener.Reset(); _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value(null)); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", null); _listener.Reset(); _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value()); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", new String[0]); _listener.Reset(); stmtFragment.Dispose(); // test scalar-coll with lambda String[] fields = "val0".SplitCsv(); _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractNum", typeof(TestEnumMinMax.MyService).FullName, "ExtractNum"); String eplLambda = "select " + "Strvals.selectFrom(v => extractNum(v)) as val0 " + "from SupportCollection"; EPStatement stmtLambda = _epService.EPAdministrator.CreateEPL(eplLambda); stmtLambda.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtLambda.EventType, fields, new [] { typeof(ICollection <object>), typeof(ICollection <object>) }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E5,E4")); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", 2, 1, 5, 4); _listener.Reset(); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1")); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", 1); _listener.Reset(); _epService.EPRuntime.SendEvent(SupportCollection.MakeString(null)); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", null); _listener.Reset(); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("")); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0"); }
public void TestKeySelectorOnly() { // - duplicate key allowed, creates a list of values // - null key & value allowed String eplFragment = "select contained.GroupBy(c => id) as val from Bean"; EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment); stmtFragment.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, "val".Split(','), new Type[] { typeof(GroupMap) }); EPAssertionUtil.AssertionCollectionValueString extractorEvents = new EPAssertionUtil.ProxyAssertionCollectionValueString( collectionItem => { int p00 = ((SupportBean_ST0)collectionItem).P00; return(Convert.ToString(p00)); }); _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value("E1,1", "E1,2", "E2,5")); EPAssertionUtil.AssertMapOfCollection( (GroupMap)_listener.AssertOneGetNewAndReset().Get("val"), new string[] { "E1", "E2" }, new string[] { "1,2", "5" }, extractorEvents); _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value(null)); Assert.IsNull(_listener.AssertOneGetNewAndReset().Get("val")); _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value()); Assert.AreEqual(0, ((GroupMap)_listener.AssertOneGetNewAndReset().Get("val")).Count); stmtFragment.Dispose(); // test scalar _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractAfterUnderscore", this.GetType().FullName, "ExtractAfterUnderscore"); String eplScalar = "select Strvals.GroupBy(c => extractAfterUnderscore(c)) as val from SupportCollection"; EPStatement stmtScalar = _epService.EPAdministrator.CreateEPL(eplScalar); stmtScalar.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtScalar.EventType, "val".Split(','), new Type[] { typeof(GroupMap) }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1_2,E2_1,E3_2")); EPAssertionUtil.AssertMapOfCollection((GroupMap)_listener.AssertOneGetNewAndReset().Get("val"), "2,1".Split(','), new String[] { "E1_2,E3_2", "E2_1" }, GetExtractorScalar()); _epService.EPRuntime.SendEvent(SupportCollection.MakeString(null)); Assert.IsNull(_listener.AssertOneGetNewAndReset().Get("val")); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("")); Assert.AreEqual(0, ((GroupMap)_listener.AssertOneGetNewAndReset().Get("val")).Count); }
private void RunAssertionScalar(EPServiceProvider epService) { string[] fields = "val0,val1".Split(','); string eplFragment = "select " + "Strvals.mostFrequent() as val0, " + "Strvals.leastFrequent() as val1 " + "from SupportCollection"; EPStatement stmtFragment = epService.EPAdministrator.CreateEPL(eplFragment); var listener = new SupportUpdateListener(); stmtFragment.Events += listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, fields, new Type[] { typeof(string), typeof(string) }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E2,E1,E3,E3,E4,E3")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E3", "E4" }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E1", "E1" }); epService.EPRuntime.SendEvent(SupportCollection.MakeString(null)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null }); stmtFragment.Dispose(); epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractNum", typeof(ExecEnumMinMax.MyService), "ExtractNum"); string eplLambda = "select " + "Strvals.mostFrequent(v => extractNum(v)) as val0, " + "Strvals.leastFrequent(v => extractNum(v)) as val1 " + "from SupportCollection"; EPStatement stmtLambda = epService.EPAdministrator.CreateEPL(eplLambda); stmtLambda.Events += listener.Update; LambdaAssertionUtil.AssertTypes(stmtLambda.EventType, fields, new Type[] { typeof(int?), typeof(int?) }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E2,E1,E3,E3,E4,E3")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 3, 4 }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 1, 1 }); epService.EPRuntime.SendEvent(SupportCollection.MakeString(null)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null }); }
public void TestScalar() { String[] fields = "val0,val1".Split(','); String eplFragment = "select " + "Strvals.MostFrequent() as val0, " + "Strvals.LeastFrequent() as val1 " + "from SupportCollection"; EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment); stmtFragment.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, fields, new Type[] { typeof(string), typeof(string) }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E2,E1,E3,E3,E4,E3")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "E3", "E4" }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "E1", "E1" }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString(null)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null, null }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null, null }); stmtFragment.Dispose(); _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractNum", typeof(TestEnumMinMax.MyService).FullName, "ExtractNum"); String eplLambda = "select " + "Strvals.mostFrequent(v => extractNum(v)) as val0, " + "Strvals.leastFrequent(v => extractNum(v)) as val1 " + "from SupportCollection"; EPStatement stmtLambda = _epService.EPAdministrator.CreateEPL(eplLambda); stmtLambda.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtLambda.EventType, fields, new [] { typeof(int?), typeof(int?) }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E2,E1,E3,E3,E4,E3")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 3, 4 }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 1, 1 }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString(null)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null, null }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null, null }); }
private void RunAssertionWhereString(EPServiceProvider epService) { string[] fields = "val0,val1".Split(','); string eplFragment = "select " + "Strvals.where(x => x not like '%1%') as val0, " + "Strvals.where((x, i) => x not like '%1%' and i > 1) as val1 " + "from SupportCollection"; EPStatement stmtFragment = epService.EPAdministrator.CreateEPL(eplFragment); var listener = new SupportUpdateListener(); stmtFragment.Events += listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, fields, new Type[] { typeof(ICollection <string>), typeof(ICollection <string>) }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,E3")); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", "E2", "E3"); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val1", "E3"); listener.Reset(); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E4,E2,E1")); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", "E4", "E2"); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val1", new string[0]); listener.Reset(); epService.EPRuntime.SendEvent(SupportCollection.MakeString("")); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", new string[0]); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val1", new string[0]); listener.Reset(); stmtFragment.Dispose(); // test boolean eplFragment = "select " + "Boolvals.where(x => x) as val0 " + "from SupportCollection"; stmtFragment = epService.EPAdministrator.CreateEPL(eplFragment); stmtFragment.Events += listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, "val0".Split(','), new Type[] { typeof(ICollection <bool?>) }); epService.EPRuntime.SendEvent(SupportCollection.MakeBoolean("true,true,false")); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", true, true); listener.Reset(); stmtFragment.Dispose(); }
public void Run(RegressionEnvironment env) { string[] fields = "c0".SplitCsv(); SupportEvalBuilder builder = new SupportEvalBuilder("SupportCollection"); builder.WithExpression(fields[0], "Strvals.reverse()"); builder.WithStatementConsumer(stmt => AssertTypesAllSame(stmt.EventType, fields, typeof(ICollection <object>))); builder.WithAssertion(SupportCollection.MakeString("E2,E1,E5,E4")) .Verify("c0", val => AssertValuesArrayScalar(val, "E4", "E5", "E1", "E2")); LambdaAssertionUtil.AssertSingleAndEmptySupportColl(builder, fields); builder.Run(env); }
private void RunAssertionOrderByScalar(EPServiceProvider epService) { string[] fields = "val0,val1".Split(','); string eplFragment = "select " + "Strvals.orderBy() as val0, " + "Strvals.OrderByDesc() as val1 " + "from SupportCollection"; EPStatement stmtFragment = epService.EPAdministrator.CreateEPL(eplFragment); var listener = new SupportUpdateListener(); stmtFragment.Events += listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, fields, new Type[] { typeof(ICollection <string>), typeof(ICollection <string>) }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E5,E4")); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", "E1", "E2", "E4", "E5"); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val1", "E5", "E4", "E2", "E1"); listener.Reset(); LambdaAssertionUtil.AssertSingleAndEmptySupportColl(epService, listener, fields); stmtFragment.Dispose(); // test scalar-coll with lambda epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractNum", typeof(ExecEnumMinMax.MyService), "ExtractNum"); string eplLambda = "select " + "Strvals.orderBy(v => extractNum(v)) as val0, " + "Strvals.OrderByDesc(v => extractNum(v)) as val1 " + "from SupportCollection"; EPStatement stmtLambda = epService.EPAdministrator.CreateEPL(eplLambda); stmtLambda.Events += listener.Update; LambdaAssertionUtil.AssertTypes(stmtLambda.EventType, fields, new Type[] { typeof(ICollection <string>), typeof(ICollection <string>) }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E5,E4")); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", "E1", "E2", "E4", "E5"); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val1", "E5", "E4", "E2", "E1"); listener.Reset(); LambdaAssertionUtil.AssertSingleAndEmptySupportColl(epService, listener, fields); stmtLambda.Dispose(); }
public void TestSetLogicWithScalar() { String epl = "select " + "Strvals.except(Strvalstwo) as val0," + "Strvals.intersect(Strvalstwo) as val1, " + "Strvals.union(Strvalstwo) as val2 " + " from SupportCollection as bean"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(epl); stmt.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmt.EventType, "val0".Split(','), new Type[] { typeof(ICollection <string>) } ); _epService.EPRuntime.SendEvent( SupportCollection.MakeString("E1,E2", "E3,E4")); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", "E1", "E2"); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val1"); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val2", "E1", "E2", "E3", "E4"); _listener.Reset(); _epService.EPRuntime.SendEvent( SupportCollection.MakeString(null, "E3,E4")); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", null); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val1", null); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val2", null); _listener.Reset(); _epService.EPRuntime.SendEvent( SupportCollection.MakeString("", "E3,E4")); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0"); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val1"); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val2", "E3", "E4"); _listener.Reset(); _epService.EPRuntime.SendEvent( SupportCollection.MakeString("E1,E3,E5", "E3,E4")); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", "E1", "E5"); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val1", "E3"); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val2", "E1", "E3", "E5", "E3", "E4"); _listener.Reset(); }
public void TestReverseScalar() { String[] fields = "val0".Split(','); String eplFragment = "select " + "Strvals.reverse() as val0 " + "from SupportCollection"; EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment); stmtFragment.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, fields, new Type[] { typeof(ICollection <string>) }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E5,E4")); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", "E4", "E5", "E1", "E2"); _listener.Reset(); LambdaAssertionUtil.AssertSingleAndEmptySupportColl(_epService, _listener, fields); }
public void Run(RegressionEnvironment env) { var fields = "c0,c1,c2,c3".SplitCsv(); var builder = new SupportEvalBuilder("SupportCollection"); builder.WithExpression(fields[0], "Strvals.sumOf(v => extractNum(v))"); builder.WithExpression(fields[1], "Strvals.sumOf(v => extractDecimal(v))"); builder.WithExpression(fields[2], "Strvals.sumOf( (v, i) => extractNum(v) + i*10)"); builder.WithExpression(fields[3], "Strvals.sumOf( (v, i, s) => extractNum(v) + i*10 + s*100)"); builder.WithStatementConsumer( stmt => AssertTypes(env.Statement("s0").EventType, fields, new[] { typeof(int?), typeof(decimal?), typeof(int?), typeof(int?) })); builder.WithAssertion(SupportCollection.MakeString("E2,E1,E5,E4")) .Expect(fields, 2 + 1 + 5 + 4, 2m + 1m + 5m + 4m, 2 + 11 + 25 + 34, 402 + 411 + 425 + 434); builder.WithAssertion(SupportCollection.MakeString("E1")).Expect(fields, 1, 1m, 1, 101); builder.WithAssertion(SupportCollection.MakeString(null)).Expect(fields, null, null, null, null); builder.WithAssertion(SupportCollection.MakeString("")).Expect(fields, null, null, null, null); builder.Run(env); }
public void TestCountOfScalar() { var fields = new[] { "val0", "val1" }; const string eplFragment = "select " + "Strvals.countof() as val0, " + "Strvals.countof(x => x = 'E1') as val1 " + " from SupportCollection"; EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment); stmtFragment.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, fields, new Type[] { typeof(int), typeof(int) }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 2, 1 }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,E1,E3")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 4, 2 }); }
private void RunAssertionParseSpecialAndMixedExprAndScript(EPServiceProvider epService) { var listener = new SupportUpdateListener(); epService.EPAdministrator.CreateEPL("create expression string jscript:myscript(p1) [return \"--\"+p1+\"--\";]"); epService.EPAdministrator.CreateEPL("create expression myexpr {sb => '--'||TheString||'--'}"); // test mapped property syntax string eplMapped = "select myscript('x') as c0, myexpr(sb) as c1 from SupportBean as sb"; EPStatement stmtMapped = epService.EPAdministrator.CreateEPL(eplMapped); stmtMapped.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), "c0,c1".Split(','), new object[] { "--x--", "--E1--" }); stmtMapped.Dispose(); // test expression chained syntax string eplExpr = "" + "create expression scalarfilter {s => " + " Strvals.where(y => y != 'E1') " + "}"; epService.EPAdministrator.CreateEPL(eplExpr); string eplSelect = "select scalarfilter(t).where(x => x != 'E2') as val1 from SupportCollection as t"; epService.EPAdministrator.CreateEPL(eplSelect).Events += listener.Update; epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,E3,E4")); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val1", "E3", "E4"); epService.EPAdministrator.DestroyAllStatements(); listener.Reset(); // test script chained syntax var beanType = typeof(SupportBean).FullName; var eplScript = $"create expression {beanType} jscript:callIt() [ return host.newObj(host.resolveType('{beanType}'), 'E1', 10); ]"; epService.EPAdministrator.CreateEPL(eplScript); epService.EPAdministrator.CreateEPL("select callIt() as val0, callIt().get_TheString() as val1 from SupportBean as sb").Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean()); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), "val0.TheString,val0.IntPrimitive,val1".Split(','), new object[] { "E1", 10, "E1" }); epService.EPAdministrator.DestroyAllStatements(); }
public void TestOrderByScalar() { String[] fields = "val0,val1".Split(','); String eplFragment = "select " + "Strvals.orderBy() as val0, " + "Strvals.OrderByDesc() as val1 " + "from SupportCollection"; EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment); stmtFragment.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, fields, new Type[] { typeof(ICollection <string>), typeof(ICollection <string>) }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E5,E4")); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", "E1", "E2", "E4", "E5"); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val1", "E5", "E4", "E2", "E1"); _listener.Reset(); LambdaAssertionUtil.AssertSingleAndEmptySupportColl(_epService, _listener, fields); stmtFragment.Dispose(); // test scalar-coll with lambda _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractNum", typeof(TestEnumMinMax.MyService).FullName, "ExtractNum"); String eplLambda = "select " + "Strvals.orderBy(v => extractNum(v)) as val0, " + "Strvals.orderByDesc(v => extractNum(v)) as val1 " + "from SupportCollection"; EPStatement stmtLambda = _epService.EPAdministrator.CreateEPL(eplLambda); stmtLambda.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtLambda.EventType, fields, new [] { typeof(ICollection <string>), typeof(ICollection <string>) }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E5,E4")); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val0", "E1", "E2", "E4", "E5"); LambdaAssertionUtil.AssertValuesArrayScalar(_listener, "val1", "E5", "E4", "E2", "E1"); _listener.Reset(); LambdaAssertionUtil.AssertSingleAndEmptySupportColl(_epService, _listener, fields); }
public void TestToMap() { // - duplicate value allowed, latest value wins // - null key & value allowed String eplFragment = "select contained.toMap(c => id, c=> p00) as val from Bean"; EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment); stmtFragment.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, "val".Split(','), new Type[] { typeof(AnyMap) }); _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value("E1,1", "E3,12", "E2,5")); ArrayAssertionUtil.AssertPropsMap(ToDataMap(_listener.AssertOneGetNewAndReset().Get("val")), "E1,E2,E3".Split(','), new Object[] { 1, 5, 12 }); _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value("E1,1", "E3,12", "E2,12", "E1,2")); ArrayAssertionUtil.AssertPropsMap(ToDataMap(_listener.AssertOneGetNewAndReset().Get("val")), "E1,E2,E3".Split(','), new Object[] { 2, 12, 12 }); _epService.EPRuntime.SendEvent(new SupportBean_ST0_Container(new SupportBean_ST0[] { new SupportBean_ST0(null, null) })); ArrayAssertionUtil.AssertPropsMap(ToDataMap(_listener.AssertOneGetNewAndReset().Get("val")), "E1,E2,E3".Split(','), new Object[] { null, null, null }); stmtFragment.Dispose(); // test scalar-coll with lambda String[] fields = "val0".SplitCsv(); _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractNum", typeof(TestEnumMinMax.MyService).FullName, "ExtractNum"); String eplLambda = "select Strvals.toMap(c => c, c => extractNum(c)) as val0 from SupportCollection"; EPStatement stmtLambda = _epService.EPAdministrator.CreateEPL(eplLambda); stmtLambda.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtLambda.EventType, fields, new [] { typeof(AnyMap) }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E3")); EPAssertionUtil.AssertPropsMap((AnyMap)_listener.AssertOneGetNewAndReset().Get("val0"), "E1,E2,E3".SplitCsv(), new Object[] { 1, 2, 3 }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1")); EPAssertionUtil.AssertPropsMap((AnyMap)_listener.AssertOneGetNewAndReset().Get("val0"), "E1".SplitCsv(), new Object[] { 1 }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString(null)); Assert.IsNull(_listener.AssertOneGetNewAndReset().Get("val0")); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("")); Assert.AreEqual(0, ((AnyMap)_listener.AssertOneGetNewAndReset().Get("val0")).Count); }
public static void AssertSingleAndEmptySupportColl( SupportEvalBuilder builder, string[] fields) { var assertionOne = builder.WithAssertion(SupportCollection.MakeString("E1")); foreach (var field in fields) { assertionOne.Verify(field, value => LambdaAssertionUtil.AssertValuesArrayScalar(value, "E1")); } var assertionTwo = builder.WithAssertion(SupportCollection.MakeString(null)); foreach (var field in fields) { assertionTwo.Verify(field, value => LambdaAssertionUtil.AssertValuesArrayScalar(value, null)); } var assertionThree = builder.WithAssertion(SupportCollection.MakeString("")); foreach (var field in fields) { assertionThree.Verify(field, value => LambdaAssertionUtil.AssertValuesArrayScalar(value)); } }
public void Run(RegressionEnvironment env) { string[] fields = "c0,c1".SplitCsv(); SupportEvalBuilder builder = new SupportEvalBuilder("SupportCollection"); builder.WithExpression(fields[0], "Strvals.mostFrequent()"); builder.WithExpression(fields[1], "Strvals.leastFrequent()"); builder.WithStatementConsumer(stmt => AssertTypesAllSame(stmt.EventType, fields, typeof(string))); builder.WithAssertion(SupportCollection.MakeString("E2,E1,E2,E1,E3,E3,E4,E3")).Expect(fields, "E3", "E4"); builder.WithAssertion(SupportCollection.MakeString("E1")).Expect(fields, "E1", "E1"); builder.WithAssertion(SupportCollection.MakeString(null)).Expect(fields, null, null); builder.WithAssertion(SupportCollection.MakeString("")).Expect(fields, null, null); builder.Run(env); }
private void RunAssertionSetLogicWithScalar(EPServiceProvider epService) { string epl = "select " + "Strvals.except(Strvalstwo) as val0," + "Strvals.intersect(Strvalstwo) as val1, " + "Strvals.union(Strvalstwo) as val2 " + " from SupportCollection as bean"; EPStatement stmt = epService.EPAdministrator.CreateEPL(epl); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; LambdaAssertionUtil.AssertTypes(stmt.EventType, "val0".Split(','), new Type[] { typeof(ICollection <string>) }); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2", "E3,E4")); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", "E1", "E2"); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val1"); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val2", "E1", "E2", "E3", "E4"); listener.Reset(); epService.EPRuntime.SendEvent(SupportCollection.MakeString(null, "E3,E4")); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", (object[])null); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val1", (object[])null); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val2", (object[])null); listener.Reset(); epService.EPRuntime.SendEvent(SupportCollection.MakeString("", "E3,E4")); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0"); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val1"); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val2", "E3", "E4"); listener.Reset(); epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E3,E5", "E3,E4")); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", "E1", "E5"); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val1", "E3"); LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val2", "E1", "E3", "E5", "E3", "E4"); listener.Reset(); stmt.Dispose(); }