private void AssertPartitionInfo(RegressionEnvironment env) { var partitionAdmin = env.Runtime.ContextPartitionService; var depIdCtx = env.DeploymentId("CTX"); var partitions = partitionAdmin.GetContextPartitions( depIdCtx, "CtxCategory", ContextPartitionSelectorAll.INSTANCE); Assert.AreEqual(2, partitions.Identifiers.Count); var descs = partitions.Identifiers.Values.ToArray(); var first = (ContextPartitionIdentifierCategory) descs[0]; var second = (ContextPartitionIdentifierCategory) descs[1]; EPAssertionUtil.AssertEqualsAnyOrder( new [] { "cat1","cat2" }, new object[] {first.Label, second.Label}); var desc = partitionAdmin.GetIdentifier(depIdCtx, "CtxCategory", 0); Assert.AreEqual("cat1", ((ContextPartitionIdentifierCategory) desc).Label); SupportContextPropUtil.AssertContextProps( env, "CTX", "CtxCategory", new[] {0, 1}, "label", new[] { new object[] {"cat1"}, new object[] {"cat2"} }); }
public void Run(RegressionEnvironment env) { var path = new RegressionPath(); var epl = "@Name('ctx') create context CtxPartitionInitWCorrTerm " + "partition by TheString from SupportBean " + "initiated by SupportBean(BoolPrimitive=true) as sb " + "terminated by SupportBean(BoolPrimitive=false, IntPrimitive=sb.IntPrimitive)"; env.CompileDeploy(epl, path); env.CompileDeploy( "@Name('s0') context CtxPartitionInitWCorrTerm select TheString, sum(LongPrimitive) as theSum from SupportBean output last when terminated", path); env.AddListener("s0"); var fields = new [] { "TheString","theSum" }; var initA = SendBean(env, "A", 100, 1, true); env.Milestone(0); SendBean(env, "B", 99, 2, false); var initB = SendBean(env, "B", 200, 3, true); SendBean(env, "A", 0, 4, false); SendBean(env, "B", 0, 5, false); SendBean(env, "A", 0, 6, true); Assert.IsFalse(env.Listener("s0").IsInvoked); AssertPartitionsInitWCorrelatedTermFilter(env); SupportContextPropUtil.AssertContextProps( env, "ctx", "CtxPartitionInitWCorrTerm", new[] {0, 1}, "key1,sb", new[] {new object[] {"A", initA}, new object[] {"B", initB}}); env.Milestone(1); SendBean(env, "B", 200, 7, false); EPAssertionUtil.AssertProps( env.Listener("s0").AssertOneGetNewAndReset(), fields, new object[] {"B", 3 + 5L}); env.Milestone(2); SendBean(env, "A", 100, 8, false); EPAssertionUtil.AssertProps( env.Listener("s0").AssertOneGetNewAndReset(), fields, new object[] {"A", 1 + 4 + 6L}); AssertFilterSvcCount(env, 1, "ctx"); env.UndeployAll(); }
public void Run(RegressionEnvironment env) { var fields = new [] { "c0", "c1", "c2", "c3" }; var milestone = new AtomicLong(); var path = new RegressionPath(); env.CompileDeploy( "@Name('ctx') 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", path); env.CompileDeploy( "@Name('s0') context MyCtx select context.id as c0, context.label as c1, TheString as c2, sum(IntPrimitive) as c3 from SupportBean#keepall group by TheString", path); env.SendEventBean(new SupportBean("E1", 1)); env.SendEventBean(new SupportBean("E2", -5)); env.SendEventBean(new SupportBean("E1", 2)); env.MilestoneInc(milestone); env.SendEventBean(new SupportBean("E3", -100)); env.SendEventBean(new SupportBean("E3", -8)); env.SendEventBean(new SupportBean("E1", 60)); EPAssertionUtil.AssertPropsPerRowAnyOrder( env.Statement("s0").GetEnumerator(), env.Statement("s0").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} }); SupportContextPropUtil.AssertContextProps( env, "ctx", "MyCtx", new[] {0, 1, 2}, "label", new[] { new object[] {"grp1"}, new object[] {"grp2"}, new object[] {"grp3"} }); env.MilestoneInc(milestone); // test iterator targeted by context partition id var selectorById = new SupportSelectorById(Collections.SingletonList(1)); EPAssertionUtil.AssertPropsPerRowAnyOrder( env.Statement("s0").GetEnumerator(selectorById), env.Statement("s0").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>(Arrays.AsList("grp1", "grp3"))); EPAssertionUtil.AssertPropsPerRowAnyOrder( env.Statement("s0").GetEnumerator(selector), env.Statement("s0").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( env.Statement("s0").GetEnumerator(filtered), env.Statement("s0").GetSafeEnumerator(filtered), fields, new[] { new object[] {0, "grp1", "E3", -108} }); Assert.IsFalse( env.Statement("s0") .GetEnumerator( new SupportSelectorCategory( (ISet<string>) null)) .MoveNext()); Assert.IsFalse( env.Statement("s0") .GetEnumerator( new SupportSelectorCategory( new EmptySet<string>())) .MoveNext()); env.MilestoneInc(milestone); // test always-false filter - compare context partition info filtered = new MySelectorFilteredCategory(null); Assert.IsFalse(env.Statement("s0").GetEnumerator(filtered).MoveNext()); EPAssertionUtil.AssertEqualsAnyOrder(new object[] {"grp1", "grp2", "grp3"}, filtered.Categories); 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, ContextPartitionSelectorCategory] interfaces but received com."), "message: " + ex.Message); } env.UndeployAll(); }
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); }