private void processStatement(EPStatement statement) { if (statement == null) { return; } Annotation annotation = AnnotationUtil.findAnnotation(statement.getAnnotations(), KafkaOutputDefault.class); if (annotation == null) { return; } KafkaOutputDefaultListener listener = new KafkaOutputDefaultListener(runtime, statement, producer, topics); statement.addListener(listener); log.info("Added Kafka-Output-Adapter listener to statement '{}' topics {}", statement.getName(), topics.toString()); }
private void tryAssertionNoClassNameRequired(RegressionEnvironment env, SupportEnum expected, String text) { env.compileDeploy("@MyAnnotationValueEnum(supportEnum = " + text + ") @name('s0') select * from SupportBean"); MyAnnotationValueEnum anno = (MyAnnotationValueEnum) env.statement("s0").getAnnotations()[0]; assertEquals(expected, anno.supportEnum()); env.undeployAll(); } }
private static void tryAssertion(EPStatement stmt) { Annotation[] annotations = stmt.getAnnotations(); annotations = sortAlpha(annotations); assertEquals(3, annotations.length); assertEquals(Description.class, annotations[0].annotationType()); assertEquals("MyTestStmt description", ((Description) annotations[0]).value()); assertEquals("@Description(\"MyTestStmt description\")", annotations[0].toString()); assertEquals(Name.class, annotations[1].annotationType()); assertEquals("MyTestStmt", ((Name) annotations[1]).value()); assertEquals("MyTestStmt", stmt.getName()); assertEquals("@Name(\"MyTestStmt\")", annotations[1].toString()); assertEquals(Tag.class, annotations[2].annotationType()); assertEquals("UserId", ((Tag) annotations[2]).name()); assertEquals("value", ((Tag) annotations[2]).value()); assertEquals("@Tag(name=\"UserId\", value=\"value\")", annotations[2].toString()); assertFalse(annotations[2].equals(annotations[1])); TestCase.assertTrue(annotations[1].equals(annotations[1])); TestCase.assertTrue(annotations[1].hashCode() != 0); } }
private static void assertStatement(RegressionEnvironment env) { assertEquals(2, env.statement("s0").getAnnotations().length); MyAnnotationValueArray array = (MyAnnotationValueArray) env.statement("s0").getAnnotations()[0]; assertTrue(Arrays.deepEquals(toObjectArray(array.value()), new Object[]{1L, 2L, 3L})); assertTrue(Arrays.deepEquals(toObjectArray(array.intArray()), new Object[]{4, 5})); assertTrue(Arrays.deepEquals(toObjectArray(array.doubleArray()), new Object[]{})); assertTrue(Arrays.deepEquals(toObjectArray(array.stringArray()), new Object[]{"X"})); assertTrue(Arrays.deepEquals(toObjectArray(array.stringArrayDef()), new Object[]{"XYZ"})); }
public void run(RegressionEnvironment env) { String epl = "@name('abc') @Tag(name='a', value='b') @Priority(1) @Drop select * from SupportBean"; env.compileDeployAddListenerMileZero(epl, "abc"); Annotation[] annotations = env.statement("abc").getAnnotations(); assertEquals(Name.class, annotations[0].annotationType()); assertEquals("abc", ((Name) annotations[0]).value()); env.undeployAll(); } }
@MyAnnotationWArrayAndClass(priorities = {@Priority(1), @Priority(3)}, classOne = java.lang.String.class, classTwo = Integer.class) private void runNestedArray(RegressionEnvironment env) { String stmtText = "@MyAnnotationWArrayAndClass(priorities = {@Priority(1), @Priority(3)}, classOne = java.lang.String.class, classTwo = Integer.class) @name('s0') select * from SupportBean"; env.compileDeploy(stmtText); Annotation[] annotations = env.statement("s0").getAnnotations(); annotations = sortAlpha(annotations); assertEquals(2, annotations.length); MyAnnotationWArrayAndClass nested = (MyAnnotationWArrayAndClass) annotations[0]; assertEquals(1, nested.priorities()[0].value()); assertEquals(3, nested.priorities()[1].value()); assertEquals(String.class, nested.classOne()); assertEquals(Integer.class, nested.classTwo()); env.undeployAll(); } }
env.compileDeploy(stmtText); Annotation[] annotations = env.statement("STMTONE").getAnnotations(); annotations = sortAlpha(annotations); assertEquals(6, annotations.length); assertEquals(stmtTextFormatted, textFormatted); env.compileDeploy(model).addListener("STMTONE"); assertEquals(6, env.statement("STMTONE").getAnnotations().length); env.undeployAll(); env.compileDeploy(stmtText); env.statement("s0").getAnnotations(); assertStatement(env); env.undeployAll();
@MyAnnotationNested( nestableSimple = @MyAnnotationNestableSimple, nestableValues = @MyAnnotationNestableValues(val = 999, arr = {2, 1}), nestableNestable = @MyAnnotationNestableNestable("CDF")) private void runNestedSimple(RegressionEnvironment env) { String stmtText = "@MyAnnotationNested(\n" + " nestableSimple=@MyAnnotationNestableSimple,\n" + " nestableValues=@MyAnnotationNestableValues(val=999, arr={2, 1}),\n" + " nestableNestable=@MyAnnotationNestableNestable(\"CDF\")\n" + " ) " + "@name('s0') select * from SupportBean"; env.compileDeploy(stmtText); Annotation[] annotations = env.statement("s0").getAnnotations(); annotations = sortAlpha(annotations); assertEquals(2, annotations.length); MyAnnotationNested nested = (MyAnnotationNested) annotations[0]; assertNotNull(nested.nestableSimple()); TestCase.assertTrue(Arrays.deepEquals(toObjectArray(nested.nestableValues().arr()), new Object[]{2, 1})); assertEquals(999, nested.nestableValues().val()); assertEquals("CDF", nested.nestableNestable().value()); env.undeployAll(); }
env.compileDeploy(epl).addListener("MyTestStmt"); tryAssertion(env.statement("MyTestStmt")); Name name = (Name) AnnotationUtil.findAnnotation(env.statement("MyTestStmt").getAnnotations(), Name.class); assertEquals("MyTestStmt", name.value()); env.undeployAll(); env.compileDeploy("@Hint(' iterate_only ') select * from SupportBean"); Annotation[] annos = env.compileDeploy("@Hint('DISABLE_RECLAIM_GROUP') @name('s0') select * from SupportBean").statement("s0").getAnnotations(); assertEquals("DISABLE_RECLAIM_GROUP", HintEnum.DISABLE_RECLAIM_GROUP.getHint(annos).value()); annos = env.compileDeploy("@Hint('ITERATE_ONLY,ITERATE_ONLY,DISABLE_RECLAIM_GROUP,ITERATE_ONLY') @name('s1') select * from SupportBean").statement("s1").getAnnotations(); assertEquals("ITERATE_ONLY,ITERATE_ONLY,DISABLE_RECLAIM_GROUP,ITERATE_ONLY", HintEnum.DISABLE_RECLAIM_GROUP.getHint(annos).value()); annos = env.compileDeploy("@Hint('ITERATE_ONLY,reclaim_group_aged=10') @name('s2') select * from SupportBean").statement("s2").getAnnotations(); Hint hint = HintEnum.RECLAIM_GROUP_AGED.getHint(annos); assertEquals("10", HintEnum.RECLAIM_GROUP_AGED.getHintAssignedValue(hint)); annos = env.compileDeploy("@Hint('reclaim_group_aged=11') @name('s3') select * from SupportBean").statement("s3").getAnnotations(); hint = HintEnum.RECLAIM_GROUP_AGED.getHint(annos); assertEquals("11", HintEnum.RECLAIM_GROUP_AGED.getHintAssignedValue(hint)); annos = env.compileDeploy("@Hint('index(one, two)') @name('s4') select * from SupportBean").statement("s4").getAnnotations(); assertEquals("one, two", HintEnum.INDEX.getHintAssignedValues(annos).get(0)); assertEquals(1, AnnotationUtil.findAnnotations(env.statement("s0").getAnnotations(), NoLock.class).size());
boolean drop = false; Annotation[] annotations = statement.getAnnotations(); for (Annotation anno : annotations) { if (anno instanceof Hint) {
public void run(RegressionEnvironment env) { MyUserObjectRuntimeOption.getContexts().clear(); String epl = "@name('s0') select * from SupportBean"; EPCompiled compiled = env.compile(epl); DeploymentOptions options = new DeploymentOptions(); options.setStatementUserObjectRuntime(new MyUserObjectRuntimeOption()); try { env.deployment().deploy(compiled, options); } catch (EPDeployException e) { fail(e.getMessage()); } StatementUserObjectRuntimeContext ctx = MyUserObjectRuntimeOption.getContexts().get(0); assertEquals("s0", ctx.getStatementName()); assertEquals(env.deploymentId("s0"), ctx.getDeploymentId()); assertSame(env.statement("s0").getAnnotations(), ctx.getAnnotations()); assertEquals(epl, ctx.getEpl()); env.undeployAll(); } }
public void run(RegressionEnvironment env) { MyStatementNameRuntimeResolver.getContexts().clear(); String epl = "@name('s0') select * from SupportBean"; EPCompiled compiled = env.compile(epl); DeploymentOptions options = new DeploymentOptions(); options.setStatementNameRuntime(new MyStatementNameRuntimeResolver()); try { env.deployment().deploy(compiled, options); } catch (EPDeployException e) { fail(e.getMessage()); } StatementNameRuntimeContext ctx = MyStatementNameRuntimeResolver.getContexts().get(0); assertEquals("s0", ctx.getStatementName()); assertEquals(env.deploymentId("hello"), ctx.getDeploymentId()); assertSame(env.statement("hello").getAnnotations(), ctx.getAnnotations()); assertEquals(epl, ctx.getEpl()); assertEquals("hello", env.statement("hello").getName()); env.milestone(0); assertEquals("hello", env.statement("hello").getName()); env.undeployAll(); } }
public void run(RegressionEnvironment env) { // The following EPL syntax compiles but fails to match a string "A'B", we are looking into: // env.compileDeploy("@name('s0') select * from SupportBean(string='A\\\'B')"); tryEscapeMatch(env, "A'B", "\"A'B\""); // opposite quotes tryEscapeMatch(env, "A'B", "'A\\'B'"); // escape ' tryEscapeMatch(env, "A'B", "'A\\u0027B'"); // unicode tryEscapeMatch(env, "A\"B", "'A\"B'"); // opposite quotes tryEscapeMatch(env, "A\"B", "'A\\\"B'"); // escape " tryEscapeMatch(env, "A\"B", "'A\\u0022B'"); // unicode env.compileDeploy("@Name('A\\\'B') @Description(\"A\\\"B\") select * from SupportBean"); Assert.assertEquals("A\'B", env.statement("A\'B").getName()); Description desc = (Description) env.statement("A\'B").getAnnotations()[1]; Assert.assertEquals("A\"B", desc.value()); env.undeployAll(); env.compileDeploy("@name('s0') select 'volume' as field1, \"sleep\" as field2, \"\\u0041\" as unicodeA from SupportBean"); env.addListener("s0"); env.sendEventBean(new SupportBean()); EPAssertionUtil.assertProps(env.listener("s0").assertOneGetNewAndReset(), new String[]{"field1", "field2", "unicodeA"}, new Object[]{"volume", "sleep", "A"}); env.undeployAll(); tryStatementMatch(env, "John's", "select * from SupportBean(theString='John\\'s')"); tryStatementMatch(env, "John's", "select * from SupportBean(theString='John\\u0027s')"); tryStatementMatch(env, "Quote \"Hello\"", "select * from SupportBean(theString like \"Quote \\\"Hello\\\"\")"); tryStatementMatch(env, "Quote \"Hello\"", "select * from SupportBean(theString like \"Quote \\u0022Hello\\u0022\")"); env.undeployAll(); }