Beispiel #1
0
  public void testInsertFromPattern() {
    String stmtOneText =
        "insert into streamA select * from pattern [every " + SupportBean.class.getName() + "]";
    SupportUpdateListener listenerOne = new SupportUpdateListener();
    EPStatement stmtOne = epService.getEPAdministrator().createEPL(stmtOneText);
    stmtOne.addListener(listenerOne);

    String stmtTwoText =
        "insert into streamA select * from pattern [every " + SupportBean.class.getName() + "]";
    SupportUpdateListener listenerTwo = new SupportUpdateListener();
    EPStatement stmtTwo = epService.getEPAdministrator().createEPL(stmtTwoText);
    stmtTwo.addListener(listenerTwo);

    EventType eventType = stmtOne.getEventType();
    assertEquals(Map.class, eventType.getUnderlyingType());
  }
  public void testConfiguredViaPropsAndXML() {
    Configuration configuration = SupportConfigFactory.getConfiguration();
    configuration
        .getEngineDefaults()
        .getEventMeta()
        .setDefaultEventRepresentation(Configuration.EventRepresentation.OBJECTARRAY);
    configuration.addEventType(
        "MyOAType",
        "bean,theString,map".split(","),
        new Object[] {SupportBean.class.getName(), "string", "java.util.Map"});

    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(configuration);
    epService.initialize();
    if (InstrumentationHelper.ENABLED) {
      InstrumentationHelper.startTest(epService, this.getClass(), getName());
    }

    EventType eventType =
        epService.getEPAdministrator().getConfiguration().getEventType("MyOAType");
    assertEquals(Object[].class, eventType.getUnderlyingType());
    assertEquals(String.class, eventType.getPropertyType("theString"));
    assertEquals(Map.class, eventType.getPropertyType("map"));
    assertEquals(SupportBean.class, eventType.getPropertyType("bean"));

    EPStatement stmt =
        epService
            .getEPAdministrator()
            .createEPL("select bean, theString, map('key'), bean.theString from MyOAType");
    SupportUpdateListener listener = new SupportUpdateListener();
    stmt.addListener(listener);
    assertEquals(Object[].class, stmt.getEventType().getUnderlyingType());

    SupportBean bean = new SupportBean("E1", 1);
    epService
        .getEPRuntime()
        .sendEvent(
            new Object[] {bean, "abc", Collections.singletonMap("key", "value")}, "MyOAType");
    EPAssertionUtil.assertProps(
        listener.assertOneGetNew(),
        "bean,theString,map('key'),bean.theString".split(","),
        new Object[] {bean, "abc", "value", "E1"});

    if (InstrumentationHelper.ENABLED) {
      InstrumentationHelper.endTest();
    }
  }