private void RunAssertionContextPartitionSelection(EPServiceProvider epService) { var fields = "c0,c1,c2,c3".Split(','); epService.EPAdministrator.CreateEPL("create context MyCtx as group by IntPrimitive < -5 as grp1, group by IntPrimitive between -5 and +5 as grp2, group by IntPrimitive > 5 as grp3 from SupportBean"); var stmt = epService.EPAdministrator.CreateEPL("context MyCtx select context.id as c0, context.label as c1, TheString as c2, sum(IntPrimitive) as c3 from SupportBean#keepall group by TheString"); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); epService.EPRuntime.SendEvent(new SupportBean("E2", -5)); epService.EPRuntime.SendEvent(new SupportBean("E1", 2)); epService.EPRuntime.SendEvent(new SupportBean("E3", -100)); epService.EPRuntime.SendEvent(new SupportBean("E3", -8)); epService.EPRuntime.SendEvent(new SupportBean("E1", 60)); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), stmt.GetSafeEnumerator(), fields, new[] { new object[] { 0, "grp1", "E3", -108 }, new object[] { 1, "grp2", "E1", 3 }, new object[] { 1, "grp2", "E2", -5 }, new object[] { 2, "grp3", "E1", 60 } }); // test iterator targeted by context partition id var selectorById = new SupportSelectorById(Collections.SingletonSet(1)); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(selectorById), stmt.GetSafeEnumerator(selectorById), fields, new[] { new object[] { 1, "grp2", "E1", 3 }, new object[] { 1, "grp2", "E2", -5 } }); // test iterator targeted for a given category var selector = new SupportSelectorCategory(new HashSet <string>(Collections.List("grp1", "grp3"))); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(selector), stmt.GetSafeEnumerator(selector), fields, new[] { new object[] { 0, "grp1", "E3", -108 }, new object[] { 2, "grp3", "E1", 60 } }); // test iterator targeted for a given filtered category var filtered = new MySelectorFilteredCategory("grp1"); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(filtered), stmt.GetSafeEnumerator(filtered), fields, new[] { new object[] { 0, "grp1", "E3", -108 } }); Assert.IsFalse(stmt.GetEnumerator(new SupportSelectorCategory((ISet <string>)null)).MoveNext()); Assert.IsFalse(stmt.GetEnumerator(new SupportSelectorCategory(Collections.GetEmptySet <string>())).MoveNext()); // test always-false filter - compare context partition info filtered = new MySelectorFilteredCategory(null); Assert.IsFalse(stmt.GetEnumerator(filtered).MoveNext()); EPAssertionUtil.AssertEqualsAnyOrder(new object[] { "grp1", "grp2", "grp3" }, filtered.Categories); try { stmt.GetEnumerator(new ProxyContextPartitionSelectorSegmented() { ProcPartitionKeys = () => null }); Assert.Fail(); } catch (InvalidContextPartitionSelector ex) { Assert.IsTrue(ex.Message.StartsWith("Invalid context partition selector, expected an implementation class of any of [ContextPartitionSelectorAll, ContextPartitionSelectorFiltered, ContextPartitionSelectorById, ContextPartitionSelectorCategory] interfaces but received com."), "message: " + ex.Message); } epService.EPAdministrator.DestroyAllStatements(); }
public void TestContextPartitionSelection() { String[] fields = "c0,c1,c2,c3".Split(','); _epService.EPRuntime.SendEvent(new CurrentTimeEvent(0)); _epService.EPAdministrator.CreateEPL("create context MyCtx as start SupportBean_S0 s0 end SupportBean_S1(Id=s0.Id)"); EPStatement stmt = _epService.EPAdministrator.CreateEPL("context MyCtx select context.id as c0, context.s0.P00 as c1, TheString as c2, sum(IntPrimitive) as c3 from SupportBean.win:keepall() group by TheString"); _epService.EPRuntime.SendEvent(new CurrentTimeEvent(1000)); _epService.EPRuntime.SendEvent(new SupportBean_S0(1, "S0_1")); _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); _epService.EPRuntime.SendEvent(new SupportBean("E2", 10)); _epService.EPRuntime.SendEvent(new SupportBean("E1", 2)); _epService.EPRuntime.SendEvent(new SupportBean("E3", 100)); _epService.EPRuntime.SendEvent(new SupportBean("E3", 101)); _epService.EPRuntime.SendEvent(new SupportBean("E1", 3)); Object[][] expected = new Object[][] { new Object[] { 0, "S0_1", "E1", 6 }, new Object[] { 0, "S0_1", "E2", 10 }, new Object[] { 0, "S0_1", "E3", 201 } }; EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), stmt.GetSafeEnumerator(), fields, expected); // test iterator targeted by context partition id SupportSelectorById selectorById = new SupportSelectorById(0.AsSingleton()); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(selectorById), stmt.GetSafeEnumerator(selectorById), fields, expected); // test iterator targeted by property on triggering event SupportSelectorFilteredInitTerm filtered = new SupportSelectorFilteredInitTerm("S0_1"); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(filtered), stmt.GetSafeEnumerator(filtered), fields, expected); filtered = new SupportSelectorFilteredInitTerm("S0_2"); Assert.IsFalse(stmt.GetEnumerator(filtered).MoveNext()); // test always-false filter - compare context partition info filtered = new SupportSelectorFilteredInitTerm(null); Assert.IsFalse(stmt.GetEnumerator(filtered).MoveNext()); EPAssertionUtil.AssertEqualsAnyOrder(new Object[] { 1000L }, filtered.ContextsStartTimes); EPAssertionUtil.AssertEqualsAnyOrder(new Object[] { "S0_1" }, filtered.P00PropertyValues); try { stmt.GetEnumerator(new ProxyContextPartitionSelectorSegmented { ProcPartitionKeys = () => null }); Assert.Fail(); } catch (InvalidContextPartitionSelector ex) { Assert.IsTrue(ex.Message.StartsWith("Invalid context partition selector, expected an implementation class of any of [ContextPartitionSelectorAll, ContextPartitionSelectorFiltered, ContextPartitionSelectorById] interfaces but received com."), "message: " + ex.Message); } }
public void TestIterateStatement() { _epService.EPAdministrator.CreateEPL("create context PartitionedByString partition by TheString from SupportBean"); String[] fields = "c0,c1".Split(','); EPStatement stmt = _epService.EPAdministrator.CreateEPL("@Name('StmtOne') context PartitionedByString select context.key1 as c0, Sum(IntPrimitive) as c1 from SupportBean#length(5)"); _epService.EPRuntime.SendEvent(new SupportBean("E1", 10)); _epService.EPRuntime.SendEvent(new SupportBean("E2", 20)); _epService.EPRuntime.SendEvent(new SupportBean("E2", 21)); Object[][] expectedAll = new Object[][] { new Object[] { "E1", 10 }, new Object[] { "E2", 41 } }; EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), stmt.GetSafeEnumerator(), fields, expectedAll); // test iterator ALL ContextPartitionSelector selector = ContextPartitionSelectorAll.INSTANCE; EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(selector), stmt.GetSafeEnumerator(selector), fields, expectedAll); // test iterator by context partition id selector = new SupportSelectorById(new HashSet <int>(Collections.List(0, 1, 2))); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(selector), stmt.GetSafeEnumerator(selector), fields, expectedAll); selector = new SupportSelectorById(new HashSet <int>(Collections.List(1))); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(selector), stmt.GetSafeEnumerator(selector), fields, new Object[][] { new Object[] { "E2", 41 } }); Assert.IsFalse(stmt.GetEnumerator(new SupportSelectorById(Collections.GetEmptySet <int>())).MoveNext()); Assert.IsFalse(stmt.GetEnumerator(new SupportSelectorById(null)).MoveNext()); try { stmt.GetEnumerator(null); Assert.Fail(); } catch (ArgumentException ex) { Assert.AreEqual(ex.Message, "No selector provided"); } try { stmt.GetSafeEnumerator(null); Assert.Fail(); } catch (ArgumentException ex) { Assert.AreEqual(ex.Message, "No selector provided"); } EPStatement stmtTwo = _epService.EPAdministrator.CreateEPL("select * from System.Object"); try { stmtTwo.GetEnumerator(null); Assert.Fail(); } catch (UnsupportedOperationException ex) { Assert.AreEqual(ex.Message, "Enumerator with context selector is only supported for statements under context"); } try { stmtTwo.GetSafeEnumerator(null); Assert.Fail(); } catch (UnsupportedOperationException ex) { Assert.AreEqual(ex.Message, "Enumerator with context selector is only supported for statements under context"); } }