public void testStartStopStatement() { String stmtText = "select id from S0 where (select true from S1.win:length(1000))"; EPStatement stmt = epService.getEPAdministrator().createEPL(stmtText); stmt.addListener(listener); epService.getEPRuntime().sendEvent(new SupportBean_S0(2)); assertFalse(listener.isInvoked()); epService.getEPRuntime().sendEvent(new SupportBean_S1(10)); epService.getEPRuntime().sendEvent(new SupportBean_S0(2)); assertEquals(2, listener.assertOneGetNewAndReset().get("id")); stmt.stop(); epService.getEPRuntime().sendEvent(new SupportBean_S0(2)); assertFalse(listener.isInvoked()); stmt.start(); epService.getEPRuntime().sendEvent(new SupportBean_S0(2)); assertFalse(listener.isInvoked()); epService.getEPRuntime().sendEvent(new SupportBean_S1(10)); epService.getEPRuntime().sendEvent(new SupportBean_S0(3)); assertEquals(3, listener.assertOneGetNewAndReset().get("id")); }
public void testSkipToNextRow() { Configuration config = SupportConfigFactory.getConfiguration(); config.addEventType("MyEvent", SupportRecogBean.class); EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(config); epService.initialize(); String[] fields = "a_string,b_string".split(","); String text = "select * from MyEvent.win:keepall() " + "match_recognize (" + " measures A.theString as a_string, B.theString as b_string " + " all matches " + " after match skip to next row " + " pattern (A B) " + " define B as B.value > A.value" + ") " + "order by a_string, b_string"; EPStatement stmt = epService.getEPAdministrator().createEPL(text); SupportUpdateListener listener = new SupportUpdateListener(); stmt.addListener(listener); epService.getEPRuntime().sendEvent(new SupportRecogBean("E1", 5)); epService.getEPRuntime().sendEvent(new SupportRecogBean("E2", 3)); assertFalse(listener.isInvoked()); assertFalse(stmt.iterator().hasNext()); epService.getEPRuntime().sendEvent(new SupportRecogBean("E3", 6)); EPAssertionUtil.assertPropsPerRow( listener.getAndResetLastNewData(), fields, new Object[][] {{"E2", "E3"}}); EPAssertionUtil.assertPropsPerRow(stmt.iterator(), fields, new Object[][] {{"E2", "E3"}}); epService.getEPRuntime().sendEvent(new SupportRecogBean("E4", 4)); assertFalse(listener.isInvoked()); EPAssertionUtil.assertPropsPerRow(stmt.iterator(), fields, new Object[][] {{"E2", "E3"}}); epService.getEPRuntime().sendEvent(new SupportRecogBean("E5", 6)); EPAssertionUtil.assertPropsPerRow( listener.getAndResetLastNewData(), fields, new Object[][] {{"E4", "E5"}}); EPAssertionUtil.assertPropsPerRow( stmt.iterator(), fields, new Object[][] {{"E2", "E3"}, {"E4", "E5"}}); epService.getEPRuntime().sendEvent(new SupportRecogBean("E6", 10)); EPAssertionUtil.assertPropsPerRow( listener.getAndResetLastNewData(), fields, new Object[][] {{"E5", "E6"}}); EPAssertionUtil.assertPropsPerRow( stmt.iterator(), fields, new Object[][] {{"E2", "E3"}, {"E4", "E5"}, {"E5", "E6"}}); epService.getEPRuntime().sendEvent(new SupportRecogBean("E7", 9)); epService.getEPRuntime().sendEvent(new SupportRecogBean("E8", 4)); assertFalse(listener.isInvoked()); EPAssertionUtil.assertPropsPerRow( stmt.iterator(), fields, new Object[][] {{"E2", "E3"}, {"E4", "E5"}, {"E5", "E6"}}); stmt.stop(); }
private void runAssertion( boolean enableIndexShareCreate, boolean disableIndexShareConsumer, boolean createExplicitIndex) { SupportUpdateListener listener = new SupportUpdateListener(); epService .getEPAdministrator() .getConfiguration() .addEventType("SupportBean", SupportBean.class); epService.getEPAdministrator().getConfiguration().addEventType("S0", SupportBean_S0.class); String createEpl = "create window SupportWindow.win:keepall() as select * from SupportBean"; if (enableIndexShareCreate) { createEpl = "@Hint('enable_window_subquery_indexshare') " + createEpl; } epService.getEPAdministrator().createEPL(createEpl); epService.getEPAdministrator().createEPL("insert into SupportWindow select * from SupportBean"); EPStatement indexStmt = null; if (createExplicitIndex) { indexStmt = epService .getEPAdministrator() .createEPL("create index MyIndex on SupportWindow(theString)"); } epService.getEPRuntime().sendEvent(new SupportBean("E1", 1)); epService.getEPRuntime().sendEvent(new SupportBean("E2", -2)); String consumeEpl = "select (select intPrimitive from SupportWindow(intPrimitive<0) sw where s0.p00=sw.theString) as val from S0 s0"; if (disableIndexShareConsumer) { consumeEpl = "@Hint('disable_window_subquery_indexshare') " + consumeEpl; } EPStatement consumeStmt = epService.getEPAdministrator().createEPL(consumeEpl); consumeStmt.addListener(listener); epService.getEPRuntime().sendEvent(new SupportBean_S0(10, "E1")); assertEquals(null, listener.assertOneGetNewAndReset().get("val")); epService.getEPRuntime().sendEvent(new SupportBean_S0(20, "E2")); assertEquals(-2, listener.assertOneGetNewAndReset().get("val")); epService.getEPRuntime().sendEvent(new SupportBean("E3", -3)); epService.getEPRuntime().sendEvent(new SupportBean("E4", 4)); epService.getEPRuntime().sendEvent(new SupportBean_S0(-3, "E3")); assertEquals(-3, listener.assertOneGetNewAndReset().get("val")); epService.getEPRuntime().sendEvent(new SupportBean_S0(20, "E4")); assertEquals(null, listener.assertOneGetNewAndReset().get("val")); consumeStmt.stop(); if (indexStmt != null) { indexStmt.stop(); } consumeStmt.destroy(); if (indexStmt != null) { indexStmt.destroy(); } }