public void testInvalidStreamUsed() { String stmtText = "insert into Event_1 (delta, product) " + "select intPrimitive - intBoxed as deltaTag, intPrimitive * intBoxed as productTag " + "from " + SupportBean.class.getName() + ".win:length(100)"; epService.getEPAdministrator().createEPL(stmtText); try { stmtText = "insert into Event_1(delta) " + "select (intPrimitive - intBoxed) as deltaTag " + "from " + SupportBean.class.getName() + ".win:length(100)"; epService.getEPAdministrator().createEPL(stmtText); fail(); } catch (EPStatementException ex) { // expected assertEquals( "Error starting statement: Event type named 'Event_1' has already been declared with differing column name or type information: Type by name 'Event_1' expects 2 properties but receives 1 properties [insert into Event_1(delta) select (intPrimitive - intBoxed) as deltaTag from com.espertech.esper.support.bean.SupportBean.win:length(100)]", ex.getMessage()); } }
private void tryInvalid(String stmtText, String expectedMsg) { try { epService.getEPAdministrator().createEPL(stmtText); fail(); } catch (EPStatementException ex) { assertEquals(expectedMsg, ex.getMessage()); } }
private void tryInvalid(String epl, String message) { try { epService.getEPAdministrator().createEPL(epl); fail(); } catch (EPStatementException ex) { assertEquals(message, ex.getMessage()); } }
public void testInvalidGroupByNoChild() { String stmtText = "select avg(price), symbol from " + SupportMarketDataBean.class.getName() + ".win:length(100).std:groupwin(symbol)"; try { epService.getEPAdministrator().createEPL(stmtText); } catch (EPStatementException ex) { assertEquals( "Error starting statement: Invalid use of the 'std:groupwin' view, the view requires one or more child views to group, or consider using the group-by clause [select avg(price), symbol from com.espertech.esper.support.bean.SupportMarketDataBean.win:length(100).std:groupwin(symbol)]", ex.getMessage()); } }
public void testInvalid() { epService = EPServiceProviderManager.getProvider("TestSchemaXML", getConfig(false)); epService.initialize(); try { epService .getEPAdministrator() .createEPL("select element1 from TestXMLSchemaType.win:length(100)"); fail(); } catch (EPStatementException ex) { assertEquals( "Error starting statement: Property named 'element1' is not valid in any stream [select element1 from TestXMLSchemaType.win:length(100)]", ex.getMessage()); } }
public void testFailedValidation() { Configuration configuration = SupportConfigFactory.getConfiguration(); configuration.addPlugInSingleRowFunction( "singlerow", MySingleRowFunctionTwo.class.getName(), "testSingleRow"); epService = EPServiceProviderManager.getDefaultProvider(configuration); epService.initialize(); try { String text = "select singlerow('a', 'b') from " + SupportBean.class.getName(); epService.getEPAdministrator().createEPL(text); } catch (EPStatementException ex) { assertEquals( "Error starting statement: Could not find static method named 'testSingleRow' in class 'com.espertech.esper.regression.client.MySingleRowFunctionTwo' with matching parameter number and expected parameter type(s) 'String, String' (nearest match found was 'testSingleRow' taking type(s) 'String, int') [select singlerow('a', 'b') from com.espertech.esper.support.bean.SupportBean]", ex.getMessage()); } }
public void testInvalidInsertInto() { try { epService .getEPAdministrator() .createEPL("insert into RevQuote select * from " + SupportBean.class.getName()); fail(); } catch (EPStatementException ex) { assertEquals( "Error starting statement: Selected event type is not a valid base or delta event type of revision event type 'RevisableQuote' [insert into RevQuote select * from com.espertech.esper.support.bean.SupportBean]", ex.getMessage()); } try { epService .getEPAdministrator() .createEPL( "insert into RevQuote select intPrimitive as k0 from " + SupportBean.class.getName()); fail(); } catch (EPStatementException ex) { assertEquals( "Error starting statement: Selected event type is not a valid base or delta event type of revision event type 'RevisableQuote' [insert into RevQuote select intPrimitive as k0 from com.espertech.esper.support.bean.SupportBean]", ex.getMessage()); } }
public void testInvalid() { epService .getEPAdministrator() .createEPL("create context SegmentedSB as partition by theString from SupportBean"); epService .getEPAdministrator() .createEPL("create context SegmentedS0 as partition by p00 from SupportBean_S0"); epService .getEPAdministrator() .createEPL("context SegmentedSB create window WinSB.win:keepall() as SupportBean"); epService .getEPAdministrator() .createEPL("context SegmentedS0 create window WinS0.win:keepall() as SupportBean_S0"); epService.getEPAdministrator().createEPL("create window WinS1.win:keepall() as SupportBean_S1"); // when a context is declared, it must be the same context that applies to all named windows tryInvalidRuntimeQuery( "context SegmentedSB select * from WinSB, WinS0", "Error executing statement: Joins in runtime queries for context partitions are not supported [context SegmentedSB select * from WinSB, WinS0]"); tryInvalidRuntimeQuery( null, "select * from WinSB, WinS1", "No context partition selectors provided"); tryInvalidRuntimeQuery( new ContextPartitionSelector[1], "select * from WinSB, WinS1", "Error executing statement: Number of context partition selectors does not match the number of named windows in the from-clause [select * from WinSB, WinS1]"); // test join epService .getEPAdministrator() .createEPL("create context PartitionedByString partition by theString from SupportBean"); epService .getEPAdministrator() .createEPL( "context PartitionedByString create window MyWindowOne.win:keepall() as SupportBean"); epService .getEPAdministrator() .createEPL("create context PartitionedByP00 partition by p00 from SupportBean_S0"); epService .getEPAdministrator() .createEPL( "context PartitionedByP00 create window MyWindowTwo.win:keepall() as SupportBean_S0"); epService.getEPRuntime().sendEvent(new SupportBean("G1", 10)); epService.getEPRuntime().sendEvent(new SupportBean("G2", 11)); epService.getEPRuntime().sendEvent(new SupportBean_S0(1, "G2")); epService.getEPRuntime().sendEvent(new SupportBean_S0(2, "G1")); try { runQueryAll( "select mw1.intPrimitive as c1, mw2.id as c2 from MyWindowOne mw1, MyWindowTwo mw2 where mw1.theString = mw2.p00", "c1,c2", new Object[][] {{10, 2}, {11, 1}}, 2); } catch (EPStatementException ex) { assertEquals( ex.getMessage(), "Error executing statement: Joins against named windows that are under context are not supported [select mw1.intPrimitive as c1, mw2.id as c2 from MyWindowOne mw1, MyWindowTwo mw2 where mw1.theString = mw2.p00]"); } }
public void testContextNamedWindowQuery() { epService .getEPAdministrator() .createEPL("create context PartitionedByString partition by theString from SupportBean"); epService .getEPAdministrator() .createEPL( "context PartitionedByString create window MyWindow.win:keepall() as SupportBean"); epService.getEPAdministrator().createEPL("insert into MyWindow select * from SupportBean"); epService.getEPRuntime().sendEvent(new SupportBean("E1", 10)); epService.getEPRuntime().sendEvent(new SupportBean("E2", 20)); epService.getEPRuntime().sendEvent(new SupportBean("E2", 21)); // test no context runQueryAll("select sum(intPrimitive) as c1 from MyWindow", "c1", new Object[][] {{51}}, 1); runQueryAll( "select sum(intPrimitive) as c1 from MyWindow where intPrimitive > 15", "c1", new Object[][] {{41}}, 1); runQuery( "select sum(intPrimitive) as c1 from MyWindow", "c1", new Object[][] {{41}}, new ContextPartitionSelector[] { new SupportSelectorPartitioned(Collections.singletonList(new Object[] {"E2"})) }); runQuery( "select sum(intPrimitive) as c1 from MyWindow", "c1", new Object[][] {{41}}, new ContextPartitionSelector[] { new SupportSelectorById(Collections.<Integer>singleton(1)) }); // test with context props runQueryAll( "context PartitionedByString select context.key1 as c0, intPrimitive as c1 from MyWindow", "c0,c1", new Object[][] {{"E1", 10}, {"E2", 20}, {"E2", 21}}, 1); runQueryAll( "context PartitionedByString select context.key1 as c0, intPrimitive as c1 from MyWindow where intPrimitive > 15", "c0,c1", new Object[][] {{"E2", 20}, {"E2", 21}}, 1); // test targeted context partition runQuery( "context PartitionedByString select context.key1 as c0, intPrimitive as c1 from MyWindow where intPrimitive > 15", "c0,c1", new Object[][] {{"E2", 20}, {"E2", 21}}, new SupportSelectorPartitioned[] { new SupportSelectorPartitioned(Collections.singletonList(new Object[] {"E2"})) }); try { epService .getEPRuntime() .executeQuery( "context PartitionedByString select * from MyWindow", new ContextPartitionSelector[] { new ContextPartitionSelectorCategory() { public Set<String> getLabels() { return null; } } }); fail(); } catch (EPStatementException ex) { assertTrue( "message: " + ex.getMessage(), ex.getMessage() .startsWith( "Error executing statement: Invalid context partition selector, expected an implementation class of any of [ContextPartitionSelectorAll, ContextPartitionSelectorFiltered, ContextPartitionSelectorById, ContextPartitionSelectorSegmented] interfaces but received com")); } }
private void runObjectArrInheritanceAssertion(EPServiceProvider epService) { SupportUpdateListener listeners[] = new SupportUpdateListener[5]; String[] statements = { "select base as vbase, sub1? as v1, sub2? as v2, suba? as va, subb? as vb from RootEvent", // 0 "select base as vbase, sub1 as v1, sub2? as v2, suba? as va, subb? as vb from Sub1Event", // 1 "select base as vbase, sub1? as v1, sub2 as v2, suba? as va, subb? as vb from Sub2Event", // 2 "select base as vbase, sub1 as v1, sub2? as v2, suba as va, subb? as vb from SubAEvent", // 3 "select base as vbase, sub1? as v1, sub2? as v2, suba? as va, subb as vb from SubBEvent" // 4 }; for (int i = 0; i < statements.length; i++) { EPStatement statement = epService.getEPAdministrator().createEPL(statements[i]); listeners[i] = new SupportUpdateListener(); statement.addListener(listeners[i]); } String[] fields = "vbase,v1,v2,va,vb".split(","); EventType type = epService.getEPAdministrator().getConfiguration().getEventType("SubAEvent"); assertEquals("base", type.getPropertyDescriptors()[0].getPropertyName()); assertEquals("sub1", type.getPropertyDescriptors()[1].getPropertyName()); assertEquals("suba", type.getPropertyDescriptors()[2].getPropertyName()); assertEquals(3, type.getPropertyDescriptors().length); type = epService.getEPAdministrator().getConfiguration().getEventType("SubBEvent"); assertEquals("[base, sub1, suba, subb]", Arrays.toString(type.getPropertyNames())); assertEquals(4, type.getPropertyDescriptors().length); type = epService.getEPAdministrator().getConfiguration().getEventType("Sub1Event"); assertEquals("[base, sub1]", Arrays.toString(type.getPropertyNames())); assertEquals(2, type.getPropertyDescriptors().length); type = epService.getEPAdministrator().getConfiguration().getEventType("Sub2Event"); assertEquals("[base, sub2]", Arrays.toString(type.getPropertyNames())); assertEquals(2, type.getPropertyDescriptors().length); epService .getEPRuntime() .sendEvent(new Object[] {"a", "b", "x"}, "SubAEvent"); // base, sub1, suba EPAssertionUtil.assertProps( listeners[0].assertOneGetNewAndReset(), fields, new Object[] {"a", "b", null, "x", null}); assertFalse(listeners[2].isInvoked() || listeners[4].isInvoked()); EPAssertionUtil.assertProps( listeners[1].assertOneGetNewAndReset(), fields, new Object[] {"a", "b", null, "x", null}); EPAssertionUtil.assertProps( listeners[3].assertOneGetNewAndReset(), fields, new Object[] {"a", "b", null, "x", null}); epService.getEPRuntime().sendEvent(new Object[] {"f1", "f2", "f4"}, "SubAEvent"); EPAssertionUtil.assertProps( listeners[0].assertOneGetNewAndReset(), fields, new Object[] {"f1", "f2", null, "f4", null}); assertFalse(listeners[2].isInvoked() || listeners[4].isInvoked()); EPAssertionUtil.assertProps( listeners[1].assertOneGetNewAndReset(), fields, new Object[] {"f1", "f2", null, "f4", null}); EPAssertionUtil.assertProps( listeners[3].assertOneGetNewAndReset(), fields, new Object[] {"f1", "f2", null, "f4", null}); epService.getEPRuntime().sendEvent(new Object[] {"XBASE", "X1", "X2", "XY"}, "SubBEvent"); Object[] values = new Object[] {"XBASE", "X1", null, "X2", "XY"}; EPAssertionUtil.assertProps(listeners[0].assertOneGetNewAndReset(), fields, values); assertFalse(listeners[2].isInvoked()); EPAssertionUtil.assertProps(listeners[1].assertOneGetNewAndReset(), fields, values); EPAssertionUtil.assertProps(listeners[3].assertOneGetNewAndReset(), fields, values); EPAssertionUtil.assertProps(listeners[4].assertOneGetNewAndReset(), fields, values); epService.getEPRuntime().sendEvent(new Object[] {"YBASE", "Y1"}, "Sub1Event"); values = new Object[] {"YBASE", "Y1", null, null, null}; EPAssertionUtil.assertProps(listeners[0].assertOneGetNewAndReset(), fields, values); assertFalse(listeners[2].isInvoked() || listeners[3].isInvoked() || listeners[4].isInvoked()); EPAssertionUtil.assertProps(listeners[1].assertOneGetNewAndReset(), fields, values); epService.getEPRuntime().sendEvent(new Object[] {"YBASE", "Y2"}, "Sub2Event"); values = new Object[] {"YBASE", null, "Y2", null, null}; EPAssertionUtil.assertProps(listeners[0].assertOneGetNewAndReset(), fields, values); assertFalse(listeners[1].isInvoked() || listeners[3].isInvoked() || listeners[4].isInvoked()); EPAssertionUtil.assertProps(listeners[2].assertOneGetNewAndReset(), fields, values); epService.getEPRuntime().sendEvent(new Object[] {"ZBASE"}, "RootEvent"); values = new Object[] {"ZBASE", null, null, null, null}; EPAssertionUtil.assertProps(listeners[0].assertOneGetNewAndReset(), fields, values); assertFalse( listeners[1].isInvoked() || listeners[2].isInvoked() || listeners[3].isInvoked() || listeners[4].isInvoked()); // try property not available try { epService.getEPAdministrator().createEPL("select suba from Sub1Event"); fail(); } catch (EPStatementException ex) { assertEquals( "Error starting statement: Failed to validate select-clause expression 'suba': Property named 'suba' is not valid in any stream (did you mean 'sub1'?) [select suba from Sub1Event]", ex.getMessage()); } // try supertype not exists try { epService .getEPAdministrator() .getConfiguration() .addEventType("Sub1Event", makeMap(""), new String[] {"doodle"}); fail(); } catch (ConfigurationException ex) { assertEquals("Supertype by name 'doodle' could not be found", ex.getMessage()); } }