public void setUp() {
   epService =
       EPServiceProviderManager.getDefaultProvider(SupportConfigFactory.getConfiguration());
   epService.initialize();
   epService
       .getEPAdministrator()
       .getConfiguration()
       .addImport(DefaultSupportCaptureOp.class.getName());
   MyExceptionHandler.getContexts().clear();
 }
  public void testExceptionHandler() throws Exception {

    epService.getEPAdministrator().getConfiguration().addEventType(SupportBean.class);

    // test exception by graph source
    EPStatement stmtGraph =
        epService
            .getEPAdministrator()
            .createEPL(
                "create dataflow MyDataFlow DefaultSupportSourceOp -> outstream<SupportBean> {}");

    DefaultSupportSourceOp op =
        new DefaultSupportSourceOp(new Object[] {new RuntimeException("My-Exception-Is-Here")});
    EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions();
    options.operatorProvider(new DefaultSupportGraphOpProvider(op));
    MyExceptionHandler handler = new MyExceptionHandler();
    options.exceptionHandler(handler);
    EPDataFlowInstance df =
        epService.getEPRuntime().getDataFlowRuntime().instantiate("MyDataFlow", options);

    df.start();
    Thread.sleep(100);
    assertEquals(EPDataFlowState.COMPLETE, df.getState());

    assertEquals(1, MyExceptionHandler.getContexts().size());
    EPDataFlowExceptionContext context = MyExceptionHandler.getContexts().get(0);
    assertEquals("MyDataFlow", context.getDataFlowName());
    assertEquals("DefaultSupportSourceOp", context.getOperatorName());
    assertEquals(0, context.getOperatorNumber());
    assertEquals(
        "DefaultSupportSourceOp#0() -> outstream<SupportBean>", context.getOperatorPrettyPrint());
    assertEquals(
        "Support-graph-source generated exception: My-Exception-Is-Here",
        context.getThrowable().getMessage());
    df.cancel();
    stmtGraph.destroy();
    MyExceptionHandler.getContexts().clear();

    // test exception by operator
    epService.getEPAdministrator().getConfiguration().addImport(MyExceptionOp.class);
    epService
        .getEPAdministrator()
        .createEPL(
            "create dataflow MyDataFlow DefaultSupportSourceOp -> outstream<SupportBean> {}"
                + "MyExceptionOp(outstream) {}");

    DefaultSupportSourceOp opTwo =
        new DefaultSupportSourceOp(new Object[] {new SupportBean("E1", 1)});
    EPDataFlowInstantiationOptions optionsTwo = new EPDataFlowInstantiationOptions();
    optionsTwo.operatorProvider(new DefaultSupportGraphOpProvider(opTwo));
    MyExceptionHandler handlerTwo = new MyExceptionHandler();
    optionsTwo.exceptionHandler(handlerTwo);
    EPDataFlowInstance dfTwo =
        epService.getEPRuntime().getDataFlowRuntime().instantiate("MyDataFlow", optionsTwo);

    dfTwo.start();
    Thread.sleep(100);

    assertEquals(1, MyExceptionHandler.getContexts().size());
    EPDataFlowExceptionContext contextTwo = MyExceptionHandler.getContexts().get(0);
    assertEquals("MyDataFlow", contextTwo.getDataFlowName());
    assertEquals("MyExceptionOp", contextTwo.getOperatorName());
    assertEquals(1, contextTwo.getOperatorNumber());
    assertEquals("MyExceptionOp#1(outstream)", contextTwo.getOperatorPrettyPrint());
    assertEquals("Operator-thrown-exception", contextTwo.getThrowable().getMessage());
  }