private void runAssertionSubquerySelectStar(Object[] rowValues) { String eplFiltered = "select (select * from MyTable where key = 'G1') as mt from SupportBean_S2"; runAssertionSubquerySelectStar(rowValues, eplFiltered); String eplUnfiltered = "select (select * from MyTable) as mt from SupportBean_S2"; runAssertionSubquerySelectStar(rowValues, eplUnfiltered); // With @eventbean String eplEventBean = "select (select * from MyTable) @eventbean as mt from SupportBean_S2"; EPStatement stmt = epService.getEPAdministrator().createEPL(eplEventBean); stmt.addListener(listener); assertEquals(Object[][].class, stmt.getEventType().getPropertyType("mt")); assertSame( getTablePublicType("MyTable"), stmt.getEventType().getFragmentType("mt").getFragmentType()); epService.getEPRuntime().sendEvent(new SupportBean_S2(0)); EventBean event = listener.assertOneGetNewAndReset(); Object[][] value = (Object[][]) event.get("mt"); assertEventUnd(value[0], rowValues); assertSame( getTablePublicType("MyTable"), ((EventBean[]) event.getFragment("mt"))[0].getEventType()); stmt.destroy(); }
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 runAssertionSingleRowFunc(Object[] rowValues) { // try join passing of params String eplJoin = "select " + this.getClass().getName() + ".myServiceEventBean(mt) as c0, " + this.getClass().getName() + ".myServiceObjectArray(mt) as c1 " + "from SupportBean_S2, MyTable as mt"; EPStatement stmtJoin = epService.getEPAdministrator().createEPL(eplJoin); stmtJoin.addListener(listener); epService.getEPRuntime().sendEvent(new SupportBean_S2(0)); EventBean result = listener.assertOneGetNewAndReset(); assertEventUnd(result.get("c0"), rowValues); assertEventUnd(result.get("c1"), rowValues); stmtJoin.destroy(); // try subquery epService .getEPAdministrator() .getConfiguration() .addPlugInSingleRowFunction( "pluginServiceEventBean", this.getClass().getName(), "myServiceEventBean"); String eplSubquery = "select (select pluginServiceEventBean(mt) from MyTable as mt) as c0 " + "from SupportBean_S2"; EPStatement stmtSubquery = epService.getEPAdministrator().createEPL(eplSubquery); stmtSubquery.addListener(listener); epService.getEPRuntime().sendEvent(new SupportBean_S2(0)); result = listener.assertOneGetNewAndReset(); assertEventUnd(result.get("c0"), rowValues); stmtSubquery.destroy(); }
private void runAssertionOnSelectWindowAgg(Object[][] expectedType, Object[] rowValues) { EPStatement stmt = epService .getEPAdministrator() .createEPL( "on SupportBean_S2 select " + "window(win.*) as c0," + "last(win.*) as c1, " + "first(win.*) as c2, " + "first(p1) as c3," + "window(p1) as c4," + "sorted(p1) as c5," + "minby(p1) as c6" + " from MyTable as win"); stmt.addListener(listener); epService.getEPRuntime().sendEvent(new SupportBean_S2(0)); EventBean event = listener.assertOneGetNewAndReset(); for (String col : "c1,c2,c6".split(",")) { assertEventUnd(event.get(col), rowValues); } for (String col : "c0,c5".split(",")) { assertEventUnd(((Object[][]) event.get(col))[0], rowValues); } assertEquals("b", event.get("c3")); EPAssertionUtil.assertEqualsExactOrder(new String[] {"b"}, (String[]) event.get("c4")); stmt.destroy(); }
public void testSchemaXMLWSchemaWithRestriction() throws Exception { Configuration config = SupportConfigFactory.getConfiguration(); ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM(); eventTypeMeta.setRootElementName("order"); InputStream schemaStream = TestSchemaXMLEvent.class .getClassLoader() .getResourceAsStream(CLASSLOADER_SCHEMA_WITH_RESTRICTION_URI); assertNotNull(schemaStream); String schemaText = ParserTool.linesToText(ParserTool.readFile(schemaStream)); eventTypeMeta.setSchemaText(schemaText); config.addEventType("OrderEvent", eventTypeMeta); epService = EPServiceProviderManager.getProvider("TestSchemaXML", config); epService.initialize(); updateListener = new SupportUpdateListener(); String text = "select order_amount from OrderEvent"; EPStatement stmt = epService.getEPAdministrator().createEPL(text); stmt.addListener(updateListener); SupportXML.sendEvent( epService.getEPRuntime(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<order>\n" + "<order_amount>202.1</order_amount>" + "</order>"); EventBean theEvent = updateListener.getLastNewData()[0]; assertEquals(Double.class, theEvent.get("order_amount").getClass()); assertEquals(202.1d, theEvent.get("order_amount")); updateListener.reset(); }
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")); }
public void update(EventBean[] newEvents, EventBean[] oldEvents) { if (newEvents != null) { System.out.println("\nResult: "); for (EventBean eb : newEvents) { System.out.println("a=" + eb.get("a") + " b=" + eb.get("b")); } System.out.println(); } }
public void update(EventBean[] newEvents, EventBean[] oldEvents) { if (newEvents != null) { System.out.println(); System.out.println("Trigger On Select:"); System.out.println("There is " + newEvents.length + " OnUpdateEvent in OnUpdateWindow!"); for (EventBean eb : newEvents) { System.out.println(eb.getUnderlying()); } } }
@Override public void update(EventBean[] newEvents, EventBean[] oldEvents) { if (newEvents != null) { for (EventBean eb : newEvents) { System.out.println(eb.getUnderlying()); } } else { System.out.println("newEvent is null"); } }
public void testInsertIntoPlusPattern() { String stmtOneTxt = "insert into InZone " + "select 111 as statementId, mac, locationReportId " + "from " + SupportRFIDEvent.class.getName() + " " + "where mac in ('1','2','3') " + "and zoneID = '10'"; EPStatement stmtOne = epService.getEPAdministrator().createEPL(stmtOneTxt); SupportUpdateListener listenerOne = new SupportUpdateListener(); stmtOne.addListener(listenerOne); String stmtTwoTxt = "insert into OutOfZone " + "select 111 as statementId, mac, locationReportId " + "from " + SupportRFIDEvent.class.getName() + " " + "where mac in ('1','2','3') " + "and zoneID != '10'"; EPStatement stmtTwo = epService.getEPAdministrator().createEPL(stmtTwoTxt); SupportUpdateListener listenerTwo = new SupportUpdateListener(); stmtTwo.addListener(listenerTwo); String stmtThreeTxt = "select 111 as eventSpecId, A.locationReportId as locationReportId " + " from pattern [every A=InZone -> (timer:interval(1 sec) and not OutOfZone(mac=A.mac))]"; EPStatement stmtThree = epService.getEPAdministrator().createEPL(stmtThreeTxt); SupportUpdateListener listener = new SupportUpdateListener(); stmtThree.addListener(listener); // try the alert case with 1 event for the mac in question epService.getEPRuntime().sendEvent(new CurrentTimeEvent(0)); epService.getEPRuntime().sendEvent(new SupportRFIDEvent("LR1", "1", "10")); assertFalse(listener.isInvoked()); epService.getEPRuntime().sendEvent(new CurrentTimeEvent(1000)); EventBean theEvent = listener.assertOneGetNewAndReset(); assertEquals("LR1", theEvent.get("locationReportId")); listenerOne.reset(); listenerTwo.reset(); // try the alert case with 2 events for zone 10 within 1 second for the mac in question epService.getEPRuntime().sendEvent(new SupportRFIDEvent("LR2", "2", "10")); assertFalse(listener.isInvoked()); epService.getEPRuntime().sendEvent(new CurrentTimeEvent(1500)); epService.getEPRuntime().sendEvent(new SupportRFIDEvent("LR3", "2", "10")); assertFalse(listener.isInvoked()); epService.getEPRuntime().sendEvent(new CurrentTimeEvent(2000)); theEvent = listener.assertOneGetNewAndReset(); assertEquals("LR2", theEvent.get("locationReportId")); }
public void testSchemaXMLWSchemaWithAll() throws Exception { Configuration config = SupportConfigFactory.getConfiguration(); ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM(); eventTypeMeta.setRootElementName("event-page-visit"); String schemaUri = TestSchemaXMLEvent.class .getClassLoader() .getResource(CLASSLOADER_SCHEMA_WITH_ALL_URI) .toString(); eventTypeMeta.setSchemaResource(schemaUri); eventTypeMeta.addNamespacePrefix("ss", "samples:schemas:simpleSchemaWithAll"); eventTypeMeta.addXPathProperty("url", "/ss:event-page-visit/ss:url", XPathConstants.STRING); config.addEventType("PageVisitEvent", eventTypeMeta); epService = EPServiceProviderManager.getProvider("TestSchemaXML", config); epService.initialize(); updateListener = new SupportUpdateListener(); // url='page4' String text = "select a.url as sesja from pattern [ every a=PageVisitEvent(url='page1') ]"; EPStatement stmt = epService.getEPAdministrator().createEPL(text); stmt.addListener(updateListener); SupportXML.sendEvent( epService.getEPRuntime(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<event-page-visit xmlns=\"samples:schemas:simpleSchemaWithAll\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"samples:schemas:simpleSchemaWithAll simpleSchemaWithAll.xsd\">\n" + "<url>page1</url>" + "</event-page-visit>"); EventBean theEvent = updateListener.getLastNewData()[0]; assertEquals("page1", theEvent.get("sesja")); updateListener.reset(); SupportXML.sendEvent( epService.getEPRuntime(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<event-page-visit xmlns=\"samples:schemas:simpleSchemaWithAll\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"samples:schemas:simpleSchemaWithAll simpleSchemaWithAll.xsd\">\n" + "<url>page2</url>" + "</event-page-visit>"); assertFalse(updateListener.isInvoked()); EventType type = epService.getEPAdministrator().createEPL("select * from PageVisitEvent").getEventType(); EPAssertionUtil.assertEqualsAnyOrder( new Object[] { new EventPropertyDescriptor( "sessionId", Node.class, null, false, false, false, false, true), new EventPropertyDescriptor( "customerId", Node.class, null, false, false, false, false, true), new EventPropertyDescriptor("url", String.class, null, false, false, false, false, false), new EventPropertyDescriptor("method", Node.class, null, false, false, false, false, true), }, type.getPropertyDescriptors()); }
private void runAssertionSubquerySelectStar(Object[] rowValues, String epl) { EPStatement stmt = epService.getEPAdministrator().createEPL(epl); stmt.addListener(listener); assertEquals(Object[].class, stmt.getEventType().getPropertyType("mt")); epService.getEPRuntime().sendEvent(new SupportBean_S2(0)); EventBean event = listener.assertOneGetNewAndReset(); assertEventUnd(event.get("mt"), rowValues); stmt.destroy(); }
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); }
@SuppressWarnings("deprecation") @SuppressLint("NewApi") @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.mainfragment, container, false); screenWidth = getActivity().getWindowManager().getDefaultDisplay().getWidth(); event = (EventBean) getActivity().getApplicationContext(); mTabHost = (TabHost) v.findViewById(android.R.id.tabhost); hs = (HorizontalScrollView) v.findViewById(R.id.horizontalScrollView1); mViewPager = (ViewPager) v.findViewById(R.id.pager); categories = event.getCategories(); events_upcoming = event.getObject(); category_id = new ArrayList<Integer>(); category_name = new ArrayList<String>(); initialiseTabHost(); List<Fragment> fragments = getFragments(); pageAdapter = new MyPageAdapter(getFragmentManager(), fragments); mViewPager.setOffscreenPageLimit(1); mViewPager.setAdapter(pageAdapter); mViewPager.setOnPageChangeListener(this); TabWidget widget = mTabHost.getTabWidget(); for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) { TextView tv = (TextView) mTabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); tv.setTextColor(Color.parseColor("#ffffff")); if (isTabletDevice(getResources()) == true) { tv.setTextSize(17); } else { tv.setTextSize(14); } tv.setTypeface(event.getTextBold()); // tv.setEllipsize(TextUtils.TruncateAt.END); if (Build.VERSION.SDK_INT > 11) { tv.setAllCaps(false); } View v1 = widget.getChildAt(i); // v1.setPadding(0,0,0,0); v1.setBackgroundResource(R.drawable.tab_selector_drawable); } return v; }
private void runAssertionOutputSnapshot( Object[][] expectedType, Object[] rowValues, AtomicLong currentTime) { EPStatement stmt = epService .getEPAdministrator() .createEPL("select * from MyTable output snapshot every 1 second"); stmt.addListener(listener); assertEventType(stmt.getEventType(), expectedType); currentTime.set(currentTime.get() + 1000L); epService.getEPRuntime().sendEvent(new CurrentTimeEvent(currentTime.get())); EventBean event = listener.assertOneGetNewAndReset(); assertEventTypeAndEvent(event.getEventType(), expectedType, event.getUnderlying(), rowValues); }
private void assertSimple( SupportUpdateListener listener, String myString, int myInt, String additionalString, int additionalInt) { assertTrue(listener.getAndClearIsInvoked()); EventBean eventBean = listener.getLastNewData()[0]; assertEquals(myString, eventBean.get("myString")); assertEquals(myInt, eventBean.get("myInt")); if (additionalString != null) { assertEquals(additionalString, eventBean.get("concat")); assertEquals(additionalInt, eventBean.get("summed")); } }
private void runAssertionSubqueryWindowAgg(Object[] rowValues) { EPStatement stmt = epService .getEPAdministrator() .createEPL( "select " + "(select window(mt.*) from MyTable as mt) as c0," + "(select first(mt.*) from MyTable as mt) as c1" + " from SupportBean_S2"); stmt.addListener(listener); epService.getEPRuntime().sendEvent(new SupportBean_S2(0)); EventBean event = listener.assertOneGetNewAndReset(); assertEventUnd(((Object[][]) event.get("c0"))[0], rowValues); assertEventUnd(event.get("c1"), rowValues); stmt.destroy(); }
private void runAssertionJoinSelectStreamName(Object[][] expectedType, Object[] rowValues) { String joinEpl = "select mt from MyTable as mt, SupportBean_S2 where key = p20"; EPStatement stmt = epService.getEPAdministrator().createEPL(joinEpl); stmt.addListener(listener); assertEventType(stmt.getEventType().getFragmentType("mt").getFragmentType(), expectedType); epService.getEPRuntime().sendEvent(new SupportBean_S2(0, "G1")); EventBean event = listener.assertOneGetNewAndReset(); assertEventTypeAndEvent( event.getEventType().getFragmentType("mt").getFragmentType(), expectedType, event.get("mt"), rowValues); stmt.destroy(); }
private void runAssertionJoinSelectStreamStarUnnamed( Object[][] expectedType, Object[] rowValues) { String joinEpl = "select mt.* from MyTable as mt, SupportBean_S2 where key = p20"; EPStatement stmt = epService.getEPAdministrator().createEPL(joinEpl); stmt.addListener(listener); stmt.setSubscriber(subscriber); assertEventType(stmt.getEventType(), expectedType); // listener assertion epService.getEPRuntime().sendEvent(new SupportBean_S2(0, "G1")); EventBean event = listener.assertOneGetNewAndReset(); assertEventTypeAndEvent(event.getEventType(), expectedType, event.getUnderlying(), rowValues); // subscriber assertion Object[][] newData = subscriber.getAndResetIndicateArr().get(0).getFirst(); assertEventUnd(newData[0][0], rowValues); stmt.destroy(); }
public void testMapNameProperty() { EPServiceProvider epService = getEngineInitialized(null, null, null); // create a named map Map<String, Object> namedDef = makeMap(new Object[][] {{"n0", int.class}}); epService.getEPAdministrator().getConfiguration().addEventType("MyNamedMap", namedDef); // create a map using the name epService .getEPAdministrator() .getConfiguration() .addEventType( "MyOAWithAMap", new String[] {"p0", "p1"}, new Object[] {"MyNamedMap", "MyNamedMap[]"}); EPStatement stmt = epService .getEPAdministrator() .createEPL( "select p0.n0 as a, p1[0].n0 as b, p1[1].n0 as c, p0 as d, p1 as e from MyOAWithAMap"); SupportUpdateListener listener = new SupportUpdateListener(); stmt.addListener(listener); Map<String, Object> n0_1 = makeMap(new Object[][] {{"n0", 1}}); Map<String, Object> n0_21 = makeMap(new Object[][] {{"n0", 2}}); Map<String, Object> n0_22 = makeMap(new Object[][] {{"n0", 3}}); Map[] n0_2 = new Map[] {n0_21, n0_22}; epService.getEPRuntime().sendEvent(new Object[] {n0_1, n0_2}, "MyOAWithAMap"); EventBean eventResult = listener.assertOneGetNewAndReset(); EPAssertionUtil.assertProps(eventResult, "a,b,c,d".split(","), new Object[] {1, 2, 3, n0_1}); Map[] valueE = (Map[]) eventResult.get("e"); assertSame(valueE[0], n0_2[0]); assertSame(valueE[1], n0_2[1]); assertEquals(int.class, stmt.getEventType().getPropertyType("a")); assertEquals(int.class, stmt.getEventType().getPropertyType("b")); assertEquals(int.class, stmt.getEventType().getPropertyType("c")); assertEquals(Map.class, stmt.getEventType().getPropertyType("d")); assertEquals(Map[].class, stmt.getEventType().getPropertyType("e")); }
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")); }
/** * Adds an event to this faces config document. * * @param event the event to add */ public void addEvent(EventBean event) { if (event.getEventType() == null) { _warning("Missing event type"); } else if (event.getEventListenerClass() == null) { _warning("Event \"" + event.getEventType() + "\" " + "has no listener class"); } else if (event.getEventClass() == null) { _warning("Event \"" + event.getEventType() + "\" " + "has no event class"); } else { event.attach(this); _events.put(event.getEventType(), event); } }
public void testAnyType() { assertTrue( epService.getEPAdministrator().getConfiguration().isVariantStreamExists("MyVariantStream")); epService .getEPAdministrator() .createEPL("insert into MyVariantStream select * from " + SupportBean.class.getName()); epService .getEPAdministrator() .createEPL( "insert into MyVariantStream select * from " + SupportBeanVariantStream.class.getName()); epService .getEPAdministrator() .createEPL("insert into MyVariantStream select * from " + SupportBean_A.class.getName()); epService .getEPAdministrator() .createEPL( "insert into MyVariantStream select symbol as theString, volume as intPrimitive, feed as id from " + SupportMarketDataBean.class.getName()); EPStatement stmt = epService.getEPAdministrator().createEPL("select * from MyVariantStream"); stmt.addListener(listener); assertEquals(0, stmt.getEventType().getPropertyNames().length); Object eventOne = new SupportBean("E0", -1); epService.getEPRuntime().sendEvent(eventOne); assertSame(eventOne, listener.assertOneGetNewAndReset().getUnderlying()); Object eventTwo = new SupportBean_A("E1"); epService.getEPRuntime().sendEvent(eventTwo); assertSame(eventTwo, listener.assertOneGetNewAndReset().getUnderlying()); stmt.destroy(); stmt = epService .getEPAdministrator() .createEPL("select theString,id,intPrimitive from MyVariantStream"); stmt.addListener(listener); assertEquals(Object.class, stmt.getEventType().getPropertyType("theString")); assertEquals(Object.class, stmt.getEventType().getPropertyType("id")); assertEquals(Object.class, stmt.getEventType().getPropertyType("intPrimitive")); String[] fields = "theString,id,intPrimitive".split(","); epService.getEPRuntime().sendEvent(new SupportBeanVariantStream("E1")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {"E1", null, null}); epService.getEPRuntime().sendEvent(new SupportBean("E2", 10)); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {"E2", null, 10}); epService.getEPRuntime().sendEvent(new SupportBean_A("E3")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, "E3", null}); epService.getEPRuntime().sendEvent(new SupportMarketDataBean("s1", 100, 1000L, "f1")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {"s1", "f1", 1000L}); epService.getEPAdministrator().destroyAllStatements(); // Test inserting a wrapper of underlying plus properties epService.getEPAdministrator().getConfiguration().addEventType(SupportBean.class); epService.getEPAdministrator().createEPL("create variant schema TheVariantStream as *"); epService .getEPAdministrator() .createEPL( "insert into TheVariantStream select 'test' as eventConfigId, * from SupportBean"); epService .getEPAdministrator() .createEPL("select * from TheVariantStream") .addListener(listener); epService.getEPRuntime().sendEvent(new SupportBean("E1", 1)); EventBean event = listener.assertOneGetNewAndReset(); assertEquals("test", event.get("eventConfigId")); assertEquals(1, event.get("intPrimitive")); }
public static Object[] myServiceEventBean(EventBean event) { return (Object[]) event.getUnderlying(); }
public static void main(String[] args) { EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(); EPAdministrator admin = epService.getEPAdministrator(); EPRuntime runtime = epService.getEPRuntime(); String SelectEvents = SelectEvents.class.getName(); String epl1 = "create window SelectWindow.win:keepall() as select * from " + SelectEvents; String epl2 = "insert into SelectWindow select * from " + SelectEvents; // 注册EPL语句 admin.createEPL(epl1); admin.createEPL(epl2); // 事件1 SelectEvents se1 = new SelectEvents("se1", 1); runtime.sendEvent(se1); System.out.println("Send SelectEvent 1: " + se1); // 事件2 SelectEvents se2 = new SelectEvents("se2", 2); runtime.sendEvent(se2); System.out.println("Send SelectEvent 2: " + se2); /* 操作语句 * 1. 查找窗体中的所有事件 * 2. 更新size = 2事件的name = "update1" * 3. 删除所有size < 2的事件 */ String select = "select * from SelectWindow"; String update = "update SelectWindow set name='update1' where size = 2"; String delete = "delete from SelectWindow where size < 2"; System.out.println("\nSelect SelectWindow!"); // 类似于数据库的查询操作,返回结果集 EPOnDemandQueryResult selectResult = epService.getEPRuntime().executeQuery(select); EventBean[] events = selectResult.getArray(); for (EventBean eb : events) { System.out.println(eb.getUnderlying()); } // 更新size=2的事件,将name改为'update1' System.out.println("\nUpdate SelectEvent(size = 2) in SelectWindow!"); EPOnDemandQueryResult updateResult = epService.getEPRuntime().executeQuery(update); events = updateResult.getArray(); for (EventBean eb : events) { System.out.println(eb.getUnderlying()); } System.out.println("\nSelect SelectWindow!"); selectResult = epService.getEPRuntime().executeQuery(select); events = selectResult.getArray(); for (EventBean eb : events) { System.out.println(eb.getUnderlying()); } // 删除size<2的事件 System.out.println("\nDelete SelectEvent(size < 2) in SelectWindow!"); EPOnDemandQueryResult deleteResult = epService.getEPRuntime().executeQuery(delete); events = deleteResult.getArray(); for (EventBean eb : events) { System.out.println(eb.getUnderlying()); } System.out.println("\nSelect SelectWindow!"); selectResult = epService.getEPRuntime().executeQuery(select); events = selectResult.getArray(); for (EventBean eb : events) { System.out.println(eb.getUnderlying()); } }
public void testSchemaXMLQuery_DOMGetterBacked() throws Exception { epService = EPServiceProviderManager.getProvider("TestSchemaXML", getConfig(false)); epService.initialize(); updateListener = new SupportUpdateListener(); String stmtSelectWild = "select * from TestXMLSchemaType"; EPStatement wildStmt = epService.getEPAdministrator().createEPL(stmtSelectWild); EventType type = wildStmt.getEventType(); EventTypeAssertionUtil.assertConsistency(type); EPAssertionUtil.assertEqualsAnyOrder( new Object[] { new EventPropertyDescriptor( "nested1", Node.class, null, false, false, false, false, true), new EventPropertyDescriptor( "prop4", String.class, null, false, false, false, false, false), new EventPropertyDescriptor( "nested3", Node.class, null, false, false, false, false, true), new EventPropertyDescriptor( "customProp", Double.class, null, false, false, false, false, false), }, type.getPropertyDescriptors()); String stmt = "select nested1 as nodeProp," + "prop4 as nested1Prop," + "nested1.prop2 as nested2Prop," + "nested3.nested4('a').prop5[1] as complexProp," + "nested1.nested2.prop3[2] as indexedProp," + "customProp," + "prop4.attr2 as attrOneProp," + "nested3.nested4[2].id as attrTwoProp" + " from TestXMLSchemaType.win:length(100)"; EPStatement selectStmt = epService.getEPAdministrator().createEPL(stmt); selectStmt.addListener(updateListener); type = selectStmt.getEventType(); EventTypeAssertionUtil.assertConsistency(type); EPAssertionUtil.assertEqualsAnyOrder( new Object[] { new EventPropertyDescriptor( "nodeProp", Node.class, null, false, false, false, false, true), new EventPropertyDescriptor( "nested1Prop", String.class, null, false, false, false, false, false), new EventPropertyDescriptor( "nested2Prop", Boolean.class, null, false, false, false, false, false), new EventPropertyDescriptor( "complexProp", String.class, null, false, false, false, false, false), new EventPropertyDescriptor( "indexedProp", Integer.class, null, false, false, false, false, false), new EventPropertyDescriptor( "customProp", Double.class, null, false, false, false, false, false), new EventPropertyDescriptor( "attrOneProp", Boolean.class, null, false, false, false, false, false), new EventPropertyDescriptor( "attrTwoProp", String.class, null, false, false, false, false, false), }, type.getPropertyDescriptors()); Document eventDoc = SupportXML.sendDefaultEvent(epService.getEPRuntime(), "test"); assertNotNull(updateListener.getLastNewData()); EventBean theEvent = updateListener.getLastNewData()[0]; assertSame(eventDoc.getDocumentElement().getChildNodes().item(1), theEvent.get("nodeProp")); assertEquals("SAMPLE_V6", theEvent.get("nested1Prop")); assertEquals(true, theEvent.get("nested2Prop")); assertEquals("SAMPLE_V8", theEvent.get("complexProp")); assertEquals(5, theEvent.get("indexedProp")); assertEquals(3.0, theEvent.get("customProp")); assertEquals(true, theEvent.get("attrOneProp")); assertEquals("c", theEvent.get("attrTwoProp")); /** * Comment-in for performance testing long start = System.nanoTime(); for (int i = 0; i < 1000; * i++) { sendEvent("test"); } long end = System.nanoTime(); double delta = (end - start) / * 1000d / 1000d / 1000d; System.out.println(delta); */ }
private void assertIntegerIndexed(EventBean event, SupportBean[] events) { EPAssertionUtil.assertEqualsExactOrder(events, (Object[]) event.get("c0.myevents")); EPAssertionUtil.assertEqualsExactOrder(events, (Object[]) event.get("c1")); assertSame(events[events.length - 1], event.get("c2")); }
public void testLinest() { // further math tests can be found in the view unit test EPAdministrator admin = epService.getEPAdministrator(); admin.getConfiguration().addEventType("Market", SupportMarketDataBean.class); EPStatement statement = admin.createEPL( "select * from Market.std:groupwin(symbol).win:length(1000000).stat:linest(price, volume, feed)"); SupportUpdateListener listener = new SupportUpdateListener(); statement.addListener(listener); assertEquals(Double.class, statement.getEventType().getPropertyType("slope")); assertEquals(Double.class, statement.getEventType().getPropertyType("YIntercept")); assertEquals(Double.class, statement.getEventType().getPropertyType("XAverage")); assertEquals(Double.class, statement.getEventType().getPropertyType("XStandardDeviationPop")); assertEquals( Double.class, statement.getEventType().getPropertyType("XStandardDeviationSample")); assertEquals(Double.class, statement.getEventType().getPropertyType("XSum")); assertEquals(Double.class, statement.getEventType().getPropertyType("XVariance")); assertEquals(Double.class, statement.getEventType().getPropertyType("YAverage")); assertEquals(Double.class, statement.getEventType().getPropertyType("YStandardDeviationPop")); assertEquals( Double.class, statement.getEventType().getPropertyType("YStandardDeviationSample")); assertEquals(Double.class, statement.getEventType().getPropertyType("YSum")); assertEquals(Double.class, statement.getEventType().getPropertyType("YVariance")); assertEquals(Long.class, statement.getEventType().getPropertyType("dataPoints")); assertEquals(Long.class, statement.getEventType().getPropertyType("n")); assertEquals(Double.class, statement.getEventType().getPropertyType("sumX")); assertEquals(Double.class, statement.getEventType().getPropertyType("sumXSq")); assertEquals(Double.class, statement.getEventType().getPropertyType("sumXY")); assertEquals(Double.class, statement.getEventType().getPropertyType("sumY")); assertEquals(Double.class, statement.getEventType().getPropertyType("sumYSq")); String[] fields = new String[] {"symbol", "slope", "YIntercept", "feed"}; epService.getEPRuntime().sendEvent(new SupportMarketDataBean("ABC", 10.0, 50000L, "f1")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {"ABC", Double.NaN, Double.NaN, "f1"}); epService.getEPRuntime().sendEvent(new SupportMarketDataBean("DEF", 1.0, 1L, "f2")); EventBean theEvent = listener.assertOneGetNewAndReset(); EPAssertionUtil.assertProps( theEvent, fields, new Object[] {"DEF", Double.NaN, Double.NaN, "f2"}); assertEquals(1d, theEvent.get("XAverage")); assertEquals(0d, theEvent.get("XStandardDeviationPop")); assertEquals(Double.NaN, theEvent.get("XStandardDeviationSample")); assertEquals(1d, theEvent.get("XSum")); assertEquals(Double.NaN, theEvent.get("XVariance")); assertEquals(1d, theEvent.get("YAverage")); assertEquals(0d, theEvent.get("YStandardDeviationPop")); assertEquals(Double.NaN, theEvent.get("YStandardDeviationSample")); assertEquals(1d, theEvent.get("YSum")); assertEquals(Double.NaN, theEvent.get("YVariance")); assertEquals(1L, theEvent.get("dataPoints")); assertEquals(1L, theEvent.get("n")); assertEquals(1d, theEvent.get("sumX")); assertEquals(1d, theEvent.get("sumXSq")); assertEquals(1d, theEvent.get("sumXY")); assertEquals(1d, theEvent.get("sumY")); assertEquals(1d, theEvent.get("sumYSq")); // above computed values tested in more detail in RegressionBean test epService.getEPRuntime().sendEvent(new SupportMarketDataBean("DEF", 2.0, 2L, "f3")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {"DEF", 1.0, 0.0, "f3"}); epService.getEPRuntime().sendEvent(new SupportMarketDataBean("ABC", 11.0, 50100L, "f4")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {"ABC", 100.0, 49000.0, "f4"}); }
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")); }