public void testInvalid() { EPServiceProvider epService = getEngineInitialized(null, null, null); // can add the same nested type twice epService .getEPAdministrator() .getConfiguration() .addEventType("ABC", new String[] {"p0"}, new Class[] {int.class}); epService .getEPAdministrator() .getConfiguration() .addEventType("ABC", new String[] {"p0"}, new Class[] {int.class}); try { // changing the definition however stops the compatibility epService .getEPAdministrator() .getConfiguration() .addEventType("ABC", new String[] {"p0"}, new Class[] {long.class}); fail(); } catch (ConfigurationException ex) { assertEquals( "Event type named 'ABC' has already been declared with differing column name or type information: Type by name 'ABC' in property 'p0' expected class java.lang.Integer but receives class java.lang.Long", ex.getMessage()); } tryInvalid( epService, new String[] {"a"}, new Object[] {new SupportBean()}, "Nestable type configuration encountered an unexpected property type of 'SupportBean' for property 'a', expected java.lang.Class or java.util.Map or the name of a previously-declared Map or ObjectArray type"); }
public void testObjectArrayInheritanceInitTime() { Configuration configuration = SupportConfigFactory.getConfiguration(); configuration.addEventType("RootEvent", new String[] {"base"}, new Object[] {String.class}); configuration.addEventType("Sub1Event", new String[] {"sub1"}, new Object[] {String.class}); configuration.addEventType("Sub2Event", new String[] {"sub2"}, new Object[] {String.class}); configuration.addEventType("SubAEvent", new String[] {"suba"}, new Object[] {String.class}); configuration.addEventType("SubBEvent", new String[] {"subb"}, new Object[] {String.class}); configuration.addObjectArraySuperType("Sub1Event", "RootEvent"); configuration.addObjectArraySuperType("Sub2Event", "RootEvent"); configuration.addObjectArraySuperType("SubAEvent", "Sub1Event"); configuration.addObjectArraySuperType("SubBEvent", "SubAEvent"); try { configuration.addObjectArraySuperType("SubBEvent", "Sub2Event"); fail(); } catch (ConfigurationException ex) { assertEquals("Object-array event types may not have multiple supertypes", ex.getMessage()); } EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(configuration); epService.initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.startTest(epService, this.getClass(), getName()); } EPAssertionUtil.assertEqualsExactOrder( new Object[] { new EventPropertyDescriptor( "base", String.class, null, false, false, false, false, false), new EventPropertyDescriptor( "sub1", String.class, null, false, false, false, false, false), new EventPropertyDescriptor( "suba", String.class, null, false, false, false, false, false), }, ((EPServiceProviderSPI) epService) .getEventAdapterService() .getExistsTypeByName("SubAEvent") .getPropertyDescriptors()); runObjectArrInheritanceAssertion(epService); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.endTest(); } }
public void testObjectArrayTypeUpdate() { Configuration configuration = SupportConfigFactory.getConfiguration(); configuration .getEngineDefaults() .getEventMeta() .setDefaultEventRepresentation(Configuration.EventRepresentation.OBJECTARRAY); String[] names = {"base1", "base2"}; Object[] types = {String.class, makeMap(new Object[][] {{"n1", int.class}})}; configuration.addEventType("MyOAEvent", names, types); EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(configuration); epService.initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.startTest(epService, this.getClass(), getName()); } EPStatement statementOne = epService .getEPAdministrator() .createEPL( "select base1 as v1, base2.n1 as v2, base3? as v3, base2.n2? as v4 from MyOAEvent"); assertEquals(Object[].class, statementOne.getEventType().getUnderlyingType()); EPStatement statementOneSelectAll = epService.getEPAdministrator().createEPL("select * from MyOAEvent"); assertEquals( "[base1, base2]", Arrays.toString(statementOneSelectAll.getEventType().getPropertyNames())); SupportUpdateListener listenerOne = new SupportUpdateListener(); statementOne.addListener(listenerOne); String[] fields = "v1,v2,v3,v4".split(","); epService .getEPRuntime() .sendEvent(new Object[] {"abc", makeMap(new Object[][] {{"n1", 10}}), ""}, "MyOAEvent"); EPAssertionUtil.assertProps( listenerOne.assertOneGetNewAndReset(), fields, new Object[] {"abc", 10, null, null}); // update type String[] namesNew = {"base3", "base2"}; Object[] typesNew = new Object[] {Long.class, makeMap(new Object[][] {{"n2", String.class}})}; epService .getEPAdministrator() .getConfiguration() .updateObjectArrayEventType("MyOAEvent", namesNew, typesNew); EPStatement statementTwo = epService .getEPAdministrator() .createEPL( "select base1 as v1, base2.n1 as v2, base3 as v3, base2.n2 as v4 from MyOAEvent"); EPStatement statementTwoSelectAll = epService.getEPAdministrator().createEPL("select * from MyOAEvent"); SupportUpdateListener listenerTwo = new SupportUpdateListener(); statementTwo.addListener(listenerTwo); epService .getEPRuntime() .sendEvent( new Object[] {"def", makeMap(new Object[][] {{"n1", 9}, {"n2", "xyz"}}), 20L}, "MyOAEvent"); EPAssertionUtil.assertProps( listenerOne.assertOneGetNewAndReset(), fields, new Object[] {"def", 9, 20L, "xyz"}); EPAssertionUtil.assertProps( listenerTwo.assertOneGetNewAndReset(), fields, new Object[] {"def", 9, 20L, "xyz"}); // assert event type assertEquals( "[base1, base2, base3]", Arrays.toString(statementOneSelectAll.getEventType().getPropertyNames())); assertEquals( "[base1, base2, base3]", Arrays.toString(statementTwoSelectAll.getEventType().getPropertyNames())); EPAssertionUtil.assertEqualsAnyOrder( new Object[] { new EventPropertyDescriptor("base3", Long.class, null, false, false, false, false, false), new EventPropertyDescriptor("base2", Map.class, null, false, false, false, true, false), new EventPropertyDescriptor( "base1", String.class, null, false, false, false, false, false), }, statementTwoSelectAll.getEventType().getPropertyDescriptors()); try { epService .getEPAdministrator() .getConfiguration() .updateObjectArrayEventType("dummy", new String[0], new Object[0]); fail(); } catch (ConfigurationException ex) { assertEquals( "Error updating Object-array event type: Event type named 'dummy' has not been declared", ex.getMessage()); } epService .getEPAdministrator() .getConfiguration() .addEventType("SupportBean", SupportBean.class); try { epService .getEPAdministrator() .getConfiguration() .updateObjectArrayEventType("SupportBean", new String[0], new Object[0]); fail(); } catch (ConfigurationException ex) { assertEquals( "Error updating Object-array event type: Event type by name 'SupportBean' is not an Object-array event type", ex.getMessage()); } if (InstrumentationHelper.ENABLED) { InstrumentationHelper.endTest(); } }
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()); } }