public void TestContextPartitionSelection() { var fields = "c0,c1,c2".Split(','); _epService.EPAdministrator.CreateEPL("create context MyCtx as coalesce Consistent_hash_crc32(TheString) from SupportBean granularity 16 preallocate"); var stmt = _epService.EPAdministrator.CreateEPL("context MyCtx select context.id as c0, TheString as c1, Sum(IntPrimitive) as c2 from SupportBean.win:keepall() group by TheString"); _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), stmt.GetSafeEnumerator(), fields, new Object[][] { new Object[] { 5, "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)); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), stmt.GetSafeEnumerator(), fields, new Object[][] { new Object[] { 5, "E1", 6 }, new Object[] { 15, "E2", 10 }, new Object[] { 9, "E3", 201 } }); // test iterator targeted hash var selector = new SupportSelectorByHashCode(Collections.SingletonList(15)); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(selector), stmt.GetSafeEnumerator(selector), fields, new Object[][] { new Object[] { 15, "E2", 10 } }); selector = new SupportSelectorByHashCode(new HashSet <int> { 1, 9, 5 }); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(selector), stmt.GetSafeEnumerator(selector), fields, new Object[][] { new Object[] { 5, "E1", 6 }, new Object[] { 9, "E3", 201 } }); Assert.IsFalse(stmt.GetEnumerator(new SupportSelectorByHashCode(Collections.SingletonList(99))).MoveNext()); Assert.IsFalse(stmt.GetEnumerator(new SupportSelectorByHashCode(Collections.GetEmptySet <int>())).MoveNext()); Assert.IsFalse(stmt.GetEnumerator(new SupportSelectorByHashCode(null)).MoveNext()); // test iterator filtered var filtered = new MySelectorFilteredHash(Collections.SingletonList(15)); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(filtered), stmt.GetSafeEnumerator(filtered), fields, new Object[][] { new Object[] { 15, "E2", 10 } }); filtered = new MySelectorFilteredHash(new HashSet <int> { 1, 9, 5 }); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(filtered), stmt.GetSafeEnumerator(filtered), fields, new Object[][] { new Object[] { 5, "E1", 6 }, new Object[] { 9, "E3", 201 } }); // test always-false filter - compare context partition info filtered = new MySelectorFilteredHash(Collections.GetEmptySet <int>()); Assert.IsFalse(stmt.GetEnumerator(filtered).MoveNext()); Assert.AreEqual(16, filtered.Contexts.Count); 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, ContextPartitionSelectorHash] interfaces but received com."), "message: " + ex.Message); } }
public void Run(RegressionEnvironment env) { var fields = new[] {"c0", "c1", "c2"}; var path = new RegressionPath(); env.CompileDeploy( "@Name('ctx') create context MyCtx as coalesce consistent_hash_crc32(TheString) from SupportBean granularity 16 preallocate", path); env.CompileDeploy( "@Name('s0') context MyCtx select context.id as c0, TheString as c1, sum(IntPrimitive) as c2 from SupportBean#keepall group by TheString", path); env.Milestone(0); env.SendEventBean(new SupportBean("E1", 1)); EPAssertionUtil.AssertPropsPerRow( env.Statement("s0").GetEnumerator(), env.Statement("s0").GetSafeEnumerator(), fields, new[] { new object[] {5, "E1", 1} }); env.SendEventBean(new SupportBean("E2", 10)); env.SendEventBean(new SupportBean("E1", 2)); env.Milestone(1); env.SendEventBean(new SupportBean("E3", 100)); env.SendEventBean(new SupportBean("E3", 101)); env.SendEventBean(new SupportBean("E1", 3)); EPAssertionUtil.AssertPropsPerRowAnyOrder( env.Statement("s0").GetEnumerator(), env.Statement("s0").GetSafeEnumerator(), fields, new[] { new object[] {5, "E1", 6}, new object[] {15, "E2", 10}, new object[] {9, "E3", 201} }); SupportContextPropUtil.AssertContextProps(env, "ctx", "MyCtx", new[] {5, 15, 9}, null, null); env.Milestone(2); // test iterator targeted hash var selector = new SupportSelectorByHashCode(Collections.SingletonSet(15)); EPAssertionUtil.AssertPropsPerRowAnyOrder( env.Statement("s0").GetEnumerator(selector), env.Statement("s0").GetSafeEnumerator(selector), fields, new[] { new object[] {15, "E2", 10} }); selector = new SupportSelectorByHashCode(new HashSet<int>(Arrays.AsList(1, 9, 5))); EPAssertionUtil.AssertPropsPerRowAnyOrder( env.Statement("s0").GetEnumerator(selector), env.Statement("s0").GetSafeEnumerator(selector), fields, new[] { new object[] {5, "E1", 6}, new object[] {9, "E3", 201} }); Assert.IsFalse( env.Statement("s0") .GetEnumerator( new SupportSelectorByHashCode(Collections.SingletonSet(99))) .MoveNext()); Assert.IsFalse( env.Statement("s0") .GetEnumerator( new SupportSelectorByHashCode(Collections.GetEmptySet<int>())) .MoveNext()); Assert.IsFalse( env.Statement("s0") .GetEnumerator( new SupportSelectorByHashCode(null)) .MoveNext()); // test iterator filtered var filtered = new MySelectorFilteredHash( Collections.SingletonSet(15)); EPAssertionUtil.AssertPropsPerRowAnyOrder( env.Statement("s0").GetEnumerator(filtered), env.Statement("s0").GetSafeEnumerator(filtered), fields, new[] { new object[] {15, "E2", 10} }); filtered = new MySelectorFilteredHash(new HashSet<int>(Arrays.AsList(1, 9, 5))); EPAssertionUtil.AssertPropsPerRowAnyOrder( env.Statement("s0").GetEnumerator(filtered), env.Statement("s0").GetSafeEnumerator(filtered), fields, new[] { new object[] {5, "E1", 6}, new object[] {9, "E3", 201} }); // test always-false filter - compare context partition info filtered = new MySelectorFilteredHash(Collections.GetEmptySet<int>()); Assert.IsFalse(env.Statement("s0").GetEnumerator(filtered).MoveNext()); Assert.AreEqual(16, filtered.Contexts.Count); try { env.Statement("s0") .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, ContextPartitionSelectorHash] interfaces but received com."), "message: " + ex.Message); } env.UndeployAll(); env.Milestone(3); }