public void traverseStatementsContains(BiConsumer<EPDeployment, EPStatement> consumer, String containsIgnoreCase) { runtimeSPI.traverseStatements((deployment, stmt) -> { boolean match = false; String searchString = containsIgnoreCase.toLowerCase(Locale.ENGLISH); if (stmt.getName().toLowerCase(Locale.ENGLISH).contains(searchString)) { match = true; } if (!match) { String epl = (String) stmt.getProperty(StatementProperty.EPL); if ((epl != null) && (epl.toLowerCase(Locale.ENGLISH).contains(searchString))) { match = true; } } if (!match) { return; } consumer.accept(deployment, stmt); }); }
public RegressionEnvironment eplToModelCompileDeploy(String epl) { EPStatementObjectModel copy = eplToModel(epl); Assert.assertEquals(epl.trim(), copy.toEPL()); EPCompiled compiled = compile(copy, new CompilerArguments(getConfiguration())); EPDeployment result = tryDeploy(compiled); EPStatement stmt = result.getStatements()[0]; Assert.assertEquals(epl.trim(), stmt.getProperty(StatementProperty.EPL)); return this; }
public RegressionEnvironment eplToModelCompileDeploy(String epl, RegressionPath path) { EPStatementObjectModel copy = eplToModel(epl); Assert.assertEquals(epl.trim(), copy.toEPL()); CompilerArguments args = getArgsWithExportToPath(path); EPCompiled compiled = compile(copy, args); path.add(compiled); EPDeployment result = tryDeploy(compiled); Assert.assertEquals(epl.trim(), result.getStatements()[0].getProperty(StatementProperty.EPL)); return this; }
public void run(RegressionEnvironment env) { String epl = "@name('schema') create schema SimpleSchema(p0 string, p1 int);" + "@name('s0') select * from SimpleSchema;\n" + "insert into SimpleSchema select theString as p0, intPrimitive as p1 from SupportBean;\n"; env.compileDeploy(epl).addListener("s0"); assertEquals(StatementType.CREATE_SCHEMA, env.statement("schema").getProperty(StatementProperty.STATEMENTTYPE)); assertEquals("SimpleSchema", env.statement("schema").getProperty(StatementProperty.CREATEOBJECTNAME)); env.sendEventBean(new SupportBean("a", 20)); EPAssertionUtil.assertProps(env.listener("s0").assertOneGetNewAndReset(), "p0,p1".split(","), new Object[]{"a", 20}); env.undeployAll(); } }
public void run(RegressionEnvironment env) { RegressionPath path = new RegressionPath(); env.compileDeploy("@name('s0') create expression E1 {''}", path); assertEquals(StatementType.CREATE_EXPRESSION, env.statement("s0").getProperty(StatementProperty.STATEMENTTYPE)); assertEquals("E1", env.statement("s0").getProperty(StatementProperty.CREATEOBJECTNAME)); SupportMessageAssertUtil.tryInvalidCompile(env, path, "create expression E1 {''}", "Expression 'E1' has already been declared [create expression E1 {''}]"); env.compileDeploy("create expression int js:abc(p1, p2) [p1*p2]", path); SupportMessageAssertUtil.tryInvalidCompile(env, path, "create expression int js:abc(a, a) [p1*p2]", "Script 'abc' that takes the same number of parameters has already been declared [create expression int js:abc(a, a) [p1*p2]]"); env.undeployAll(); } }
public void run(RegressionEnvironment env) { String epl = "@name('fl') insert into Event_1_EPL(delta, product) " + "select intPrimitive-intBoxed as deltaTag, intPrimitive*intBoxed as productTag " + "from SupportBean#length(100)"; EPStatementObjectModel model = env.eplToModel(epl); model = SerializableObjectCopier.copyMayFail(model); assertEquals(epl, model.toEPL()); tryAssertsVariant(env, null, model, "Event_1_EPL"); assertEquals(epl, env.statement("fl").getProperty(StatementProperty.EPL)); env.undeployAll(); } }
public void run(RegressionEnvironment env) { env.compileDeploy("@name('update') update istream SupportBean " + "set intPrimitive=myvar, intBoxed=intPrimitive"); assertEquals(StatementType.UPDATE, env.statement("update").getProperty(StatementProperty.STATEMENTTYPE)); env.compileDeploy("@name('s0') select * from SupportBean").addListener("s0"); String[] fields = "intPrimitive,intBoxed".split(","); env.sendEventBean(makeSupportBean("E1", 1, 2)); EPAssertionUtil.assertProps(env.listener("s0").getAndResetLastNewData()[0], fields, new Object[]{10, 1}); env.undeployAll(); } }
private static void runAssertionScriptReturningEvents(RegressionEnvironment env, boolean soda) { RegressionPath path = new RegressionPath(); env.compileDeploy("@name('type') create schema ItemEvent(id string)", path); String script = "@name('script') create expression EventBean[] @type(ItemEvent) js:myScriptReturnsEvents() [\n" + "myScriptReturnsEvents();" + "function myScriptReturnsEvents() {" + " var EventBeanArray = Java.type(\"com.espertech.esper.common.client.EventBean[]\");\n" + " var events = new EventBeanArray(3);\n" + " events[0] = epl.getEventBeanService().adapterForMap(java.util.Collections.singletonMap(\"id\", \"id1\"), \"ItemEvent\");\n" + " events[1] = epl.getEventBeanService().adapterForMap(java.util.Collections.singletonMap(\"id\", \"id2\"), \"ItemEvent\");\n" + " events[2] = epl.getEventBeanService().adapterForMap(java.util.Collections.singletonMap(\"id\", \"id3\"), \"ItemEvent\");\n" + " return events;\n" + "}]"; env.compileDeploy(soda, script, path); assertEquals(StatementType.CREATE_EXPRESSION, env.statement("script").getProperty(StatementProperty.STATEMENTTYPE)); assertEquals("myScriptReturnsEvents", env.statement("script").getProperty(StatementProperty.CREATEOBJECTNAME)); env.compileDeploy("@name('s0') select myScriptReturnsEvents().where(v => v.id in ('id1', 'id3')) as c0 from SupportBean", path); env.addListener("s0"); env.sendEventBean(new SupportBean()); Collection<Map> coll = (Collection<Map>) env.listener("s0").assertOneGetNewAndReset().get("c0"); EPAssertionUtil.assertPropsPerRow(coll.toArray(new Map[coll.size()]), "id".split(","), new Object[][]{{"id1"}, {"id3"}}); env.undeployModuleContaining("s0"); env.undeployModuleContaining("script"); env.undeployModuleContaining("type"); }
public void run(RegressionEnvironment env) { RegressionPath path = new RegressionPath(); String eplCtx = "@name('ctx') create context Ctx600a group by theString like 'A%' as agroup, group by theString like 'B%' as bgroup, group by theString like 'C%' as cgroup from SupportBean"; env.compileDeploy(eplCtx, path); String eplSum = "@name('s0') context Ctx600a select context.label as c0, count(*) as c1 from SupportBean"; env.compileDeploy(eplSum, path).addListener("s0"); assertEquals("Ctx600a", env.statement("s0").getProperty(StatementProperty.CONTEXTNAME)); assertEquals(env.deploymentId("ctx"), env.statement("s0").getProperty(StatementProperty.CONTEXTDEPLOYMENTID)); sendAssertBooleanExprFilter(env, "B1", "bgroup", 1); env.milestone(0); sendAssertBooleanExprFilter(env, "A1", "agroup", 1); env.milestone(1); sendAssertBooleanExprFilter(env, "B171771", "bgroup", 2); env.milestone(2); sendAssertBooleanExprFilter(env, "A x", "agroup", 2); env.undeployAll(); } }
public void run(RegressionEnvironment env) { String epl = "@name('window') create window MyWindowOne#unique(theString) as SupportBean;\n" + "insert into MyWindowOne select * from SupportBean;\n" + "@name('idx') create unique index I1 on MyWindowOne(theString);\n"; env.compileDeploy(epl); assertEquals(StatementType.CREATE_INDEX, env.statement("idx").getProperty(StatementProperty.STATEMENTTYPE)); assertEquals("I1", env.statement("idx").getProperty(StatementProperty.CREATEOBJECTNAME)); env.sendEventBean(new SupportBean("E0", 1)); env.sendEventBean(new SupportBean("E2", 2)); env.sendEventBean(new SupportBean("E2", 3)); env.sendEventBean(new SupportBean("E1", 4)); env.sendEventBean(new SupportBean("E0", 5)); EPAssertionUtil.assertPropsPerRowAnyOrder(env.iterator("window"), "theString,intPrimitive".split(","), new Object[][]{{"E0", 5}, {"E1", 4}, {"E2", 3}}); env.undeployAll(); } }
private static void tryAssertionIntegerIndexedPropertyLookAlike(RegressionEnvironment env, boolean soda) { RegressionPath path = new RegressionPath(); String eplDeclare = "@name('infra') create table varaggIIP (key int primary key, myevents window(*) @type('SupportBean'))"; env.compileDeploy(soda, eplDeclare, path); assertEquals(StatementType.CREATE_TABLE, env.statement("infra").getProperty(StatementProperty.STATEMENTTYPE)); assertEquals("varaggIIP", env.statement("infra").getProperty(StatementProperty.CREATEOBJECTNAME)); String eplInto = "into table varaggIIP select window(*) as myevents from SupportBean#length(3) group by intPrimitive"; env.compileDeploy(soda, eplInto, path); String eplSelect = "@name('s0') select varaggIIP[1] as c0, varaggIIP[1].myevents as c1, varaggIIP[1].myevents.last(*) as c2, varaggIIP[1].myevents.last(*,1) as c3 from SupportBean_S0"; env.compileDeploy(soda, eplSelect, path).addListener("s0"); SupportBean e1 = makeSendBean(env, "E1", 1, 10L); SupportBean e2 = makeSendBean(env, "E2", 1, 20L); env.milestone(0); env.sendEventBean(new SupportBean_S0(0)); assertIntegerIndexed(env.listener("s0").assertOneGetNewAndReset(), new SupportBean[]{e1, e2}); env.undeployAll(); } }
public void run(RegressionEnvironment env) { String stmtText = "select * from SupportBean"; EPStatementObjectModel model = env.eplToModel(stmtText); SerializableObjectCopier.copyMayFail(model); model.setAnnotations(Collections.singletonList(AnnotationPart.nameAnnotation("s0"))); env.compileDeploy(model).addListener("s0"); Object theEvent = new SupportBean(); env.sendEventBean(theEvent); Assert.assertEquals(theEvent, env.listener("s0").assertOneGetNewAndReset().getUnderlying()); Assert.assertEquals("@name('s0') " + stmtText, env.statement("s0").getProperty(StatementProperty.EPL)); env.undeployAll(); } }
public void run(RegressionEnvironment env) { env.compileDeploy("@name('s0') expression returnsOne {1} select returnsOne as c0 from SupportBean").addListener("s0"); assertEquals(StatementType.SELECT, env.statement("s0").getProperty(StatementProperty.STATEMENTTYPE)); env.sendEventBean(new SupportBean()); assertEquals(1, env.listener("s0").assertOneGetNewAndReset().get("c0")); env.undeployAll(); } }
public void run(RegressionEnvironment env) { RegressionPath path = new RegressionPath(); env.compileDeploy("create expression int js:abc(p1, p2) [p1*p2*10]", path); env.compileDeploy("create expression int js:abc(p1) [p1*10]", path); String epl = "@name('s0') select abc(intPrimitive, doublePrimitive) as c0, abc(intPrimitive) as c1 from SupportBean"; env.compileDeploy(epl, path).addListener("s0"); env.sendEventBean(makeBean("E1", 10, 3.5)); EPAssertionUtil.assertProps(env.listener("s0").assertOneGetNewAndReset(), "c0,c1".split(","), new Object[]{350, 100}); env.undeployAll(); // test SODA String eplExpr = "@name('expr') create expression somescript(i1) ['a']"; EPStatementObjectModel modelExpr = env.eplToModel(eplExpr); Assert.assertEquals(eplExpr, modelExpr.toEPL()); env.compileDeploy(modelExpr, path); Assert.assertEquals(eplExpr, env.statement("expr").getProperty(StatementProperty.EPL)); String eplSelect = "@name('select') select somescript(1) from SupportBean"; EPStatementObjectModel modelSelect = env.eplToModel(eplSelect); Assert.assertEquals(eplSelect, modelSelect.toEPL()); env.compileDeploy(modelSelect, path); Assert.assertEquals(eplSelect, env.statement("select").getProperty(StatementProperty.EPL)); env.undeployAll(); } }
private static void tryAssertionNoTerminationConditionOverlapping(RegressionEnvironment env, AtomicInteger milestone, boolean soda) { RegressionPath path = new RegressionPath(); env.compileDeploy(soda, "@name('ctx') create context SupportBeanInstanceCtx as initiated by SupportBean as sb", path); env.compileDeploy(soda, "@name('s0') context SupportBeanInstanceCtx " + "select id, context.sb.intPrimitive as sbint, context.startTime as starttime, context.endTime as endtime from SupportBean_S0(p00=context.sb.theString)", path); env.addListener("s0"); String[] fields = "id,sbint,starttime,endtime".split(","); assertEquals(StatementType.CREATE_CONTEXT, env.statement("ctx").getProperty(StatementProperty.STATEMENTTYPE)); assertEquals("SupportBeanInstanceCtx", env.statement("ctx").getProperty(StatementProperty.CREATEOBJECTNAME)); env.milestoneInc(milestone); env.sendEventBean(new SupportBean("P1", 100)); env.milestoneInc(milestone); env.sendEventBean(new SupportBean("P2", 200)); env.milestoneInc(milestone); env.sendEventBean(new SupportBean_S0(10, "P2")); EPAssertionUtil.assertProps(env.listener("s0").assertOneGetNewAndReset(), fields, new Object[]{10, 200, 5L, null}); env.milestoneInc(milestone); env.sendEventBean(new SupportBean_S0(20, "P1")); EPAssertionUtil.assertProps(env.listener("s0").assertOneGetNewAndReset(), fields, new Object[]{20, 100, 5L, null}); env.undeployAll(); }
public void run(RegressionEnvironment env) { EPCompiled compiled = env.readCompile("regression/test_module_9.epl"); EPDeployment result; try { result = env.runtime().getDeploymentService().deploy(compiled); } catch (EPDeployException ex) { throw new RuntimeException(ex); } assertTrue(env.runtime().getDeploymentService().isDeployed(result.getDeploymentId())); assertNotNull(result.getDeploymentId()); assertEquals(2, result.getStatements().length); assertEquals(1, env.deployment().getDeployments().length); assertEquals("@Name(\"StmtOne\")" + NEWLINE + "create schema MyEvent(id String, val1 int, val2 int)", env.statement("StmtOne").getProperty(StatementProperty.EPL)); assertEquals("@Name(\"StmtTwo\")" + NEWLINE + "select * from MyEvent", env.statement("StmtTwo").getProperty(StatementProperty.EPL)); assertEquals(0, result.getDeploymentIdDependencies().length); env.undeployAll(); assertFalse(env.runtime().getDeploymentService().isDeployed(result.getDeploymentId())); } }
public void run(RegressionEnvironment env) { String epl = "select * from pattern[SupportBean(theString=?::string)]"; EPCompiled compiled = env.compile(epl); deployWithResolver(env, compiled, "s0", prepared -> prepared.setObject(1, "e1")); env.addListener("s0"); assertEquals(epl, env.statement("s0").getProperty(StatementProperty.EPL)); deployWithResolver(env, compiled, "s1", prepared -> prepared.setObject(1, "e2")); env.addListener("s1"); assertEquals(epl, env.statement("s1").getProperty(StatementProperty.EPL)); env.sendEventBean(new SupportBean("e2", 10)); assertFalse(env.listener("s0").isInvoked()); assertTrue(env.listener("s1").getAndClearIsInvoked()); env.sendEventBean(new SupportBean("e1", 10)); assertFalse(env.listener("s1").isInvoked()); assertTrue(env.listener("s0").getAndClearIsInvoked()); env.undeployAll(); } }
public void run(RegressionEnvironment env) { EPStatementObjectModel model = new EPStatementObjectModel(); model.setInsertInto(InsertIntoClause.create("Event_1_OMS", "delta", "product")); model.setSelectClause(SelectClause.create().add(Expressions.minus("intPrimitive", "intBoxed"), "deltaTag") .add(Expressions.multiply("intPrimitive", "intBoxed"), "productTag")); model.setFromClause(FromClause.create(FilterStream.create("SupportBean").addView(View.create("length", Expressions.constant(100))))); model = SerializableObjectCopier.copyMayFail(model); tryAssertsVariant(env, null, model, "Event_1_OMS"); String epl = "@name('fl') insert into Event_1_OMS(delta, product) " + "select intPrimitive-intBoxed as deltaTag, intPrimitive*intBoxed as productTag " + "from SupportBean#length(100)"; assertEquals(epl, model.toEPL()); assertEquals(epl, env.statement("fl").getProperty(StatementProperty.EPL)); env.undeployAll(); } }
private static void tryAssertionFromClauseBeginBodyEnd(RegressionEnvironment env, boolean soda) { RegressionPath path = new RegressionPath(); String epl = "@name('split') on OrderBean " + "insert into BeginEvent select orderdetail.orderId as orderId " + "insert into OrderItem select * from [select orderdetail.orderId as orderId, * from orderdetail.items] " + "insert into EndEvent select orderdetail.orderId as orderId " + "output all"; env.compileDeploy(soda, epl, path); assertEquals(StatementType.ON_SPLITSTREAM, env.statement("split").getProperty(StatementProperty.STATEMENTTYPE)); SupportListener[] listeners = getListeners(env); env.compileDeploy("@name('s0') select * from BeginEvent", path).addListener("s0", listeners[0]); env.compileDeploy("@name('s1') select * from OrderItem", path).addListener("s1", listeners[1]); env.compileDeploy("@name('s2') select * from EndEvent", path).addListener("s2", listeners[2]); EventType orderItemType = env.runtime().getEventTypeService().getEventType(env.deploymentId("split"), "OrderItem"); assertEquals("[amount, itemId, price, productId, orderId]", Arrays.toString(orderItemType.getPropertyNames())); env.sendEventBean(OrderBeanFactory.makeEventOne()); assertFromClauseWContained(listeners, "PO200901", new Object[][]{{"PO200901", "A001"}, {"PO200901", "A002"}, {"PO200901", "A003"}}); env.sendEventBean(OrderBeanFactory.makeEventTwo()); assertFromClauseWContained(listeners, "PO200902", new Object[][]{{"PO200902", "B001"}}); env.sendEventBean(OrderBeanFactory.makeEventFour()); assertFromClauseWContained(listeners, "PO200904", new Object[0][]); env.undeployAll(); }
public void run(RegressionEnvironment env) { String[] fields = new String[]{"p0", "p1"}; RegressionPath path = new RegressionPath(); // create window String stmtTextCreateOne = namedWindow ? "@name('create') create window MyInfra#keepall() as (p0 string, p1 int)" : "@name('create') create table MyInfra(p0 string primary key, p1 int)"; env.compileDeploy(stmtTextCreateOne, path); // create merge String stmtTextMerge = "@name('merge') on SupportBean sb merge MyInfra insert select theString as p0, intPrimitive as p1"; env.compileDeploy(stmtTextMerge, path).addListener("merge"); assertEquals(StatementType.ON_MERGE, env.statement("merge").getProperty(StatementProperty.STATEMENTTYPE)); env.milestone(0); // populate some data env.sendEventBean(new SupportBean("E1", 1)); EPAssertionUtil.assertProps(env.listener("merge").assertOneGetNewAndReset(), fields, new Object[]{"E1", 1}); EPAssertionUtil.assertPropsPerRow(env.iterator("create"), fields, new Object[][]{{"E1", 1}}); env.milestone(1); env.sendEventBean(new SupportBean("E2", 2)); EPAssertionUtil.assertProps(env.listener("merge").getLastNewData()[0], fields, new Object[]{"E2", 2}); EPAssertionUtil.assertPropsPerRowAnyOrder(env.iterator("create"), fields, new Object[][]{{"E1", 1}, {"E2", 2}}); env.undeployAll(); } }