public void TestAuditBasic() { // stream, and test audit callback var callback = new SupportAuditCallback(); AuditPath.AuditCallback += callback.Audit; AuditLog.Info("*** Stream: "); var stmtInput = _epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('stream') select * from SupportBean(TheString = 'E1')"); _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); Assert.AreEqual(1, callback.Audits.Count); var cb = callback.Audits[0]; Assert.AreEqual("SupportBean(TheString=...) inserted SupportBean[SupportBean(E1, 1)]", cb.Message); Assert.AreEqual("ABC", cb.StatementName); Assert.AreEqual(EPServiceProviderConstants.DEFAULT_ENGINE_URI, cb.EngineURI); Assert.AreEqual(AuditEnum.STREAM, cb.Category); AuditPath.AuditCallback -= callback.Audit; stmtInput.Dispose(); }
private void RunAssertionAudit(EPServiceProvider epService) { // stream, and test audit callback var callback = new SupportAuditCallback(); AuditPath.AuditCallback = callback.Audit; AUDITLOG.Info("*** Stream: "); EPStatement stmtInput = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('stream') select * from SupportBean(TheString = 'E1')"); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); Assert.AreEqual(1, callback.Audits.Count); AuditContext cb = callback.Audits[0]; Assert.AreEqual("SupportBean(TheString=...) inserted SupportBean[SupportBean(E1, 1)]", cb.Message); Assert.AreEqual("ABC", cb.StatementName); Assert.AreEqual(EPServiceProviderConstants.DEFAULT_ENGINE_URI, cb.EngineURI); Assert.AreEqual(AuditEnum.STREAM, cb.Category); AuditPath.AuditCallback = null; stmtInput.Dispose(); AUDITLOG.Info("*** Named Window And Insert-Into: "); EPStatement stmtNW = epService.EPAdministrator.CreateEPL("@Name('create') @Audit create window WinOne#keepall as SupportBean"); EPStatement stmtInsertNW = epService.EPAdministrator.CreateEPL("@Name('insert') @Audit insert into WinOne select * from SupportBean"); EPStatement stmtConsumeNW = epService.EPAdministrator.CreateEPL("@Name('select') @Audit select * from WinOne"); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); stmtNW.Dispose(); stmtInsertNW.Dispose(); stmtConsumeNW.Dispose(); AUDITLOG.Info("*** Insert-Into: "); EPStatement stmtInsertInto = epService.EPAdministrator.CreateEPL("@Name('insert') @Audit insert into ABC select * from SupportBean"); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); stmtInsertInto.Dispose(); AUDITLOG.Info("*** Schedule: "); epService.EPRuntime.SendEvent(new CurrentTimeEvent(0)); EPStatement stmtSchedule = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('schedule') select irstream * from SupportBean#time(1 sec)"); var listener = new SupportUpdateListener(); stmtSchedule.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); listener.Reset(); Log.Info("Sending time"); epService.EPRuntime.SendEvent(new CurrentTimeEvent(2000)); Assert.IsTrue(listener.IsInvoked); listener.Reset(); stmtSchedule.Dispose(); // exprdef-instances AUDITLOG.Info("*** Expression-Def: "); EPStatement stmtExprDef = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('exprdef') " + "expression DEF { 1 } " + "expression INN { x => x.TheString }" + "expression OUT { x => INN(x) } " + "select DEF(), OUT(sb) from SupportBean sb"); stmtExprDef.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); Assert.AreEqual(1, listener.AssertOneGetNewAndReset().Get("DEF()")); stmtExprDef.Dispose(); // pattern-instances AUDITLOG.Info("*** Pattern-Lifecycle: "); EPStatement stmtPatternLife = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('pattern-instances') select a.IntPrimitive as val0 from pattern [every a=SupportBean -> (b=SupportBean_ST0 and not SupportBean_ST1)]"); stmtPatternLife.Events += listener.Update; Log.Info("Sending E1"); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); Log.Info("Sending E2"); epService.EPRuntime.SendEvent(new SupportBean("E2", 2)); Log.Info("Sending E3"); epService.EPRuntime.SendEvent(new SupportBean_ST1("E3", 3)); stmtPatternLife.Dispose(); // pattern AUDITLOG.Info("*** Pattern: "); EPStatement stmtPattern = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('pattern') select a.IntPrimitive as val0 from pattern [a=SupportBean -> b=SupportBean_ST0]"); stmtPattern.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); epService.EPRuntime.SendEvent(new SupportBean_ST0("E2", 2)); Assert.AreEqual(1, listener.AssertOneGetNewAndReset().Get("val0")); stmtPattern.Dispose(); // view AUDITLOG.Info("*** View: "); EPStatement stmtView = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('view') select IntPrimitive from SupportBean#lastevent"); stmtView.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 50)); Assert.AreEqual(50, listener.AssertOneGetNewAndReset().Get("IntPrimitive")); stmtView.Dispose(); EPStatement stmtGroupedView = epService.EPAdministrator.CreateEPL("@Audit Select * From SupportBean#groupwin(TheString)#length(2)"); stmtGroupedView.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 50)); listener.Reset(); stmtGroupedView.Dispose(); EPStatement stmtGroupedWIntersectionView = epService.EPAdministrator.CreateEPL("@Audit Select * From SupportBean#groupwin(TheString)#length(2)#unique(IntPrimitive)"); stmtGroupedWIntersectionView.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 50)); listener.Reset(); stmtGroupedWIntersectionView.Dispose(); // expression AUDITLOG.Info("*** Expression: "); EPStatement stmtExpr = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('expression') select IntPrimitive*100 as val0, sum(IntPrimitive) as val1 from SupportBean"); stmtExpr.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 50)); Assert.AreEqual(5000, listener.AssertOneGetNew().Get("val0")); Assert.AreEqual(50, listener.AssertOneGetNewAndReset().Get("val1")); stmtExpr.Dispose(); // expression-detail AUDITLOG.Info("*** Expression-Nested: "); EPStatement stmtExprNested = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('expression-nested') select ('A'||TheString)||'X' as val0 from SupportBean"); stmtExprNested.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 50)); Assert.AreEqual("AE1X", listener.AssertOneGetNewAndReset().Get("val0")); stmtExprNested.Dispose(); // property AUDITLOG.Info("*** Property: "); EPStatement stmtProp = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('property') select IntPrimitive from SupportBean"); stmtProp.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 50)); Assert.AreEqual(50, listener.AssertOneGetNewAndReset().Get("IntPrimitive")); stmtProp.Dispose(); // with aggregation epService.EPAdministrator.CreateEPL("@Audit @Name ('create') create window MyWindow#keepall as SupportBean"); string eplWithAgg = "@Audit @Name('S0') on SupportBean as sel select count(*) from MyWindow as win having count(*)=3 order by win.IntPrimitive"; EPStatement stmtWithAgg = epService.EPAdministrator.CreateEPL(eplWithAgg); stmtWithAgg.Dispose(); // data flow EPStatement stmtDataflow = epService.EPAdministrator.CreateEPL("@Audit @Name('df') create dataflow MyFlow " + "EventBusSource -> a<SupportBean> {filter:TheString like 'I%'} " + "Filter(a) -> b {filter: true}" + "LogSink(b) {log:false}"); EPDataFlowInstance df = epService.EPRuntime.DataFlowRuntime.Instantiate("MyFlow"); df.Start(); epService.EPRuntime.SendEvent(new SupportBean("I1", 1)); df.Cancel(); // context partitions epService.EPAdministrator.CreateEPL("create context WhenEventArrives " + "initiated by SupportBean_ST0 as st0 " + "terminated by SupportBean_ST1(id=st0.id)"); epService.EPAdministrator.CreateEPL("@Audit('ContextPartition') context WhenEventArrives select * from SupportBean"); epService.EPRuntime.SendEvent(new SupportBean_ST0("E1", 0)); epService.EPRuntime.SendEvent(new SupportBean_ST1("E1", 0)); stmtDataflow.Dispose(); // table AUDITLOG.Info("*** Table And Insert-Into and Into-table: "); EPStatement stmtTable = epService.EPAdministrator.CreateEPL("@Name('create-table') @Audit create table TableOne(c0 string primary key, cnt count(*))"); EPStatement stmtIntoTable = epService.EPAdministrator.CreateEPL("@Name('into-table') @Audit into table TableOne select count(*) as cnt from SupportBean group by TheString"); EPStatement stmtAccessTable = epService.EPAdministrator.CreateEPL("@Name('access-table') @Audit select TableOne[id].cnt from SupportBean_ST0"); stmtAccessTable.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); epService.EPRuntime.SendEvent(new SupportBean_ST0("E1", 0)); stmtTable.Dispose(); stmtIntoTable.Dispose(); stmtAccessTable.Dispose(); }
public void Run(RegressionEnvironment env) { env.AdvanceTime(1); var path = new RegressionPath(); // stream, and test audit callback var callback = new SupportAuditCallback(); AuditPath.AuditCallback = callback.Audit; AUDITLOG.Info("*** Stream: "); env.CompileDeploy("@Name('ABC') @Audit('stream') select * from SupportBean(TheString = 'E1')"); env.SendEventBean(new SupportBean("E1", 1)); Assert.AreEqual(1, callback.Audits.Count); var cb = callback.Audits[0]; Assert.AreEqual("SupportBean(TheString=...) inserted SupportBean[SupportBean(\"E1\", 1)]", cb.Message); Assert.AreEqual(env.DeploymentId("ABC"), cb.DeploymentId); Assert.AreEqual("ABC", cb.StatementName); Assert.AreEqual(DEFAULT_RUNTIME_URI, cb.RuntimeURI); Assert.AreEqual(AuditEnum.STREAM, cb.Category); Assert.AreEqual(1, cb.RuntimeTime); AuditPath.AuditCallback = null; env.UndeployAll(); AUDITLOG.Info("*** Insert-Into: "); env.CompileDeploy("@Name('insert') @Audit insert into ABC select * from SupportBean"); env.SendEventBean(new SupportBean("E1", 1)); env.UndeployAll(); AUDITLOG.Info("*** Named Window And Insert-Into: "); env.CompileDeploy("@Name('create') @Audit create window WinOne#keepall as SupportBean", path); env.CompileDeploy("@Name('insert') @Audit insert into WinOne select * from SupportBean", path); env.CompileDeploy("@Name('select') @Audit select * from WinOne", path); env.SendEventBean(new SupportBean("E1", 1)); env.UndeployAll(); path.Clear(); AUDITLOG.Info("*** Schedule: "); env.AdvanceTime(0); env.CompileDeploy("@Name('ABC') @Audit('schedule') select irstream * from SupportBean#time(1 sec)") .AddListener("ABC"); env.SendEventBean(new SupportBean("E1", 1)); env.Listener("ABC").Reset(); log.Info("Sending time"); env.AdvanceTime(2000); Assert.IsTrue(env.Listener("ABC").IsInvoked); env.UndeployAll(); // property AUDITLOG.Info("*** Property: "); env.CompileDeploy("@Name('ABC') @Audit('property') select IntPrimitive from SupportBean") .AddListener("ABC"); env.SendEventBean(new SupportBean("E1", 50)); Assert.AreEqual(50, env.Listener("ABC").AssertOneGetNewAndReset().Get("IntPrimitive")); env.UndeployAll(); // view AUDITLOG.Info("*** View: "); env.CompileDeploy("@Name('ABC') @Audit('view') select IntPrimitive from SupportBean#lastevent") .AddListener("ABC"); env.SendEventBean(new SupportBean("E1", 50)); Assert.AreEqual(50, env.Listener("ABC").AssertOneGetNewAndReset().Get("IntPrimitive")); env.UndeployAll(); env.CompileDeploy("@Name('s0') @Audit Select * From SupportBean#groupwin(TheString)#length(2)") .AddListener("s0"); env.SendEventBean(new SupportBean("E1", 50)); env.UndeployAll(); env.CompileDeploy( "@Name('s0') @Audit Select * From SupportBean#groupwin(TheString)#length(2)#unique(IntPrimitive)") .AddListener("s0"); env.SendEventBean(new SupportBean("E1", 50)); env.UndeployAll(); // expression AUDITLOG.Info("*** Expression: "); env.CompileDeploy( "@Name('ABC') @Audit('expression') select IntPrimitive*100 as val0, sum(IntPrimitive) as val1 from SupportBean") .AddListener("ABC"); env.SendEventBean(new SupportBean("E1", 50)); Assert.AreEqual(5000, env.Listener("ABC").AssertOneGetNew().Get("val0")); Assert.AreEqual(50, env.Listener("ABC").AssertOneGetNewAndReset().Get("val1")); env.UndeployAll(); // expression-detail AUDITLOG.Info("*** Expression-Nested: "); env.CompileDeploy( "@Name('ABC') @Audit('expression-nested') select ('A'||TheString)||'X' as val0 from SupportBean") .AddListener("ABC"); env.SendEventBean(new SupportBean("E1", 50)); Assert.AreEqual("AE1X", env.Listener("ABC").AssertOneGetNewAndReset().Get("val0")); env.UndeployAll(); // pattern AUDITLOG.Info("*** Pattern: "); env.CompileDeploy( "@Name('ABC') @Audit('pattern') select a.IntPrimitive as val0 from pattern [a=SupportBean -> b=SupportBean_ST0]") .AddListener("ABC"); env.SendEventBean(new SupportBean("E1", 1)); env.SendEventBean(new SupportBean_ST0("E2", 2)); Assert.AreEqual(1, env.Listener("ABC").AssertOneGetNewAndReset().Get("val0")); env.UndeployAll(); // pattern-instances AUDITLOG.Info("*** Pattern-Lifecycle: "); env.CompileDeploy( "@Name('ABC') @Audit('pattern-instances') select a.IntPrimitive as val0 from pattern [every a=SupportBean -> (b=SupportBean_ST0 and not SupportBean_ST1)]") .AddListener("ABC"); log.Info("Sending E1"); env.SendEventBean(new SupportBean("E1", 1)); log.Info("Sending E2"); env.SendEventBean(new SupportBean("E2", 2)); log.Info("Sending E3"); env.SendEventBean(new SupportBean_ST1("E3", 3)); log.Info("Destroy"); env.UndeployAll(); // exprdef-instances AUDITLOG.Info("*** Expression-Def: "); env.CompileDeploy( "@Name('ABC') @Audit('exprdef') " + "expression DEF { 1 } " + "expression INN { x -> x.TheString }" + "expression OUT { x -> INN(x) } " + "select DEF(), OUT(sb) from SupportBean sb") .AddListener("ABC"); env.SendEventBean(new SupportBean("E1", 1)); Assert.AreEqual(1, env.Listener("ABC").AssertOneGetNewAndReset().Get("DEF()")); env.UndeployAll(); // data flow env.CompileDeploy( "@Audit @Name('df') create dataflow MyFlow " + "EventBusSource -> a<SupportBean> {filter:TheString like 'I%'} " + "filter(a) -> b {filter: true}" + "LogSink(b) {log:false}"); var df = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("df"), "MyFlow"); df.Start(); env.SendEventBean(new SupportBean("I1", 1)); df.Cancel(); // context partitions env.CompileDeploy( "create context WhenEventArrives " + "initiated by SupportBean_ST0 as st0 " + "terminated by SupportBean_ST1(Id=st0.Id);\n" + "@Audit('ContextPartition') context WhenEventArrives select * from SupportBean;\n"); env.SendEventBean(new SupportBean_ST0("E1", 0)); env.SendEventBean(new SupportBean_ST1("E1", 0)); env.UndeployAll(); // table AUDITLOG.Info("*** Table And Insert-Into and Into-table: "); env.CompileDeploy( "@Name('create-table') @Audit create table TableOne(c0 string primary key, cnt count(*))", path); env.CompileDeploy( "@Name('into-table') @Audit into table TableOne select count(*) as cnt from SupportBean group by TheString", path); env.CompileDeploy("@Name('access-table') @Audit select TableOne[Id].cnt from SupportBean_ST0", path) .AddListener("access-table"); env.SendEventBean(new SupportBean("E1", 1)); env.SendEventBean(new SupportBean_ST0("E1", 0)); env.UndeployAll(); path.Clear(); // int-expression with endpoint-included env.CompileDeploy("@Audit select * from SupportBean#keepall where IntPrimitive in (1:3)"); env.SendEventBean(new SupportBean("E1", 1)); env.UndeployAll(); }