Ejemplo n.º 1
0
  private Configuration getConfig(
      long engineMetricInterval, long stmtMetricInterval, boolean shareViews) {
    Configuration configuration = SupportConfigFactory.getConfiguration();
    configuration.getEngineDefaults().getViewResources().setShareViews(shareViews);
    configuration.getEngineDefaults().getMetricsReporting().setEnableMetricsReporting(true);
    configuration.getEngineDefaults().getMetricsReporting().setThreading(false);
    configuration.getEngineDefaults().getMetricsReporting().setEngineInterval(engineMetricInterval);
    configuration
        .getEngineDefaults()
        .getMetricsReporting()
        .setStatementInterval(stmtMetricInterval);

    configuration.addImport(MyMetricFunctions.class.getName());

    configuration.addEventType("SupportBean", SupportBean.class);

    return configuration;
  }
 public void setUp() {
   Configuration configuration = SupportConfigFactory.getConfiguration();
   configuration.addEventType("SupportBean", SupportBean.class);
   configuration.addEventType("SupportBean_S0", SupportBean_S0.class);
   configuration.addEventType("SupportBean_S1", SupportBean_S1.class);
   configuration.getEngineDefaults().getLogging().setEnableExecutionDebug(true);
   epService = EPServiceProviderManager.getDefaultProvider(configuration);
   epService.initialize();
 }
Ejemplo n.º 3
0
  public static void main(String[] args)
      throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
    DOMConfigurator.configure("logger.xml");

    Configuration conf = new Configuration();
    conf.configure(new File("configuation.xml"));
    conf.getEngineDefaults().getThreading().setListenerDispatchPreserveOrder(false);

    conf.addEventTypeAutoName(Main.class.getPackage().getName());

    init(conf);

    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(conf);
    String statement = "CREATE WINDOW trainSet.win:length(1000) as select * from InputTuple";
    epService.getEPAdministrator().createEPL(statement);

    statement = "INSERT INTO trainSet SELECT * FROM InputTuple";
    epService.getEPAdministrator().createEPL(statement);

    ////////// TASK 1. Performing Naive Bayes Classification over a data stream

    StreamClassifier classifier = new StreamClassifier(conf);
    classifier.verticalizeTuples(_fieldNames);
    EPStatement stmt = classifier.run(_fieldNames.length + 1);

    /////////// TASK 2. Periodically check quality of the classifier

    PeriodicChecker checker = new PeriodicChecker(conf, stmt);
    checker.run(
        "2 seconds", 100, 0.9); // every two seconds test last 100 tuples to satisfy threshold 0.7

    //////////

    _log.info("started");

    // emulate a continuous input
    AdapterInputSource adapterInputSource = new AdapterInputSource(new File("simulation.csv"));

    CSVInputAdapterSpec spec = new CSVInputAdapterSpec(adapterInputSource, "InputTuple");
    spec.setEventsPerSec(400);
    spec.setLooping(true);
    spec.setUsingEngineThread(true);

    (new CSVInputAdapter(epService, spec)).start();

    try {
      Thread.sleep(10000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    _log.info("stopped");
  }
Ejemplo n.º 4
0
  public void setUp() {
    Map<String, Object> typeInfo = new HashMap<String, Object>();
    typeInfo.put("id", String.class);
    typeInfo.put("p00", int.class);

    Configuration config = SupportConfigFactory.getConfiguration();
    config.addEventType("MapS0", typeInfo);
    config.addEventType("MapS1", typeInfo);

    config.getEngineDefaults().getLogging().setEnableQueryPlan(true);
    epService = EPServiceProviderManager.getDefaultProvider(config);
    epService.initialize();
    if (InstrumentationHelper.ENABLED) {
      InstrumentationHelper.startTest(epService, this.getClass(), getName());
    }
    listener = new SupportUpdateListener();
  }
  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();
    }
  }
Ejemplo n.º 6
0
  /** Comment-in this test for manual/threading tests. */
  public void testManual() {
    Configuration config = getConfig(1000, 1000, true);
    config.getEngineDefaults().getMetricsReporting().setThreading(true);

    /*
    epService = EPServiceProviderManager.getProvider("MyURI", config);
    epService.initialize();

    EPStatement[] statements = new EPStatement[5];

    statements[0] = epService.getEPAdministrator().createEPL("select * from " + StatementMetric.class.getName(), "stmt_metrics");
    statements[0].addListener(new PrintUpdateListener());

    statements[1] = epService.getEPAdministrator().createEPL("select * from " + EngineMetric.class.getName(), "engine_metrics");
    statements[1].addListener(new PrintUpdateListener());

    statements[2] = epService.getEPAdministrator().createEPL("select * from SupportBean(intPrimitive=1).win:keepall() where MyMetricFunctions.takeCPUTime(longPrimitive)", "cpuStmtOne");

    sleep(20000);
    */
  }
