示例#1
0
  public void testInvalidConfig() {
    ConfigurationRevisionEventType config = new ConfigurationRevisionEventType();
    tryInvalidConfig(
        "abc",
        config,
        "Required base event type name is not set in the configuration for revision event type 'abc'");

    epService.getEPAdministrator().getConfiguration().addEventType("MyEvent", SupportBean.class);
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("MyComplex", SupportBeanComplexProps.class);
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("MyTypeChange", SupportBeanTypeChange.class);

    config.addNameBaseEventType("XYZ");
    tryInvalidConfig(
        "abc",
        config,
        "Could not locate event type for name 'XYZ' in the configuration for revision event type 'abc'");

    config.getNameBaseEventTypes().clear();
    config.addNameBaseEventType("MyEvent");
    tryInvalidConfig(
        "abc",
        config,
        "Required key properties are not set in the configuration for revision event type 'abc'");

    config.addNameBaseEventType("AEvent");
    config.addNameBaseEventType("AEvent");
    tryInvalidConfig(
        "abc",
        config,
        "Only one base event type name may be added to revision event type 'abc', multiple base types are not yet supported");

    config.getNameBaseEventTypes().clear();
    config.addNameBaseEventType("MyEvent");
    config.setKeyPropertyNames(new String[0]);
    tryInvalidConfig(
        "abc",
        config,
        "Required key properties are not set in the configuration for revision event type 'abc'");

    config.setKeyPropertyNames(new String[] {"xyz"});
    tryInvalidConfig(
        "abc",
        config,
        "Key property 'xyz' as defined in the configuration for revision event type 'abc' does not exists in event type 'MyEvent'");

    config.setKeyPropertyNames(new String[] {"intPrimitive"});
    config.addNameDeltaEventType("MyComplex");
    tryInvalidConfig(
        "abc",
        config,
        "Key property 'intPrimitive' as defined in the configuration for revision event type 'abc' does not exists in event type 'MyComplex'");

    config.addNameDeltaEventType("XYZ");
    tryInvalidConfig(
        "abc",
        config,
        "Could not locate event type for name 'XYZ' in the configuration for revision event type 'abc'");

    config.getNameDeltaEventTypes().clear();
    config.setKeyPropertyNames(new String[] {"intBoxed"});
    config.addNameDeltaEventType("MyTypeChange"); // invalid intPrimitive property type
    tryInvalidConfig(
        "abc",
        config,
        "Property named 'intPrimitive' does not have the same type for base and delta types of revision event type 'abc'");

    config.getNameDeltaEventTypes().clear();
    epService.getEPAdministrator().getConfiguration().addRevisionEventType("abc", config);
  }
示例#2
0
  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"));
  }
示例#3
0
  public void setUp() {
    Configuration config = SupportConfigFactory.getConfiguration();

    config.addEventType("SupportBean", SupportBean.class);
    config.addEventType("FullEvent", SupportRevisionFull.class);
    config.addEventType("D1", SupportDeltaOne.class);
    config.addEventType("D2", SupportDeltaTwo.class);
    config.addEventType("D3", SupportDeltaThree.class);
    config.addEventType("D4", SupportDeltaFour.class);
    config.addEventType("D5", SupportDeltaFive.class);

    ConfigurationRevisionEventType configRev = new ConfigurationRevisionEventType();
    configRev.setKeyPropertyNames(new String[] {"k0"});
    configRev.addNameBaseEventType("FullEvent");
    configRev.addNameDeltaEventType("D1");
    configRev.addNameDeltaEventType("D2");
    configRev.addNameDeltaEventType("D3");
    configRev.addNameDeltaEventType("D4");
    configRev.addNameDeltaEventType("D5");
    config.addRevisionEventType("RevisableQuote", configRev);

    epService = EPServiceProviderManager.getDefaultProvider(config);
    epService.initialize();
    listenerOne = new SupportUpdateListener();
    listenerTwo = new SupportUpdateListener();
    listenerThree = new SupportUpdateListener();

    stmtCreateWin =
        epService
            .getEPAdministrator()
            .createEPL("create window RevQuote.win:keepall() as select * from RevisableQuote");
    epService.getEPAdministrator().createEPL("insert into RevQuote select * from FullEvent");
    epService.getEPAdministrator().createEPL("insert into RevQuote select * from D1");
    epService.getEPAdministrator().createEPL("insert into RevQuote select * from D2");
    epService.getEPAdministrator().createEPL("insert into RevQuote select * from D3");
    epService.getEPAdministrator().createEPL("insert into RevQuote select * from D4");
    epService.getEPAdministrator().createEPL("insert into RevQuote select * from D5");

    // assert type metadata
    EventTypeSPI type =
        (EventTypeSPI)
            ((EPServiceProviderSPI) epService)
                .getValueAddEventService()
                .getValueAddProcessor("RevQuote")
                .getValueAddEventType();
    assertEquals(null, type.getMetadata().getOptionalApplicationType());
    assertEquals(null, type.getMetadata().getOptionalSecondaryNames());
    assertEquals("RevisableQuote", type.getMetadata().getPrimaryName());
    assertEquals("RevisableQuote", type.getMetadata().getPublicName());
    assertEquals("RevisableQuote", type.getName());
    assertEquals(EventTypeMetadata.TypeClass.REVISION, type.getMetadata().getTypeClass());
    assertEquals(true, type.getMetadata().isApplicationConfigured());
    assertEquals(true, type.getMetadata().isApplicationPreConfigured());
    assertEquals(true, type.getMetadata().isApplicationPreConfiguredStatic());

    EventType[] valueAddTypes =
        ((EPServiceProviderSPI) epService).getValueAddEventService().getValueAddedTypes();
    assertEquals(1, valueAddTypes.length);
    assertSame(type, valueAddTypes[0]);

    ArrayAssertionUtil.assertEqualsAnyOrder(
        new Object[] {
          new EventPropertyDescriptor("k0", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor("p0", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor("p1", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor("p2", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor("p3", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor("p4", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor("p5", String.class, null, false, false, false, false, false)
        },
        type.getPropertyDescriptors());
  }