예제 #1
0
 public void setUp() {
   epService =
       EPServiceProviderManager.getDefaultProvider(SupportConfigFactory.getConfiguration());
   epService.initialize();
   feedListener = new SupportUpdateListener();
   resultListenerDelta = new SupportUpdateListener();
   resultListenerProduct = new SupportUpdateListener();
 }
  private EPServiceProvider getEngineInitialized(
      String name, String[] propertyNames, Object[] propertyTypes) {
    Configuration configuration = SupportConfigFactory.getConfiguration();
    if (name != null) {
      configuration.addEventType(name, propertyNames, propertyTypes);
    }

    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(configuration);
    epService.initialize();
    return epService;
  }
예제 #3
0
 public void setUp() {
   Configuration config = SupportConfigFactory.getConfiguration();
   config.addEventType("S0", SupportBean_S0.class);
   config.addEventType("S1", SupportBean_S1.class);
   config.addEventType("S2", SupportBean_S2.class);
   config.addEventType("S3", SupportBean_S3.class);
   config.addEventType("S4", SupportBean_S4.class);
   config.addEventType("S5", SupportBean_S5.class);
   epService = EPServiceProviderManager.getDefaultProvider(config);
   epService.initialize();
   listener = new SupportUpdateListener();
 }
  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 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();
    }
  }
  public void testObjectArrayInheritanceRuntime() {
    Configuration configuration = SupportConfigFactory.getConfiguration();

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

    ConfigurationOperations configOps = epService.getEPAdministrator().getConfiguration();
    configOps.addEventType("RootEvent", new String[] {"base"}, new Object[] {String.class});
    configOps.addEventType(
        "Sub1Event",
        new String[] {"sub1"},
        new Object[] {String.class},
        new ConfigurationEventTypeObjectArray(Collections.singleton("RootEvent")));
    configOps.addEventType(
        "Sub2Event",
        new String[] {"sub2"},
        new Object[] {String.class},
        new ConfigurationEventTypeObjectArray(Collections.singleton("RootEvent")));
    configOps.addEventType(
        "SubAEvent",
        new String[] {"suba"},
        new Object[] {String.class},
        new ConfigurationEventTypeObjectArray(Collections.singleton("Sub1Event")));
    configOps.addEventType(
        "SubBEvent",
        new String[] {"subb"},
        new Object[] {String.class},
        new ConfigurationEventTypeObjectArray(Collections.singleton("SubAEvent")));

    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();
    }
  }
예제 #8
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());
  }