Beispiel #1
0
  public void testInvalidStreamUsed() {
    String stmtText =
        "insert into Event_1 (delta, product) "
            + "select intPrimitive - intBoxed as deltaTag, intPrimitive * intBoxed as productTag "
            + "from "
            + SupportBean.class.getName()
            + ".win:length(100)";
    epService.getEPAdministrator().createEPL(stmtText);

    try {
      stmtText =
          "insert into Event_1(delta) "
              + "select (intPrimitive - intBoxed) as deltaTag "
              + "from "
              + SupportBean.class.getName()
              + ".win:length(100)";
      epService.getEPAdministrator().createEPL(stmtText);
      fail();
    } catch (EPStatementException ex) {
      // expected
      assertEquals(
          "Error starting statement: Event type named 'Event_1' has already been declared with differing column name or type information: Type by name 'Event_1' expects 2 properties but receives 1 properties [insert into Event_1(delta) select (intPrimitive - intBoxed) as deltaTag from com.espertech.esper.support.bean.SupportBean.win:length(100)]",
          ex.getMessage());
    }
  }
 private void tryInvalid(String stmtText, String expectedMsg) {
   try {
     epService.getEPAdministrator().createEPL(stmtText);
     fail();
   } catch (EPStatementException ex) {
     assertEquals(expectedMsg, ex.getMessage());
   }
 }
  public void testInvalidInsertInto() {
    try {
      epService
          .getEPAdministrator()
          .createEPL("insert into RevQuote select * from " + SupportBean.class.getName());
      fail();
    } catch (EPStatementException ex) {
      assertEquals(
          "Error starting statement: Selected event type is not a valid base or delta event type of revision event type 'RevisableQuote' [insert into RevQuote select * from com.espertech.esper.support.bean.SupportBean]",
          ex.getMessage());
    }

    try {
      epService
          .getEPAdministrator()
          .createEPL(
              "insert into RevQuote select intPrimitive as k0 from " + SupportBean.class.getName());
      fail();
    } catch (EPStatementException ex) {
      assertEquals(
          "Error starting statement: Selected event type is not a valid base or delta event type of revision event type 'RevisableQuote' [insert into RevQuote select intPrimitive as k0 from com.espertech.esper.support.bean.SupportBean]",
          ex.getMessage());
    }
  }
  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());
    }
  }