Esempio n. 1
0
  public void testFlattenList() {
    // test many arrays
    EventBean[] testEvents =
        makeEventArray(new String[] {"a1", "a2", "b1", "b2", "b3", "c1", "c2"});
    ArrayDeque<UniformPair<EventBean[]>> eventVector = new ArrayDeque<UniformPair<EventBean[]>>();

    eventVector.add(
        new UniformPair<EventBean[]>(null, new EventBean[] {testEvents[0], testEvents[1]}));
    eventVector.add(new UniformPair<EventBean[]>(new EventBean[] {testEvents[2]}, null));
    eventVector.add(
        new UniformPair<EventBean[]>(
            null, new EventBean[] {testEvents[3], testEvents[4], testEvents[5]}));
    eventVector.add(new UniformPair<EventBean[]>(new EventBean[] {testEvents[6]}, null));

    UniformPair<EventBean[]> events = EventBeanUtility.flattenList(eventVector);
    EPAssertionUtil.assertEqualsExactOrder(
        new EventBean[] {testEvents[2], testEvents[6]}, events.getFirst());
    EPAssertionUtil.assertEqualsExactOrder(
        new EventBean[] {testEvents[0], testEvents[1], testEvents[3], testEvents[4], testEvents[5]},
        events.getSecond());

    // test just one array
    eventVector.clear();
    eventVector.add(new UniformPair<EventBean[]>(new EventBean[] {testEvents[2]}, null));
    events = EventBeanUtility.flattenList(eventVector);
    EPAssertionUtil.assertEqualsExactOrder(new EventBean[] {testEvents[2]}, events.getFirst());
    EPAssertionUtil.assertEqualsExactOrder((Object[]) null, events.getSecond());

    // test empty vector
    eventVector.clear();
    events = EventBeanUtility.flattenList(eventVector);
    assertNull(events);
  }
  public void testMixedEntryElement() {
    LinkedList<EventBean> list1 = new LinkedList<EventBean>();
    list1.add(events.get("a"));
    MultiKeyUntyped keyA = new MultiKeyUntyped(new Object[] {"keyA"});
    testMap.put(keyA, list1);
    LinkedList<EventBean> list2 = new LinkedList<EventBean>();
    list2.add(events.get("c"));
    list2.add(events.get("d"));
    MultiKeyUntyped keyB = new MultiKeyUntyped(new Object[] {"keyB"});
    testMap.put(keyB, list2);
    LinkedList<EventBean> list3 = new LinkedList<EventBean>();
    list3.add(events.get("e"));
    list3.add(events.get("f"));
    list3.add(events.get("g"));
    MultiKeyUntyped keyC = new MultiKeyUntyped(new Object[] {"keyC"});
    testMap.put(keyC, list3);

    Iterator<EventBean> it = new SortWindowIterator(testMap);
    EPAssertionUtil.assertEqualsExactOrder(
        new EventBean[] {
          events.get("a"),
          events.get("c"),
          events.get("d"),
          events.get("e"),
          events.get("f"),
          events.get("g")
        },
        it);
  }
  private void runAssertionOnSelectWindowAgg(Object[][] expectedType, Object[] rowValues) {
    EPStatement stmt =
        epService
            .getEPAdministrator()
            .createEPL(
                "on SupportBean_S2 select "
                    + "window(win.*) as c0,"
                    + "last(win.*) as c1, "
                    + "first(win.*) as c2, "
                    + "first(p1) as c3,"
                    + "window(p1) as c4,"
                    + "sorted(p1) as c5,"
                    + "minby(p1) as c6"
                    + " from MyTable as win");
    stmt.addListener(listener);

    epService.getEPRuntime().sendEvent(new SupportBean_S2(0));
    EventBean event = listener.assertOneGetNewAndReset();
    for (String col : "c1,c2,c6".split(",")) {
      assertEventUnd(event.get(col), rowValues);
    }
    for (String col : "c0,c5".split(",")) {
      assertEventUnd(((Object[][]) event.get(col))[0], rowValues);
    }
    assertEquals("b", event.get("c3"));
    EPAssertionUtil.assertEqualsExactOrder(new String[] {"b"}, (String[]) event.get("c4"));

    stmt.destroy();
  }
  public void testOneElement() {
    LinkedList<EventBean> list = new LinkedList<EventBean>();
    list.add(events.get("a"));
    MultiKeyUntyped key = new MultiKeyUntyped(new Object[] {"akey"});
    testMap.put(key, list);

    Iterator<EventBean> it = new SortWindowIterator(testMap);
    EPAssertionUtil.assertEqualsExactOrder(new EventBean[] {events.get("a")}, it);
  }
  public void testTwoSeparateEntryElement() {
    LinkedList<EventBean> list1 = new LinkedList<EventBean>();
    list1.add(events.get("a"));
    MultiKeyUntyped keyB = new MultiKeyUntyped(new Object[] {"keyB"});
    testMap.put(keyB, list1);
    LinkedList<EventBean> list2 = new LinkedList<EventBean>();
    list2.add(events.get("b"));
    MultiKeyUntyped keyA = new MultiKeyUntyped(new Object[] {"keyA"});
    testMap.put(keyA, list2); // Actually before list1

    Iterator<EventBean> it = new SortWindowIterator(testMap);
    EPAssertionUtil.assertEqualsExactOrder(new EventBean[] {events.get("b"), events.get("a")}, it);
  }
  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();
    }
  }
