public void testAfterNextRow() { Configuration config = SupportConfigFactory.getConfiguration(); config.addEventType("MyEvent", SupportRecogBean.class); EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(config); epService.initialize(); String[] fields = "a,b0,b1".split(","); String text = "select * from MyEvent.win:keepall() " + "match_recognize (" + " measures A.theString as a, B[0].theString as b0, B[1].theString as b1" + " AFTER MATCH SKIP TO NEXT ROW " + " pattern (A B*) " + " define " + " A as A.theString like 'A%'," + " B as B.theString like 'B%'" + ")"; EPStatement stmt = epService.getEPAdministrator().createEPL(text); SupportUpdateListener listener = new SupportUpdateListener(); stmt.addListener(listener); epService.getEPRuntime().sendEvent(new SupportRecogBean("A1", 1)); EPAssertionUtil.assertPropsPerRow( listener.getAndResetLastNewData(), fields, new Object[][] {{"A1", null, null}}); EPAssertionUtil.assertPropsPerRow(stmt.iterator(), fields, new Object[][] {{"A1", null, null}}); // since the first match skipped past A, we do not match again epService.getEPRuntime().sendEvent(new SupportRecogBean("B1", 2)); assertFalse(listener.isInvoked()); // incremental skips to next EPAssertionUtil.assertPropsPerRow(stmt.iterator(), fields, new Object[][] {{"A1", "B1", null}}); }
private void configureImport() { // the single-row functions to be called are in this class provider.getEPAdministrator().getConfiguration().addImport(this.getClass()); // Add an event type that has a byte-type property value Map<String, Object> typeDefinition = new HashMap<String, Object>(); typeDefinition.put("byteValue", byte.class); provider.getEPAdministrator().getConfiguration().addEventType("MyByteEvent", typeDefinition); // keep the last few events from the variant stream EPStatement stmt = provider .getEPAdministrator() .createEPL( "select RuntimeConfigMain.check2BitSet(byteValue) as check2BitSet from MyByteEvent"); // send an event Map<String, Object> eventData = new HashMap<String, Object>(); eventData.put("byteValue", 2); provider.getEPRuntime().sendEvent(eventData, "MyByteEvent"); // print results System.out.println("\nConfigure Import:"); System.out.println("Received:" + " check2BitSet=" + stmt.iterator().next().get("check2BitSet")); // send a second event eventData = new HashMap<String, Object>(); eventData.put("byteValue", 1); provider.getEPRuntime().sendEvent(eventData, "MyByteEvent"); // print results System.out.println("Received:" + " check2BitSet=" + stmt.iterator().next().get("check2BitSet")); }
private void runAssertion( EPServiceProvider epService, SupportUpdateListener listener, EPStatement stmt) { String[] fields = "a,b0,b1".split(","); epService.getEPRuntime().sendEvent(new SupportRecogBean("A1", 1)); EPAssertionUtil.assertPropsPerRow( listener.getAndResetLastNewData(), fields, new Object[][] {{"A1", null, null}}); EPAssertionUtil.assertPropsPerRow(stmt.iterator(), fields, new Object[][] {{"A1", null, null}}); // since the first match skipped past A, we do not match again epService.getEPRuntime().sendEvent(new SupportRecogBean("B1", 2)); EPAssertionUtil.assertPropsPerRow( listener.getAndResetLastNewData(), fields, new Object[][] {{"A1", "B1", null}}); EPAssertionUtil.assertPropsPerRow(stmt.iterator(), fields, new Object[][] {{"A1", "B1", null}}); }
public void testObjectArrayNested() { EPServiceProvider epService = getEngineInitialized(null, null, null); epService .getEPAdministrator() .getConfiguration() .addEventType("TypeLev1", new String[] {"p1id"}, new Object[] {int.class}); epService .getEPAdministrator() .getConfiguration() .addEventType( "TypeLev0", new String[] {"p0id", "p1"}, new Object[] {int.class, "TypeLev1"}); epService .getEPAdministrator() .getConfiguration() .addEventType( "TypeRoot", new String[] {"rootId", "p0"}, new Object[] {int.class, "TypeLev0"}); EPStatement stmt = epService.getEPAdministrator().createEPL("select * from TypeRoot.std:lastevent()"); Object[] dataLev1 = {1000}; Object[] dataLev0 = {100, dataLev1}; epService.getEPRuntime().sendEvent(new Object[] {10, dataLev0}, "TypeRoot"); EventBean theEvent = stmt.iterator().next(); EPAssertionUtil.assertProps( theEvent, "rootId,p0.p0id,p0.p1.p1id".split(","), new Object[] {10, 100, 1000}); }
public void testJoinSelect() { String eventA = SupportBean.class.getName(); String eventB = SupportBean.class.getName(); String joinStatement = "select s0.doubleBoxed, s1.intPrimitive*s1.intBoxed/2.0 as div from " + eventA + "(theString='s0').win:length(3) as s0," + eventB + "(theString='s1').win:length(3) as s1" + " where s0.doubleBoxed = s1.doubleBoxed"; EPStatement joinView = epService.getEPAdministrator().createEPL(joinStatement); joinView.addListener(updateListener); EventType result = joinView.getEventType(); assertEquals(Double.class, result.getPropertyType("s0.doubleBoxed")); assertEquals(Double.class, result.getPropertyType("div")); assertEquals(2, joinView.getEventType().getPropertyNames().length); assertNull(updateListener.getLastNewData()); sendEvent("s0", 1, 4, 5); sendEvent("s1", 1, 3, 2); EventBean[] newEvents = updateListener.getLastNewData(); assertEquals(1d, newEvents[0].get("s0.doubleBoxed")); assertEquals(3d, newEvents[0].get("div")); Iterator<EventBean> iterator = joinView.iterator(); EventBean theEvent = iterator.next(); assertEquals(1d, theEvent.get("s0.doubleBoxed")); assertEquals(3d, theEvent.get("div")); }
private void configureVariables() { provider.getEPAdministrator().getConfiguration().addVariable("myintvar", int.class, 5); EPStatement stmt = provider .getEPAdministrator() .createEPL("select propertyOne, propertyTwo, myintvar from MyEvent"); // send an event Map<String, Object> eventData = new HashMap<String, Object>(); eventData.put("propertyOne", "value"); eventData.put("propertyTwo", 10); provider.getEPRuntime().sendEvent(eventData, "MyEvent"); // the statement above keeps the last event for iterating EventBean received = stmt.iterator().next(); System.out.println("\nConfigure Variables:"); System.out.println( "Received:" + " propertyOne=" + received.get("propertyOne") + " propertyTwo=" + received.get("propertyTwo") + " myintvar=" + received.get("myintvar")); }
private void configureVariantStream() { ConfigurationVariantStream variantStream = new ConfigurationVariantStream(); variantStream.setTypeVariance( ConfigurationVariantStream.TypeVariance .ANY); // allow any type of event to be inserted into the stream // add variant stream provider .getEPAdministrator() .getConfiguration() .addVariantStream("MyVariantStream", variantStream); // keep the last few events from the variant stream EPStatement stmt = provider.getEPAdministrator().createEPL("select * from MyVariantStream.win:time(1 min)"); // insert MyEvent events into the variant stream provider.getEPAdministrator().createEPL("insert into MyVariantStream select * from MyEvent"); // Add a second event type Map<String, Object> typeDefinition = new HashMap<String, Object>(); typeDefinition.put("propertyOther", String.class); provider.getEPAdministrator().getConfiguration().addEventType("MyOtherEvent", typeDefinition); // insert MyOtherEvent events into the variant stream provider .getEPAdministrator() .createEPL("insert into MyVariantStream select * from MyOtherEvent"); // send some events Map<String, Object> eventData = new HashMap<String, Object>(); eventData.put("propertyOne", "value"); eventData.put("propertyTwo", 10); provider.getEPRuntime().sendEvent(eventData, "MyEvent"); eventData = new HashMap<String, Object>(); eventData.put("propertyOther", "test"); provider.getEPRuntime().sendEvent(eventData, "MyOtherEvent"); // print results System.out.println("\nConfigure Variant Stream:"); Iterator<EventBean> iterator = stmt.iterator(); EventBean first = iterator.next(); System.out.println( "Received (1):" + " propertyOne=" + first.get("propertyOne") + " propertyOther=" + first.get("propertyOther")); EventBean second = iterator.next(); System.out.println( "Received (2):" + " propertyOne=" + second.get("propertyOne") + " propertyOther=" + second.get("propertyOther")); }
private void runAssertionIterateCreateTable( Object[][] expectedType, Object[] rowValues, EPStatement stmtCreate) { assertEventTypeAndEvent( stmtCreate.getEventType(), expectedType, stmtCreate.iterator().next().getUnderlying(), rowValues); }
public void testVariableMoreThenOnce() { Configuration config = SupportConfigFactory.getConfiguration(); config.addEventType("MyEvent", SupportRecogBean.class); EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(config); epService.initialize(); String[] fields = "a0,b,a1".split(","); String text = "select * from MyEvent.win:keepall() " + "match_recognize (" + " measures A[0].theString as a0, B.theString as b, A[1].theString as a1 " + " all matches " + " after match skip to next row " + " pattern ( A B A ) " + " define " + " A as (A.value = 1)," + " B as (B.value = 2)" + ")"; EPStatement stmt = epService.getEPAdministrator().createEPL(text); SupportUpdateListener listener = new SupportUpdateListener(); stmt.addListener(listener); epService.getEPRuntime().sendEvent(new SupportRecogBean("E1", 3)); epService.getEPRuntime().sendEvent(new SupportRecogBean("E2", 1)); epService.getEPRuntime().sendEvent(new SupportRecogBean("E3", 2)); epService.getEPRuntime().sendEvent(new SupportRecogBean("E4", 5)); epService.getEPRuntime().sendEvent(new SupportRecogBean("E5", 1)); epService.getEPRuntime().sendEvent(new SupportRecogBean("E6", 2)); assertFalse(listener.isInvoked()); assertFalse(stmt.iterator().hasNext()); epService.getEPRuntime().sendEvent(new SupportRecogBean("E7", 1)); EPAssertionUtil.assertPropsPerRow( listener.getAndResetLastNewData(), fields, new Object[][] {{"E5", "E6", "E7"}}); EPAssertionUtil.assertPropsPerRow(stmt.iterator(), fields, new Object[][] {{"E5", "E6", "E7"}}); epService.getEPRuntime().sendEvent(new SupportRecogBean("E8", 2)); epService.getEPRuntime().sendEvent(new SupportRecogBean("E9", 1)); EPAssertionUtil.assertPropsPerRow( listener.getAndResetLastNewData(), fields, new Object[][] {{"E7", "E8", "E9"}}); EPAssertionUtil.assertPropsPerRow( stmt.iterator(), fields, new Object[][] {{"E5", "E6", "E7"}, {"E7", "E8", "E9"}}); }
public static final void readNamedWindow(EPServiceProvider provider) { EPStatement statement = provider .getEPAdministrator() .createEPL(properties.getProperty("deposit.window.named1.select")); Iterator<EventBean> iterator = statement.iterator(); while (iterator.hasNext()) { EventBean bean = iterator.next(); System.out.println(bean.get("accountName")); } }
private void runAssertionPerformance(boolean namedWindow, EventRepresentationEnum outputType) { String eplCreate = namedWindow ? outputType.getAnnotationText() + " create window MyWindow.win:keepall() as (c1 string, c2 int)" : "create table MyWindow(c1 string primary key, c2 int)"; EPStatement stmtNamedWindow = epService.getEPAdministrator().createEPL(eplCreate); assertEquals(outputType.getOutputClass(), stmtNamedWindow.getEventType().getUnderlyingType()); // preload events EPStatement stmt = epService .getEPAdministrator() .createEPL( "insert into MyWindow select theString as c1, intPrimitive as c2 from SupportBean"); final int totalUpdated = 5000; for (int i = 0; i < totalUpdated; i++) { epService.getEPRuntime().sendEvent(new SupportBean("E" + i, 0)); } stmt.destroy(); String epl = "on SupportBean sb merge MyWindow nw where nw.c1 = sb.theString " + "when matched then update set nw.c2=sb.intPrimitive"; stmt = epService.getEPAdministrator().createEPL(epl); stmt.addListener(mergeListener); // prime for (int i = 0; i < 100; i++) { epService.getEPRuntime().sendEvent(new SupportBean("E" + i, 1)); } long startTime = System.currentTimeMillis(); for (int i = 0; i < totalUpdated; i++) { epService.getEPRuntime().sendEvent(new SupportBean("E" + i, 1)); } long endTime = System.currentTimeMillis(); long delta = endTime - startTime; // verify Iterator<EventBean> events = stmtNamedWindow.iterator(); int count = 0; for (; events.hasNext(); ) { EventBean next = events.next(); assertEquals(1, next.get("c2")); count++; } assertEquals(totalUpdated, count); assertTrue("Delta=" + delta, delta < 500); epService.getEPAdministrator().destroyAllStatements(); epService.getEPAdministrator().getConfiguration().removeEventType("MyWindow", true); }
private void configureSingleRowFunction() { // define a single-row median function provided by this class provider .getEPAdministrator() .getConfiguration() .addPlugInSingleRowFunction("mymedian", this.getClass().getName(), "computeDoubleMedian"); // Add an event type that has a double-array -type property value Map<String, Object> typeDefinition = new HashMap<String, Object>(); typeDefinition.put("doubles", double[].class); provider .getEPAdministrator() .getConfiguration() .addEventType("MyMedianSampleEvent", typeDefinition); // keep the last few events from the variant stream EPStatement stmt = provider .getEPAdministrator() .createEPL("select mymedian(doubles) as med from MyMedianSampleEvent"); // send an event Map<String, Object> eventData = new HashMap<String, Object>(); eventData.put("doubles", new double[] {5, 1, 2, 3, 4}); provider.getEPRuntime().sendEvent(eventData, "MyMedianSampleEvent"); // print results System.out.println("\nConfigure Single-Row Function:"); System.out.println("Received:" + " med=" + stmt.iterator().next().get("med")); // send a second event eventData = new HashMap<String, Object>(); eventData.put("doubles", new double[] {5, 1, 2, 3, 4, 4}); provider.getEPRuntime().sendEvent(eventData, "MyMedianSampleEvent"); // print results System.out.println("Received:" + " med=" + stmt.iterator().next().get("med")); }
private void configureCustomAggregationFunction() { // define a append-string aggregation function provided by another class provider .getEPAdministrator() .getConfiguration() .addPlugInAggregationFunction("concat", MyConcatAggregationFunction.class.getName()); // Add an event type that has a string-type property value Map<String, Object> typeDefinition = new HashMap<String, Object>(); typeDefinition.put("str", String.class); provider .getEPAdministrator() .getConfiguration() .addEventType("MyConcatSampleEvent", typeDefinition); // keep the last few events from the variant stream EPStatement stmt = provider .getEPAdministrator() .createEPL("select concat(str) as cstr from MyConcatSampleEvent"); // send an event Map<String, Object> eventData = new HashMap<String, Object>(); eventData.put("str", "part1"); provider.getEPRuntime().sendEvent(eventData, "MyConcatSampleEvent"); // print results System.out.println("\nConfigure Aggregation Function:"); System.out.println("Received:" + " cstr=" + stmt.iterator().next().get("cstr")); // send a second event eventData = new HashMap<String, Object>(); eventData.put("str", "part2"); provider.getEPRuntime().sendEvent(eventData, "MyConcatSampleEvent"); // print results System.out.println("Received:" + " cstr=" + stmt.iterator().next().get("cstr")); }
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(); }
public void testReclaimAgedHint() { epService.getEPRuntime().sendEvent(new CurrentTimeEvent(0)); epService .getEPAdministrator() .getConfiguration() .addEventType("SupportBean", SupportBean.class); String epl = "@Hint('reclaim_group_aged=5,reclaim_group_freq=1') " + "select * from SupportBean.std:groupwin(theString).win:keepall()"; EPStatement stmt = epService.getEPAdministrator().createEPL(epl); int maxSlots = 10; int maxEventsPerSlot = 1000; for (int timeSlot = 0; timeSlot < maxSlots; timeSlot++) { epService.getEPRuntime().sendEvent(new CurrentTimeEvent(timeSlot * 1000 + 1)); for (int i = 0; i < maxEventsPerSlot; i++) { epService.getEPRuntime().sendEvent(new SupportBean("E" + timeSlot, 0)); } } EventBean[] iterator = EPAssertionUtil.iteratorToArray(stmt.iterator()); assertTrue(iterator.length <= 6 * maxEventsPerSlot); }
public void testRevision() { EPStatement consumerOne = epService.getEPAdministrator().createEPL("select * from RevQuote"); consumerOne.addListener(listenerOne); EPStatement consumerTwo = epService .getEPAdministrator() .createEPL( "select k0, count(*) as count, sum(Long.parseLong(p0)) as sum from RevQuote group by k0"); consumerTwo.addListener(listenerTwo); EPStatement consumerThree = epService.getEPAdministrator().createEPL("select * from RevQuote output every 2 events"); consumerThree.addListener(listenerThree); String[] agg = "k0,count,sum".split(","); epService .getEPRuntime() .sendEvent(new SupportRevisionFull("k00", "01", "p10", "20", "p30", "40", "50")); ArrayAssertionUtil.assertProps( listenerOne.assertOneGetNewAndReset(), fields, new Object[] {"k00", "01", "p10", "20", "p30", "40", "50"}); ArrayAssertionUtil.assertProps( stmtCreateWin.iterator().next(), fields, new Object[] {"k00", "01", "p10", "20", "p30", "40", "50"}); ArrayAssertionUtil.assertProps( listenerTwo.assertOneGetNewAndReset(), agg, new Object[] {"k00", 1L, 1L}); assertFalse(listenerThree.isInvoked()); epService.getEPRuntime().sendEvent(new SupportDeltaThree("k00", "03", "41")); ArrayAssertionUtil.assertProps( listenerOne.assertOneGetNewAndReset(), fields, new Object[] {"k00", "03", "p10", "20", "p30", "41", "50"}); ArrayAssertionUtil.assertProps( stmtCreateWin.iterator().next(), fields, new Object[] {"k00", "03", "p10", "20", "p30", "41", "50"}); ArrayAssertionUtil.assertProps( listenerTwo.assertOneGetNewAndReset(), agg, new Object[] {"k00", 1L, 3L}); ArrayAssertionUtil.assertProps( listenerThree.getLastNewData()[0], fields, new Object[] {"k00", "01", "p10", "20", "p30", "40", "50"}); ArrayAssertionUtil.assertProps( listenerThree.getLastNewData()[1], fields, new Object[] {"k00", "03", "p10", "20", "p30", "41", "50"}); listenerThree.reset(); epService.getEPRuntime().sendEvent(new SupportDeltaOne("k00", "p11", "51")); ArrayAssertionUtil.assertProps( listenerOne.assertOneGetNewAndReset(), fields, new Object[] {"k00", "03", "p11", "20", "p30", "41", "51"}); ArrayAssertionUtil.assertProps( stmtCreateWin.iterator().next(), fields, new Object[] {"k00", "03", "p11", "20", "p30", "41", "51"}); ArrayAssertionUtil.assertProps( listenerTwo.assertOneGetNewAndReset(), agg, new Object[] {"k00", 1L, 3L}); assertFalse(listenerThree.isInvoked()); epService.getEPRuntime().sendEvent(new SupportDeltaTwo("k00", "04", "21", "p31")); ArrayAssertionUtil.assertProps( listenerOne.assertOneGetNewAndReset(), fields, new Object[] {"k00", "04", "p11", "21", "p31", "41", "51"}); ArrayAssertionUtil.assertProps( stmtCreateWin.iterator().next(), fields, new Object[] {"k00", "04", "p11", "21", "p31", "41", "51"}); ArrayAssertionUtil.assertProps( listenerTwo.assertOneGetNewAndReset(), agg, new Object[] {"k00", 1L, 4L}); ArrayAssertionUtil.assertProps( listenerThree.getLastNewData()[0], fields, new Object[] {"k00", "03", "p11", "20", "p30", "41", "51"}); ArrayAssertionUtil.assertProps( listenerThree.getLastNewData()[1], fields, new Object[] {"k00", "04", "p11", "21", "p31", "41", "51"}); listenerThree.reset(); epService.getEPRuntime().sendEvent(new SupportDeltaFour("k00", "05", "22", "52")); ArrayAssertionUtil.assertProps( listenerOne.assertOneGetNewAndReset(), fields, new Object[] {"k00", "05", "p11", "22", "p31", "41", "52"}); ArrayAssertionUtil.assertProps( stmtCreateWin.iterator().next(), fields, new Object[] {"k00", "05", "p11", "22", "p31", "41", "52"}); ArrayAssertionUtil.assertProps( listenerTwo.assertOneGetNewAndReset(), agg, new Object[] {"k00", 1L, 5L}); assertFalse(listenerThree.isInvoked()); epService.getEPRuntime().sendEvent(new SupportDeltaFive("k00", "p12", "53")); ArrayAssertionUtil.assertProps( listenerOne.assertOneGetNewAndReset(), fields, new Object[] {"k00", "05", "p12", "22", "p31", "41", "53"}); ArrayAssertionUtil.assertProps( stmtCreateWin.iterator().next(), fields, new Object[] {"k00", "05", "p12", "22", "p31", "41", "53"}); ArrayAssertionUtil.assertProps( listenerTwo.assertOneGetNewAndReset(), agg, new Object[] {"k00", 1L, 5L}); ArrayAssertionUtil.assertProps( listenerThree.getLastNewData()[0], fields, new Object[] {"k00", "05", "p11", "22", "p31", "41", "52"}); ArrayAssertionUtil.assertProps( listenerThree.getLastNewData()[1], fields, new Object[] {"k00", "05", "p12", "22", "p31", "41", "53"}); listenerThree.reset(); epService .getEPRuntime() .sendEvent(new SupportRevisionFull("k00", "06", "p13", "23", "p32", "42", "54")); ArrayAssertionUtil.assertProps( listenerOne.assertOneGetNewAndReset(), fields, new Object[] {"k00", "06", "p13", "23", "p32", "42", "54"}); ArrayAssertionUtil.assertProps( stmtCreateWin.iterator().next(), fields, new Object[] {"k00", "06", "p13", "23", "p32", "42", "54"}); ArrayAssertionUtil.assertProps( listenerTwo.assertOneGetNewAndReset(), agg, new Object[] {"k00", 1L, 6L}); assertFalse(listenerThree.isInvoked()); epService.getEPRuntime().sendEvent(new SupportDeltaOne("k00", "p14", "55")); ArrayAssertionUtil.assertProps( listenerOne.assertOneGetNewAndReset(), fields, new Object[] {"k00", "06", "p14", "23", "p32", "42", "55"}); ArrayAssertionUtil.assertProps( stmtCreateWin.iterator().next(), fields, new Object[] {"k00", "06", "p14", "23", "p32", "42", "55"}); ArrayAssertionUtil.assertProps( listenerTwo.assertOneGetNewAndReset(), agg, new Object[] {"k00", 1L, 6L}); ArrayAssertionUtil.assertProps( listenerThree.getLastNewData()[0], fields, new Object[] {"k00", "06", "p13", "23", "p32", "42", "54"}); ArrayAssertionUtil.assertProps( listenerThree.getLastNewData()[1], fields, new Object[] {"k00", "06", "p14", "23", "p32", "42", "55"}); listenerThree.reset(); }
public void testStats() { EPAdministrator epAdmin = epService.getEPAdministrator(); String filter = "select * from " + SupportMarketDataBean.class.getName(); EPStatement priceLast3Stats = epAdmin.createEPL(filter + ".std:groupwin(symbol).win:length(3).stat:uni(price)"); priceLast3Stats.addListener(priceLast3StatsListener); EPStatement volumeLast3Stats = epAdmin.createEPL(filter + ".std:groupwin(symbol).win:length(3).stat:uni(volume)"); volumeLast3Stats.addListener(volumeLast3StatsListener); EPStatement priceAllStats = epAdmin.createEPL(filter + ".std:groupwin(symbol).stat:uni(price)"); priceAllStats.addListener(priceAllStatsListener); EPStatement volumeAllStats = epAdmin.createEPL(filter + ".std:groupwin(symbol).stat:uni(volume)"); volumeAllStats.addListener(volumeAllStatsListener); Vector<Map<String, Object>> expectedList = new Vector<Map<String, Object>>(); for (int i = 0; i < 3; i++) { expectedList.add(new HashMap<String, Object>()); } sendEvent(SYMBOL_CISCO, 25, 50000); sendEvent(SYMBOL_CISCO, 26, 60000); sendEvent(SYMBOL_IBM, 10, 8000); sendEvent(SYMBOL_IBM, 10.5, 8200); sendEvent(SYMBOL_GE, 88, 1000); EPAssertionUtil.assertPropsPerRow( priceLast3StatsListener.getLastNewData(), makeMap(SYMBOL_GE, 88)); EPAssertionUtil.assertPropsPerRow( priceAllStatsListener.getLastNewData(), makeMap(SYMBOL_GE, 88)); EPAssertionUtil.assertPropsPerRow( volumeLast3StatsListener.getLastNewData(), makeMap(SYMBOL_GE, 1000)); EPAssertionUtil.assertPropsPerRow( volumeAllStatsListener.getLastNewData(), makeMap(SYMBOL_GE, 1000)); sendEvent(SYMBOL_CISCO, 27, 70000); sendEvent(SYMBOL_CISCO, 28, 80000); EPAssertionUtil.assertPropsPerRow( priceAllStatsListener.getLastNewData(), makeMap(SYMBOL_CISCO, 26.5d)); EPAssertionUtil.assertPropsPerRow( volumeAllStatsListener.getLastNewData(), makeMap(SYMBOL_CISCO, 65000d)); EPAssertionUtil.assertPropsPerRow( priceLast3StatsListener.getLastNewData(), makeMap(SYMBOL_CISCO, 27d)); EPAssertionUtil.assertPropsPerRow( volumeLast3StatsListener.getLastNewData(), makeMap(SYMBOL_CISCO, 70000d)); sendEvent(SYMBOL_IBM, 11, 8700); sendEvent(SYMBOL_IBM, 12, 8900); EPAssertionUtil.assertPropsPerRow( priceAllStatsListener.getLastNewData(), makeMap(SYMBOL_IBM, 10.875d)); EPAssertionUtil.assertPropsPerRow( volumeAllStatsListener.getLastNewData(), makeMap(SYMBOL_IBM, 8450d)); EPAssertionUtil.assertPropsPerRow( priceLast3StatsListener.getLastNewData(), makeMap(SYMBOL_IBM, 11d + 1 / 6d)); EPAssertionUtil.assertPropsPerRow( volumeLast3StatsListener.getLastNewData(), makeMap(SYMBOL_IBM, 8600d)); sendEvent(SYMBOL_GE, 85.5, 950); sendEvent(SYMBOL_GE, 85.75, 900); sendEvent(SYMBOL_GE, 89, 1250); sendEvent(SYMBOL_GE, 86, 1200); sendEvent(SYMBOL_GE, 85, 1150); double averageGE = (88d + 85.5d + 85.75d + 89d + 86d + 85d) / 6d; EPAssertionUtil.assertPropsPerRow( priceAllStatsListener.getLastNewData(), makeMap(SYMBOL_GE, averageGE)); EPAssertionUtil.assertPropsPerRow( volumeAllStatsListener.getLastNewData(), makeMap(SYMBOL_GE, 1075d)); EPAssertionUtil.assertPropsPerRow( priceLast3StatsListener.getLastNewData(), makeMap(SYMBOL_GE, 86d + 2d / 3d)); EPAssertionUtil.assertPropsPerRow( volumeLast3StatsListener.getLastNewData(), makeMap(SYMBOL_GE, 1200d)); // Check iterator results expectedList.get(0).put("symbol", SYMBOL_CISCO); expectedList.get(0).put("average", 26.5d); expectedList.get(1).put("symbol", SYMBOL_IBM); expectedList.get(1).put("average", 10.875d); expectedList.get(2).put("symbol", SYMBOL_GE); expectedList.get(2).put("average", averageGE); EPAssertionUtil.assertPropsPerRow(priceAllStats.iterator(), expectedList); expectedList.get(0).put("symbol", SYMBOL_CISCO); expectedList.get(0).put("average", 27d); expectedList.get(1).put("symbol", SYMBOL_IBM); expectedList.get(1).put("average", 11d + 1 / 6d); expectedList.get(2).put("symbol", SYMBOL_GE); expectedList.get(2).put("average", 86d + 2d / 3d); EPAssertionUtil.assertPropsPerRow(priceLast3Stats.iterator(), expectedList); }
public void testIterateStatement() { epService .getEPAdministrator() .createEPL("create context PartitionedByString partition by theString from SupportBean"); String[] fields = "c0,c1".split(","); EPStatement stmt = epService .getEPAdministrator() .createEPL( "@Name('StmtOne') context PartitionedByString select context.key1 as c0, sum(intPrimitive) as c1 from SupportBean.win:length(5)"); epService.getEPRuntime().sendEvent(new SupportBean("E1", 10)); epService.getEPRuntime().sendEvent(new SupportBean("E2", 20)); epService.getEPRuntime().sendEvent(new SupportBean("E2", 21)); Object[][] expectedAll = new Object[][] {{"E1", 10}, {"E2", 41}}; EPAssertionUtil.assertPropsPerRow(stmt.iterator(), stmt.safeIterator(), fields, expectedAll); // test iterator ALL ContextPartitionSelector selector = ContextPartitionSelectorAll.INSTANCE; EPAssertionUtil.assertPropsPerRow( stmt.iterator(selector), stmt.safeIterator(selector), fields, expectedAll); // test iterator by context partition id selector = new SupportSelectorById(new HashSet<Integer>(Arrays.asList(0, 1, 2))); EPAssertionUtil.assertPropsPerRow( stmt.iterator(selector), stmt.safeIterator(selector), fields, expectedAll); selector = new SupportSelectorById(new HashSet<Integer>(Arrays.asList(1))); EPAssertionUtil.assertPropsPerRow( stmt.iterator(selector), stmt.safeIterator(selector), fields, new Object[][] {{"E2", 41}}); assertFalse(stmt.iterator(new SupportSelectorById(Collections.<Integer>emptySet())).hasNext()); assertFalse(stmt.iterator(new SupportSelectorById(null)).hasNext()); try { stmt.iterator(null); fail(); } catch (IllegalArgumentException ex) { assertEquals(ex.getMessage(), "No selector provided"); } try { stmt.safeIterator(null); fail(); } catch (IllegalArgumentException ex) { assertEquals(ex.getMessage(), "No selector provided"); } EPStatement stmtTwo = epService.getEPAdministrator().createEPL("select * from java.lang.Object"); try { stmtTwo.iterator(null); fail(); } catch (UnsupportedOperationException ex) { assertEquals( ex.getMessage(), "Iterator with context selector is only supported for statements under context"); } try { stmtTwo.safeIterator(null); fail(); } catch (UnsupportedOperationException ex) { assertEquals( ex.getMessage(), "Iterator with context selector is only supported for statements under context"); } }
private void configureRevisionType() { // Declare two types: a base type and an update type // Define a type for the base events Map<String, Object> baseTypeDef = new HashMap<String, Object>(); baseTypeDef.put("itemId", "string"); baseTypeDef.put("category", "string"); baseTypeDef.put("description", "string"); baseTypeDef.put("price", "double"); provider.getEPAdministrator().getConfiguration().addEventType("MyBaseEvent", baseTypeDef); // Define a type for the update/delta events Map<String, Object> updateTypeDef = new HashMap<String, Object>(); updateTypeDef.put("itemId", "string"); updateTypeDef.put("price", "double"); // price is updated provider.getEPAdministrator().getConfiguration().addEventType("MyUpdateEvent", updateTypeDef); // Define revision event type ConfigurationRevisionEventType config = new ConfigurationRevisionEventType(); config.setKeyPropertyNames(new String[] {"itemId"}); config.addNameBaseEventType("MyBaseEvent"); config.addNameDeltaEventType("MyUpdateEvent"); provider.getEPAdministrator().getConfiguration().addRevisionEventType("MyRevisionType", config); // Create a statement to keep the last event per item EPStatement stmt = provider .getEPAdministrator() .createEPL("create window ItemWindow.std:unique(itemId) select * from MyRevisionType"); provider.getEPAdministrator().createEPL("insert into ItemWindow select * from MyBaseEvent"); provider.getEPAdministrator().createEPL("insert into ItemWindow select * from MyUpdateEvent"); // Send some base events and some update events Map<String, Object> baseEvent1 = makeBaseEvent("item1", "stockorder", "GE 100", 20d); provider.getEPRuntime().sendEvent(baseEvent1, "MyBaseEvent"); Map<String, Object> baseEvent2 = makeBaseEvent("item2", "basketorder", "Basket of IBM-100 MSFT-200", 25d); provider.getEPRuntime().sendEvent(baseEvent2, "MyBaseEvent"); Map<String, Object> updateEvent1 = makeUpdateEvent("item1", 21.05d); provider.getEPRuntime().sendEvent(updateEvent1, "MyUpdateEvent"); Map<String, Object> updateEvent2 = makeUpdateEvent("item2", 24.95d); provider.getEPRuntime().sendEvent(updateEvent2, "MyUpdateEvent"); // print results System.out.println("\nConfigure Revision Type:"); Iterator<EventBean> iterator = stmt.iterator(); EventBean first = iterator.next(); System.out.println( "Received (1):" + " itemId=" + first.get("itemId") + " category=" + first.get("category") + " price=" + first.get("price")); EventBean second = iterator.next(); System.out.println( "Received (2):" + " itemId=" + second.get("itemId") + " category=" + second.get("category") + " price=" + second.get("price")); }
public void testOnDelete() { EPStatement consumerOne = epService.getEPAdministrator().createEPL("select irstream * from RevQuote"); consumerOne.addListener(listenerOne); epService .getEPAdministrator() .createEPL("on SupportBean(intPrimitive=2) as sb delete from RevQuote where string = p2"); log("a00"); epService .getEPRuntime() .sendEvent(new SupportRevisionFull("a", "a00", "a10", "a20", "a30", "a40", "a50")); ArrayAssertionUtil.assertProps( listenerOne.assertOneGetNewAndReset(), fields, new Object[] {"a", "a00", "a10", "a20", "a30", "a40", "a50"}); epService.getEPRuntime().sendEvent(new SupportDeltaThree("x", "03", "41")); assertFalse(listenerOne.isInvoked()); epService .getEPAdministrator() .createEPL("on SupportBean(intPrimitive=3) as sb delete from RevQuote where string = p3"); log("b00"); epService .getEPRuntime() .sendEvent(new SupportRevisionFull("b", "b00", "b10", "b20", "b30", "b40", "b50")); ArrayAssertionUtil.assertProps( listenerOne.assertOneGetNewAndReset(), fields, new Object[] {"b", "b00", "b10", "b20", "b30", "b40", "b50"}); log("a01"); epService.getEPRuntime().sendEvent(new SupportDeltaThree("a", "a01", "a41")); ArrayAssertionUtil.assertProps( listenerOne.getLastNewData()[0], fields, new Object[] {"a", "a01", "a10", "a20", "a30", "a41", "a50"}); ArrayAssertionUtil.assertProps( listenerOne.getLastOldData()[0], fields, new Object[] {"a", "a00", "a10", "a20", "a30", "a40", "a50"}); listenerOne.reset(); log("c00"); epService .getEPRuntime() .sendEvent(new SupportRevisionFull("c", "c00", "c10", "c20", "c30", "c40", "c50")); ArrayAssertionUtil.assertProps( listenerOne.assertOneGetNewAndReset(), fields, new Object[] {"c", "c00", "c10", "c20", "c30", "c40", "c50"}); epService .getEPAdministrator() .createEPL("on SupportBean(intPrimitive=0) as sb delete from RevQuote where string = p0"); log("c11"); epService.getEPRuntime().sendEvent(new SupportDeltaFive("c", "c11", "c51")); ArrayAssertionUtil.assertProps( listenerOne.getLastNewData()[0], fields, new Object[] {"c", "c00", "c11", "c20", "c30", "c40", "c51"}); ArrayAssertionUtil.assertProps( listenerOne.getLastOldData()[0], fields, new Object[] {"c", "c00", "c10", "c20", "c30", "c40", "c50"}); listenerOne.reset(); epService .getEPAdministrator() .createEPL("on SupportBean(intPrimitive=1) as sb delete from RevQuote where string = p1"); log("d00"); epService .getEPRuntime() .sendEvent(new SupportRevisionFull("d", "d00", "d10", "d20", "d30", "d40", "d50")); ArrayAssertionUtil.assertProps( listenerOne.assertOneGetNewAndReset(), fields, new Object[] {"d", "d00", "d10", "d20", "d30", "d40", "d50"}); log("d01"); epService.getEPRuntime().sendEvent(new SupportDeltaFour("d", "d01", "d21", "d51")); ArrayAssertionUtil.assertProps( listenerOne.getLastNewData()[0], fields, new Object[] {"d", "d01", "d10", "d21", "d30", "d40", "d51"}); ArrayAssertionUtil.assertProps( listenerOne.getLastOldData()[0], fields, new Object[] {"d", "d00", "d10", "d20", "d30", "d40", "d50"}); listenerOne.reset(); ArrayAssertionUtil.assertEqualsExactOrder( stmtCreateWin.iterator(), fields, new Object[][] { {"b", "b00", "b10", "b20", "b30", "b40", "b50"}, {"a", "a01", "a10", "a20", "a30", "a41", "a50"}, {"c", "c00", "c11", "c20", "c30", "c40", "c51"}, {"d", "d01", "d10", "d21", "d30", "d40", "d51"} }); epService .getEPAdministrator() .createEPL("on SupportBean(intPrimitive=4) as sb delete from RevQuote where string = p4"); epService.getEPRuntime().sendEvent(new SupportBean("abc", 1)); assertFalse(listenerOne.isInvoked()); log("delete b"); epService.getEPRuntime().sendEvent(new SupportBean("b40", 4)); // delete b ArrayAssertionUtil.assertProps( listenerOne.assertOneGetOldAndReset(), fields, new Object[] {"b", "b00", "b10", "b20", "b30", "b40", "b50"}); ArrayAssertionUtil.assertEqualsExactOrder( stmtCreateWin.iterator(), fields, new Object[][] { {"a", "a01", "a10", "a20", "a30", "a41", "a50"}, {"c", "c00", "c11", "c20", "c30", "c40", "c51"}, {"d", "d01", "d10", "d21", "d30", "d40", "d51"} }); log("delete d"); epService.getEPRuntime().sendEvent(new SupportBean("d21", 2)); // delete d ArrayAssertionUtil.assertProps( listenerOne.assertOneGetOldAndReset(), fields, new Object[] {"d", "d01", "d10", "d21", "d30", "d40", "d51"}); ArrayAssertionUtil.assertEqualsExactOrder( stmtCreateWin.iterator(), fields, new Object[][] { {"a", "a01", "a10", "a20", "a30", "a41", "a50"}, {"c", "c00", "c11", "c20", "c30", "c40", "c51"} }); log("delete a"); epService.getEPRuntime().sendEvent(new SupportBean("a30", 3)); // delete a ArrayAssertionUtil.assertProps( listenerOne.assertOneGetOldAndReset(), fields, new Object[] {"a", "a01", "a10", "a20", "a30", "a41", "a50"}); ArrayAssertionUtil.assertEqualsExactOrder( stmtCreateWin.iterator(), fields, new Object[][] {{"c", "c00", "c11", "c20", "c30", "c40", "c51"}}); log("delete c"); epService.getEPRuntime().sendEvent(new SupportBean("c11", 1)); // delete c ArrayAssertionUtil.assertProps( listenerOne.assertOneGetOldAndReset(), fields, new Object[] {"c", "c00", "c11", "c20", "c30", "c40", "c51"}); ArrayAssertionUtil.assertEqualsExactOrder(stmtCreateWin.iterator(), fields, null); epService.getEPRuntime().sendEvent(new SupportBean("c11", 1)); assertFalse(listenerOne.isInvoked()); }