Ejemplo n.º 7
0
  public void testEnabledDisableStatement() {
    String[] fields = new String[] {"statementName"};
    EPStatement[] statements = new EPStatement[5];
    Configuration config = getConfig(-1, 10000, true);

    ConfigurationMetricsReporting.StmtGroupMetrics configOne =
        new ConfigurationMetricsReporting.StmtGroupMetrics();
    configOne.setInterval(-1);
    configOne.addIncludeLike("%@METRIC%");
    config.getEngineDefaults().getMetricsReporting().addStmtGroup("metrics", configOne);

    epService = EPServiceProviderManager.getProvider("MyURI", config);
    epService.initialize();

    sendTimer(1000);

    statements[0] =
        epService
            .getEPAdministrator()
            .createEPL("select * from " + StatementMetric.class.getName(), "MyStatement@METRIC");
    statements[0].addListener(listenerStmtMetric);

    statements[1] =
        epService
            .getEPAdministrator()
            .createEPL(
                "select * from SupportBean(intPrimitive=1).win:keepall() where 2=2", "stmtone");
    sendEvent("E1", 1, cpuGoalOneNano);
    statements[2] =
        epService
            .getEPAdministrator()
            .createEPL(
                "select * from SupportBean(intPrimitive>0).std:lastevent() where 1=1", "stmttwo");
    sendEvent("E2", 1, cpuGoalOneNano);

    sendTimer(11000);
    ArrayAssertionUtil.assertPropsPerRow(
        listenerStmtMetric.getNewDataListFlattened(),
        fields,
        new Object[][] {{"stmtone"}, {"stmttwo"}});
    listenerStmtMetric.reset();

    sendEvent("E1", 1, cpuGoalOneNano);
    sendTimer(21000);
    ArrayAssertionUtil.assertPropsPerRow(
        listenerStmtMetric.getNewDataListFlattened(),
        fields,
        new Object[][] {{"stmtone"}, {"stmttwo"}});
    listenerStmtMetric.reset();

    epService.getEPAdministrator().getConfiguration().setMetricsReportingStmtDisabled("stmtone");

    sendEvent("E1", 1, cpuGoalOneNano);
    sendTimer(31000);
    ArrayAssertionUtil.assertPropsPerRow(
        listenerStmtMetric.getNewDataListFlattened(), fields, new Object[][] {{"stmttwo"}});
    listenerStmtMetric.reset();

    epService.getEPAdministrator().getConfiguration().setMetricsReportingStmtEnabled("stmtone");
    epService.getEPAdministrator().getConfiguration().setMetricsReportingStmtDisabled("stmttwo");

    sendEvent("E1", 1, cpuGoalOneNano);
    sendTimer(41000);
    ArrayAssertionUtil.assertPropsPerRow(
        listenerStmtMetric.getNewDataListFlattened(), fields, new Object[][] {{"stmtone"}});
    listenerStmtMetric.reset();
  }
Ejemplo n.º 8
0
  public void testStatementMetrics() {
    Configuration config = getConfig(-1, -1, true);

    // report on all statements every 10 seconds
    ConfigurationMetricsReporting.StmtGroupMetrics configOne =
        new ConfigurationMetricsReporting.StmtGroupMetrics();
    configOne.setInterval(10000);
    configOne.addIncludeLike("%cpuStmt%");
    configOne.addIncludeLike("%wallStmt%");
    config.getEngineDefaults().getMetricsReporting().addStmtGroup("nonmetrics", configOne);

    // exclude metrics themselves from reporting
    ConfigurationMetricsReporting.StmtGroupMetrics configTwo =
        new ConfigurationMetricsReporting.StmtGroupMetrics();
    configTwo.setInterval(-1);
    configOne.addExcludeLike("%metrics%");
    config.getEngineDefaults().getMetricsReporting().addStmtGroup("metrics", configTwo);

    epService = EPServiceProviderManager.getProvider("MyURI", config);
    epService.initialize();

    sendTimer(1000);

    EPStatement[] statements = new EPStatement[5];
    statements[0] =
        epService
            .getEPAdministrator()
            .createEPL("select * from " + StatementMetric.class.getName(), "stmt_metrics");
    statements[0].addListener(listener);

    statements[1] =
        epService
            .getEPAdministrator()
            .createEPL(
                "select * from SupportBean(intPrimitive=1).win:keepall() where MyMetricFunctions.takeCPUTime(longPrimitive)",
                "cpuStmtOne");
    statements[1].addListener(listenerTwo);
    statements[2] =
        epService
            .getEPAdministrator()
            .createEPL(
                "select * from SupportBean(intPrimitive=2).win:keepall() where MyMetricFunctions.takeCPUTime(longPrimitive)",
                "cpuStmtTwo");
    statements[2].addListener(listenerTwo);
    statements[3] =
        epService
            .getEPAdministrator()
            .createEPL(
                "select * from SupportBean(intPrimitive=3).win:keepall() where MyMetricFunctions.takeWallTime(longPrimitive)",
                "wallStmtThree");
    statements[3].addListener(listenerTwo);
    statements[4] =
        epService
            .getEPAdministrator()
            .createEPL(
                "select * from SupportBean(intPrimitive=4).win:keepall() where MyMetricFunctions.takeWallTime(longPrimitive)",
                "wallStmtFour");
    statements[4].addListener(listenerTwo);

    sendEvent("E1", 1, cpuGoalOneNano);
    sendEvent("E2", 2, cpuGoalTwoNano);
    sendEvent("E3", 3, wallGoalOneMsec);
    sendEvent("E4", 4, wallGoalTwoMsec);

    sendTimer(10999);
    assertFalse(listener.isInvoked());

    sendTimer(11000);
    runAssertion(11000);

    sendEvent("E1", 1, cpuGoalOneNano);
    sendEvent("E2", 2, cpuGoalTwoNano);
    sendEvent("E3", 3, wallGoalOneMsec);
    sendEvent("E4", 4, wallGoalTwoMsec);

    sendTimer(21000);
    runAssertion(21000);

    // destroy all application stmts
    for (int i = 1; i < 5; i++) {
      statements[i].destroy();
    }
    sendTimer(31000);
    assertFalse(listener.isInvoked());
  }
