Esempio n. 1
0
  public void testStartCaptiveCancel() throws Exception {
    String[] fields = "p0,p1".split(",");
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("MyOAEventType", fields, new Object[] {String.class, int.class});

    epService
        .getEPAdministrator()
        .createEPL(
            "create dataflow MyDataFlow "
                + "Emitter -> outstream<MyOAEventType> {name:'src1'}"
                + "DefaultSupportCaptureOp(outstream) {}");

    DefaultSupportCaptureOp<Object> captureOp = new DefaultSupportCaptureOp<Object>();
    EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions();
    options.operatorProvider(new DefaultSupportGraphOpProvider(captureOp));

    EPDataFlowInstance instance =
        epService.getEPRuntime().getDataFlowRuntime().instantiate("MyDataFlow", options);
    EPDataFlowInstanceCaptive captiveStart = instance.startCaptive();
    assertEquals(0, captiveStart.getRunnables().size());
    assertEquals(1, captiveStart.getEmitters().size());
    Emitter emitter = captiveStart.getEmitters().get("src1");
    assertEquals(EPDataFlowState.RUNNING, instance.getState());

    emitter.submit(new Object[] {"E1", 10});
    EPAssertionUtil.assertPropsPerRow(captureOp.getCurrent(), fields, new Object[][] {{"E1", 10}});

    emitter.submit(new Object[] {"E2", 20});
    EPAssertionUtil.assertPropsPerRow(
        captureOp.getCurrent(), fields, new Object[][] {{"E1", 10}, {"E2", 20}});

    emitter.submitSignal(new EPDataFlowSignalFinalMarker() {});
    EPAssertionUtil.assertPropsPerRow(captureOp.getCurrent(), fields, new Object[0][]);
    EPAssertionUtil.assertPropsPerRow(
        captureOp.getAndReset().get(0).toArray(), fields, new Object[][] {{"E1", 10}, {"E2", 20}});

    emitter.submit(new Object[] {"E3", 30});
    EPAssertionUtil.assertPropsPerRow(captureOp.getCurrent(), fields, new Object[][] {{"E3", 30}});

    // stays running until cancelled (no transition to complete)
    assertEquals(EPDataFlowState.RUNNING, instance.getState());

    instance.cancel();
    assertEquals(EPDataFlowState.CANCELLED, instance.getState());

    // test doc sample
    String epl =
        "create dataflow HelloWorldDataFlow\n"
            + "  create schema SampleSchema(text string),\t// sample type\t\t\n"
            + "\t\n"
            + "  Emitter -> helloworld.stream<SampleSchema> { name: 'myemitter' }\n"
            + "  LogSink(helloworld.stream) {}";
    epService.getEPAdministrator().createEPL(epl);
    epService.getEPRuntime().getDataFlowRuntime().instantiate("HelloWorldDataFlow");
  }
Esempio n. 2
0
  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());
  }