Beispiel #1
0
 private void updatePropertySet() {
   PropertyDescriptorComposite compositeProperties =
       getCompositeProperties(underlyingEventType, underlyingMapType);
   propertyNames = compositeProperties.getPropertyNames();
   propertyDescriptorMap = compositeProperties.getPropertyDescriptorMap();
   propertyDesc = compositeProperties.getDescriptors();
   numPropertiesUnderlyingType = underlyingEventType.getPropertyDescriptors().length;
 }
  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());
  }
Beispiel #3
0
  private static PropertyDescriptorComposite getCompositeProperties(
      EventType underlyingEventType, MapEventType underlyingMapType) {
    List<String> propertyNames = new ArrayList<String>();
    propertyNames.addAll(Arrays.asList(underlyingEventType.getPropertyNames()));
    propertyNames.addAll(Arrays.asList(underlyingMapType.getPropertyNames()));
    String[] propertyNamesArr = propertyNames.toArray(new String[propertyNames.size()]);

    List<EventPropertyDescriptor> propertyDesc = new ArrayList<EventPropertyDescriptor>();
    HashMap<String, EventPropertyDescriptor> propertyDescriptorMap =
        new HashMap<String, EventPropertyDescriptor>();
    for (EventPropertyDescriptor eventProperty : underlyingEventType.getPropertyDescriptors()) {
      propertyDesc.add(eventProperty);
      propertyDescriptorMap.put(eventProperty.getPropertyName(), eventProperty);
    }
    for (EventPropertyDescriptor mapProperty : underlyingMapType.getPropertyDescriptors()) {
      propertyDesc.add(mapProperty);
      propertyDescriptorMap.put(mapProperty.getPropertyName(), mapProperty);
    }
    EventPropertyDescriptor[] propertyDescArr =
        propertyDesc.toArray(new EventPropertyDescriptor[propertyDesc.size()]);
    return new PropertyDescriptorComposite(
        propertyDescriptorMap, propertyNamesArr, propertyDescArr);
  }
  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);
     */
  }
Beispiel #5
0
 private void checkInitProperties() {
   if (numPropertiesUnderlyingType != underlyingEventType.getPropertyDescriptors().length) {
     updatePropertySet();
   }
 }
  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());
    }
  }