private static void compileDeployWSubstitution(RegressionEnvironment env, String epl, Map<String, Object> params) { EPCompiled compiled = env.compile("@name('s0') " + epl); StatementSubstitutionParameterOption resolver = ctx -> { for (Map.Entry<String, Object> entry : params.entrySet()) { ctx.setObject(entry.getKey(), entry.getValue()); } }; env.deploy(compiled, new DeploymentOptions().setStatementSubstitutionParameter(resolver)); env.addListener("s0"); }
private static void deployWithResolver(RegressionEnvironment env, EPCompiled compiled, String statementName, StatementSubstitutionParameterOption resolver) { DeploymentOptions options = new DeploymentOptions().setStatementSubstitutionParameter(resolver); options.setStatementNameRuntime(context -> statementName); try { env.deployment().deploy(compiled, options); } catch (EPDeployException e) { throw new RuntimeException(e); } }
public void run(RegressionEnvironment env) { String expression = "@name('s0') select * from pattern [every timer:at(?::int,?::int,*,*,[1,2,3,4,5])]"; Calendar cal = GregorianCalendar.getInstance(); cal.set(Calendar.MILLISECOND, 0); cal.set(2008, 7, 3, 10, 0, 0); // start on a Sunday at 6am, August 3 2008 sendTimer(cal.getTimeInMillis(), env); EPCompiled compiled = env.compile(expression); env.deploy(compiled, new DeploymentOptions().setStatementSubstitutionParameter(prepared -> { prepared.setObject(1, 0); prepared.setObject(2, 8); })); env.addListener("s0"); tryAssertion(env); env.undeployAll(); } }
private static void tryInvalidResolver(RegressionEnvironment env, EPCompiled compiled, String expected, StatementSubstitutionParameterOption resolver) { DeploymentOptions options = new DeploymentOptions().setStatementSubstitutionParameter(resolver); try { env.deployment().deploy(compiled, options); fail(); } catch (EPDeploySubstitutionParameterException e) { SupportMessageAssertUtil.assertMessage(e.getMessage(), expected); } catch (EPDeployException e) { throw new RuntimeException(e); } }
public void run(RegressionEnvironment env) { EPCompiled compiled; DeploymentOptions options; // numbered, typed compiled = env.compile("select * from SupportBean(theString=?::string)"); options = new DeploymentOptions().setStatementSubstitutionParameter(prepared -> { tryInvalidSetObject(prepared, stmt -> stmt.setObject(1, 10), "Failed to set substitution parameter 1, expected a value of type 'java.lang.String': " + SupportJavaVersionUtil.getCastMessage(Integer.class, String.class)); prepared.setObject(1, "abc"); }); deployWithOptionsWUndeploy(env, compiled, options); // name, typed compiled = env.compile("select * from SupportBean(theString=?:p0:string)"); options = new DeploymentOptions().setStatementSubstitutionParameter(prepared -> { tryInvalidSetObject(prepared, stmt -> stmt.setObject("p0", 10), "Failed to set substitution parameter 'p0', expected a value of type 'java.lang.String': " + SupportJavaVersionUtil.getCastMessage(Integer.class, String.class)); prepared.setObject("p0", "abc"); }); deployWithOptionsWUndeploy(env, compiled, options); // name, primitive compiled = env.compile("select * from SupportBean(intPrimitive=?:p0:int)"); options = new DeploymentOptions().setStatementSubstitutionParameter(prepared -> { // There is only boxed type consistent with all other column/variable/schema typing: // tryInvalidSetObject(prepared, stmt -> stmt.setObject("p0", null), "Failed to set substitution parameter 'p0', expected a value of type 'int': Received a null-value for a primitive type"); prepared.setObject("p0", 10); }); deployWithOptionsWUndeploy(env, compiled, options); } }
public void run(RegressionEnvironment env) { env.advanceTime(0); String text = "select rstream theString from SupportBean#time(?::int)"; EPCompiled compiled = env.compile(text); env.deploy(compiled, new DeploymentOptions() .setStatementSubstitutionParameter(prepared -> prepared.setObject(1, 4)) .setStatementNameRuntime(ctx -> "s0")); env.deploy(compiled, new DeploymentOptions() .setStatementSubstitutionParameter(prepared -> prepared.setObject(1, 3)) .setStatementNameRuntime(ctx -> "s1")); env.addListener("s0").addListener("s1"); runAssertion(env); env.undeployAll(); } }
public void run(RegressionEnvironment env) { EPCompiled compiled; DeploymentOptions options; compiled = env.compile("select * from SupportBean(theString='ABC')"); options = new DeploymentOptions().setStatementSubstitutionParameter(prepared -> { tryInvalidSetObject(prepared, stmt -> stmt.setObject("x", 10), "The statement has no substitution parameters"); tryInvalidSetObject(prepared, stmt -> stmt.setObject(1, 10), "The statement has no substitution parameters"); }); deployWithOptionsWUndeploy(env, compiled, options); // numbered, untyped, casted at eventService compiled = env.compile("select * from SupportBean(theString=cast(?, String))"); options = new DeploymentOptions().setStatementSubstitutionParameter(prepared -> { tryInvalidSetObject(prepared, stmt -> stmt.setObject("x", 10), "Substitution parameter names have not been provided for this statement"); tryInvalidSetObject(prepared, stmt -> stmt.setObject(0, "a"), "Invalid substitution parameter index, expected an index between 1 and 1"); tryInvalidSetObject(prepared, stmt -> stmt.setObject(2, "a"), "Invalid substitution parameter index, expected an index between 1 and 1"); prepared.setObject(1, "xxx"); }); deployWithOptionsWUndeploy(env, compiled, options); // named, untyped, casted at eventService compiled = env.compile("select * from SupportBean(theString=cast(?:p0, String))"); options = new DeploymentOptions().setStatementSubstitutionParameter(prepared -> { tryInvalidSetObject(prepared, stmt -> stmt.setObject("x", 10), "Failed to find substitution parameter named 'x', available parameters are [p0]"); tryInvalidSetObject(prepared, stmt -> stmt.setObject(0, "a"), "Substitution parameter names have been provided for this statement, please set the value by name"); prepared.setObject("p0", "xxx"); }); deployWithOptionsWUndeploy(env, compiled, options); } }
public void run(RegressionEnvironment env) { String stmtText = "@name('s0') select intPrimitive in (?::int[primitive]) as result from SupportBean"; EPCompiled compiled = env.compile(stmtText); env.deploy(compiled, new DeploymentOptions().setStatementSubstitutionParameter(prepared -> prepared.setObject(1, new int[]{10, 20, 30}))); env.addListener("s0"); env.sendEventBean(new SupportBean("E1", 10), SupportBean.class.getSimpleName()); assertTrue((Boolean) env.listener("s0").assertOneGetNewAndReset().get("result")); env.sendEventBean(new SupportBean("E2", 9), SupportBean.class.getSimpleName()); assertFalse((Boolean) env.listener("s0").assertOneGetNewAndReset().get("result")); env.undeployAll(); } }
public void run(RegressionEnvironment env) { MySubstitutionOption.getContexts().clear(); EPCompiled compiled = env.compile("@name('s0') select ?:p0:int as c0 from SupportBean"); DeploymentOptions options = new DeploymentOptions().setStatementSubstitutionParameter(new MySubstitutionOption()); options.setDeploymentId("abc"); try { env.deployment().deploy(compiled, options); fail(); } catch (EPDeployException e) { // expected } assertEquals(1, MySubstitutionOption.getContexts().size()); StatementSubstitutionParameterContext ctx = MySubstitutionOption.getContexts().get(0); assertNotNull(ctx.getAnnotations()); assertEquals("abc", ctx.getDeploymentId()); assertNotNull(ctx.getEpl()); assertTrue(ctx.getStatementId() > 0); assertEquals("s0", ctx.getStatementName()); assertEquals(Integer.class, ctx.getSubstitutionParameterTypes()[0]); assertEquals((Integer) 1, ctx.getSubstitutionParameterNames().get("p0")); } }
public void run(RegressionEnvironment env) { // External clocking sendTimer(0, env); // Set up a timer:within EPCompiled compiled = env.compile("@name('s0') select * from pattern [(every SupportBean) where timer:within(?::int days ?::int hours ?::int minutes ?::int seconds ?::int milliseconds)]"); env.deploy(compiled, new DeploymentOptions().setStatementSubstitutionParameter(prepared -> { prepared.setObject(1, 1); prepared.setObject(2, 2); prepared.setObject(3, 3); prepared.setObject(4, 4); prepared.setObject(5, 5); })); env.addListener("s0"); tryAssertion(env); env.undeployAll(); } }
public void run(RegressionEnvironment env) { // External clocking sendTimer(0, env); // Set up a timer:within EPCompiled compiled = env.compile("@name('s0') select * from pattern [timer:interval(?::int minute ?::int seconds)]"); env.deploy(compiled, new DeploymentOptions().setStatementSubstitutionParameter(prepared -> { prepared.setObject(1, 1); prepared.setObject(2, 2); })); env.addListener("s0"); sendTimer(62 * 1000 - 1, env); assertFalse(env.listener("s0").isInvoked()); sendTimer(62 * 1000, env); assertTrue(env.listener("s0").isInvoked()); env.undeployAll(); } }
public void run(RegressionEnvironment env) { EPCompiled compiled = env.compile("expression myindex {pointregionquadtree(0, 0, 100, 100)}" + "select * from SupportSpatialAABB(point(?::int, ?::int, filterindex:myindex).inside(rectangle(x, y, width, height)))"); SupportUpdateListener listener = new SupportUpdateListener(); int count = 0; for (int x = 0; x < 10; x++) { for (int y = 0; y < 10; y++) { int finalX = x; int finalY = y; String name = x + "_" + y; DeploymentOptions options = new DeploymentOptions().setStatementSubstitutionParameter(prepared -> { prepared.setObject(1, finalX); prepared.setObject(2, finalY); }).setStatementNameRuntime(ctx -> name); env.deploy(compiled, options).statement(name).addListener(listener); // System.out.println("Deployed #" + count); count++; } } sendAssertSpatialAABB(env, listener, 10, 10, 1000); env.undeployAll(); } }
private static void trySubstitutionParameter(RegressionEnvironment env, String substitution, Object parameter) { EPCompiled compiled = env.compile("@name('s0') select * from SupportBean(" + substitution + ".sequenceEqual({1, intPrimitive, 100}))"); env.deploy(compiled, new DeploymentOptions().setStatementSubstitutionParameter(prepared -> prepared.setObject(1, parameter))); env.addListener("s0"); env.sendEventBean(new SupportBean("E1", 10)); assertTrue(env.listener("s0").getAndClearIsInvoked()); env.sendEventBean(new SupportBean("E2", 20)); assertFalse(env.listener("s0").getAndClearIsInvoked()); env.undeployAll(); }
public void run(RegressionEnvironment env) { String epl = "@name('s0') select * from SupportBean_S0(id=?:subs_1:int);\n" + "@name('s1') select * from SupportBean_S1(p10=?:subs_2:string);\n"; EPCompiled compiled = env.compile(epl); DeploymentOptions options = new DeploymentOptions().setStatementSubstitutionParameter(new StatementSubstitutionParameterOption() { public void setStatementParameters(StatementSubstitutionParameterContext env) { if (env.getStatementName().equals("s1")) { env.setObject("subs_2", "abc"); } else { env.setObject("subs_1", 100); } } }); try { env.deployment().deploy(compiled, options); } catch (EPDeployException e) { throw new RuntimeException(e); } env.addListener("s0").addListener("s1"); env.sendEventBean(new SupportBean_S1(-1, "abc")); assertTrue(env.listener("s1").isInvoked()); env.sendEventBean(new SupportBean_S0(100)); assertTrue(env.listener("s0").isInvoked()); env.undeployAll(); } }
public void run(RegressionEnvironment env) { String epl = "@name('s0') select * from SupportBean(intPrimitive in (1, 10))"; env.compileDeployAddListenerMile(epl, "s0", 0); sendBeanInt(env, 10); assertTrue(env.listener("s0").getAndClearIsInvoked()); sendBeanInt(env, 11); assertFalse(env.listener("s0").getAndClearIsInvoked()); sendBeanInt(env, 1); assertTrue(env.listener("s0").getAndClearIsInvoked()); env.undeployAll(); // try enum collection with substitution param Set<SupportEnum> types = new HashSet<>(); types.add(SupportEnum.ENUM_VALUE_2); EPCompiled compiled = env.compile("@name('s0') select * from SupportBean ev " + "where ev.enumValue in (?::java.util.Collection)"); env.deploy(compiled, new DeploymentOptions().setStatementSubstitutionParameter(prepared -> prepared.setObject(1, types))); env.addListener("s0"); SupportBean theEvent = new SupportBean(); theEvent.setEnumValue(SupportEnum.ENUM_VALUE_2); env.sendEventBean(theEvent); assertTrue(env.listener("s0").isInvoked()); env.undeployAll(); } }
DeploymentOptions options = new DeploymentOptions().setStatementSubstitutionParameter(new StatementSubstitutionParameterOption() { public void setStatementParameters(StatementSubstitutionParameterContext env) { env.setObject("a0", new Integer[]{1, 2});
env.deploy(compiled, new DeploymentOptions().setStatementSubstitutionParameter(prepared -> prepared.setObject(1, 2))); env.undeployAll();