Esempio n. 7
0
  private void assertModule(
      Module module,
      String name,
      String usesCSV,
      String importsCSV,
      String[] statementsExpected,
      boolean[] commentsExpected,
      int[] lineNumsExpected,
      int[] charStartsExpected,
      int[] charEndsExpected) {
    assertEquals(name, module.getName());

    String[] expectedUses = usesCSV == null ? new String[0] : usesCSV.split(",");
    EPAssertionUtil.assertEqualsExactOrder(expectedUses, module.getUses().toArray());

    String[] expectedImports = importsCSV == null ? new String[0] : importsCSV.split(",");
    EPAssertionUtil.assertEqualsExactOrder(expectedImports, module.getImports().toArray());

    String[] stmtsFound = new String[module.getItems().size()];
    boolean[] comments = new boolean[module.getItems().size()];
    int[] lineNumsFound = new int[module.getItems().size()];
    int[] charStartsFound = new int[module.getItems().size()];
    int[] charEndsFound = new int[module.getItems().size()];

    for (int i = 0; i < module.getItems().size(); i++) {
      stmtsFound[i] = module.getItems().get(i).getExpression();
      comments[i] = module.getItems().get(i).isCommentOnly();
      lineNumsFound[i] = module.getItems().get(i).getLineNumber();
      charStartsFound[i] = module.getItems().get(i).getCharPosStart();
      charEndsFound[i] = module.getItems().get(i).getCharPosEnd();
    }

    EPAssertionUtil.assertEqualsExactOrder(statementsExpected, stmtsFound);
    EPAssertionUtil.assertEqualsExactOrder(commentsExpected, comments);

    boolean isCompareLineNums = false;
    for (int l : lineNumsExpected) {
      if (l > 0) {
        isCompareLineNums = true;
      }
    }
    if (isCompareLineNums) {
      EPAssertionUtil.assertEqualsExactOrder(lineNumsExpected, lineNumsFound);
      EPAssertionUtil.assertEqualsExactOrder(charStartsExpected, charStartsFound);
      EPAssertionUtil.assertEqualsExactOrder(charEndsExpected, charEndsFound);
    }
  }
Esempio n. 8
0
  public void testAddRemoveType() {
    epService = EPServiceProviderManager.getProvider("TestSchemaXML", getConfig(false));
    epService.initialize();
    updateListener = new SupportUpdateListener();
    ConfigurationOperations configOps = epService.getEPAdministrator().getConfiguration();

    // test remove type with statement used (no force)
    configOps.addEventType("MyXMLEvent", getConfigTestType("p01", false));
    EPStatement stmt =
        epService.getEPAdministrator().createEPL("select p01 from MyXMLEvent", "stmtOne");
    EPAssertionUtil.assertEqualsExactOrder(
        configOps.getEventTypeNameUsedBy("MyXMLEvent").toArray(), new String[] {"stmtOne"});

    try {
      configOps.removeEventType("MyXMLEvent", false);
    } catch (ConfigurationException ex) {
      assertTrue(ex.getMessage().contains("MyXMLEvent"));
    }

    // destroy statement and type
    stmt.destroy();
    assertTrue(configOps.getEventTypeNameUsedBy("MyXMLEvent").isEmpty());
    assertTrue(configOps.isEventTypeExists("MyXMLEvent"));
    assertTrue(configOps.removeEventType("MyXMLEvent", false));
    assertFalse(configOps.removeEventType("MyXMLEvent", false)); // try double-remove
    assertFalse(configOps.isEventTypeExists("MyXMLEvent"));
    try {
      epService.getEPAdministrator().createEPL("select p01 from MyXMLEvent");
      fail();
    } catch (EPException ex) {
      // expected
    }

    // add back the type
    configOps.addEventType("MyXMLEvent", getConfigTestType("p20", false));
    assertTrue(configOps.isEventTypeExists("MyXMLEvent"));
    assertTrue(configOps.getEventTypeNameUsedBy("MyXMLEvent").isEmpty());

    // compile
    epService.getEPAdministrator().createEPL("select p20 from MyXMLEvent", "stmtTwo");
    EPAssertionUtil.assertEqualsExactOrder(
        configOps.getEventTypeNameUsedBy("MyXMLEvent").toArray(), new String[] {"stmtTwo"});
    try {
      epService.getEPAdministrator().createEPL("select p01 from MyXMLEvent");
      fail();
    } catch (EPException ex) {
      // expected
    }

    // remove with force
    try {
      configOps.removeEventType("MyXMLEvent", false);
    } catch (ConfigurationException ex) {
      assertTrue(ex.getMessage().contains("MyXMLEvent"));
    }
    assertTrue(configOps.removeEventType("MyXMLEvent", true));
    assertFalse(configOps.isEventTypeExists("MyXMLEvent"));
    assertTrue(configOps.getEventTypeNameUsedBy("MyXMLEvent").isEmpty());

    // add back the type
    configOps.addEventType("MyXMLEvent", getConfigTestType("p03", false));
    assertTrue(configOps.isEventTypeExists("MyXMLEvent"));

    // compile
    epService.getEPAdministrator().createEPL("select p03 from MyXMLEvent");
    try {
      epService.getEPAdministrator().createEPL("select p20 from MyXMLEvent");
      fail();
    } catch (EPException ex) {
      // expected
    }
  }
Esempio n. 9
0
 private void assertIntegerIndexed(EventBean event, SupportBean[] events) {
   EPAssertionUtil.assertEqualsExactOrder(events, (Object[]) event.get("c0.myevents"));
   EPAssertionUtil.assertEqualsExactOrder(events, (Object[]) event.get("c1"));
   assertSame(events[events.length - 1], event.get("c2"));
 }
 public void testEmpty() {
   Iterator<EventBean> it = new SortWindowIterator(testMap);
   EPAssertionUtil.assertEqualsExactOrder(null, it);
 }
 private void assertEventUnd(Object underlying, Object[] expectedValues) {
   Object[] und = (Object[]) underlying;
   EPAssertionUtil.assertEqualsExactOrder(expectedValues, und);
 }