Ejemplo n.º 9
0
  public void testStatementGroups() {
    Configuration config = getConfig(-1, 7000, true);

    ConfigurationMetricsReporting.StmtGroupMetrics groupOne =
        new ConfigurationMetricsReporting.StmtGroupMetrics();
    groupOne.setInterval(8000);
    groupOne.addIncludeLike("%GroupOne%");
    groupOne.setReportInactive(true);
    config.getEngineDefaults().getMetricsReporting().addStmtGroup("GroupOneStatements", groupOne);

    ConfigurationMetricsReporting.StmtGroupMetrics groupTwo =
        new ConfigurationMetricsReporting.StmtGroupMetrics();
    groupTwo.setInterval(6000);
    groupTwo.setDefaultInclude(true);
    groupTwo.addExcludeLike("%Default%");
    groupTwo.addExcludeLike("%Metrics%");
    config
        .getEngineDefaults()
        .getMetricsReporting()
        .addStmtGroup("GroupTwoNonDefaultStatements", groupTwo);

    ConfigurationMetricsReporting.StmtGroupMetrics groupThree =
        new ConfigurationMetricsReporting.StmtGroupMetrics();
    groupThree.setInterval(-1);
    groupThree.addIncludeLike("%Metrics%");
    config.getEngineDefaults().getMetricsReporting().addStmtGroup("MetricsStatements", groupThree);

    epService = EPServiceProviderManager.getProvider("MyURI", config);
    epService.initialize();

    sendTimer(0);

    epService
        .getEPAdministrator()
        .createEPL("select * from SupportBean(intPrimitive = 1).win:keepall()", "GroupOne");
    EPStatement stmt =
        epService
            .getEPAdministrator()
            .createEPL("select * from SupportBean(intPrimitive = 2).win:keepall()", "GroupTwo");
    stmt.setSubscriber(new SupportSubscriber());
    epService
        .getEPAdministrator()
        .createEPL(
            "select * from SupportBean(intPrimitive = 3).win:keepall()", "Default"); // no listener

    stmt =
        epService
            .getEPAdministrator()
            .createEPL("select * from " + StatementMetric.class.getName(), "StmtMetrics");
    stmt.addListener(listener);

    sendTimer(6000);
    sendTimer(7000);
    assertFalse(listener.isInvoked());

    sendTimer(8000);
    String[] fields = "statementName,numOutputIStream,numInput".split(",");
    ArrayAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"GroupOne", 0L, 0L});

    sendTimer(12000);
    sendTimer(14000);
    sendTimer(15999);
    assertFalse(listener.isInvoked());

    sendTimer(16000);
    ArrayAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"GroupOne", 0L, 0L});

    // should report as groupTwo
    epService.getEPRuntime().sendEvent(new SupportBean("E1", 2));
    sendTimer(17999);
    assertFalse(listener.isInvoked());

    sendTimer(18000);
    ArrayAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"GroupTwo", 1L, 1L});

    // should report as groupTwo
    epService.getEPRuntime().sendEvent(new SupportBean("E1", 3));
    sendTimer(20999);
    assertFalse(listener.isInvoked());

    sendTimer(21000);
    ArrayAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"Default", 0L, 1L});

    // turn off group 1
    epService
        .getEPAdministrator()
        .getConfiguration()
        .setMetricsReportingInterval("GroupOneStatements", -1);
    sendTimer(24000);
    assertFalse(listener.isInvoked());

    // turn on group 1
    epService
        .getEPAdministrator()
        .getConfiguration()
        .setMetricsReportingInterval("GroupOneStatements", 1000);
    sendTimer(25000);
    ArrayAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"GroupOne", 0L, 0L});
  }
  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();
    }
  }
 @Override
 public ConfigurationEngineDefaults getEngineDefaults() {
   return m_esperconfig.getEngineDefaults();
 }