private static void tryInstantiate(RegressionEnvironment env, String deploymentId, String graph, String message) { try { env.runtime().getDataFlowService().instantiate(deploymentId, graph); fail(); } catch (EPDataFlowInstantiationException ex) { assertEquals(message, ex.getMessage()); } }
public void run(RegressionEnvironment env) { SupportGraphSource.getAndResetLifecycle(); env.compileDeploy("@name('flow') create dataflow MyDataFlow MyLineFeedSource -> outstream {} SupportOperator(outstream) {propOne:'abc'}"); assertEquals(0, SupportOperator.getAndResetLifecycle().size()); // instantiate MyLineFeedSource src = new MyLineFeedSource(Arrays.asList("abc", "def").iterator()); EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions().operatorProvider(new DefaultSupportGraphOpProvider(src)); EPDataFlowInstance df = env.runtime().getDataFlowService().instantiate(env.deploymentId("flow"), "MyDataFlow", options); List<Object> events = SupportOperator.getAndResetLifecycle(); assertEquals(1, events.size()); assertEquals("instantiated", events.get(0)); // instantiated // run df.run(); events = SupportOperator.getAndResetLifecycle(); assertEquals(4, events.size()); assertTrue(events.get(0) instanceof DataFlowOpOpenContext); // called open (GraphSource only) assertEquals("abc", ((Object[]) events.get(1))[0]); assertEquals("def", ((Object[]) events.get(2))[0]); assertTrue(events.get(3) instanceof DataFlowOpCloseContext); // called close (GraphSource only) env.undeployAll(); } }
public void run(RegressionEnvironment env) { if (env.isHA()) { return; } env.compileDeploy("create objectarray schema MyEventOA(p0 string, p1 long);\n" + "@name('flow') create dataflow MyDataFlowOne " + "Emitter -> instream<MyEventOA> {name: 'E1'}" + "Select(instream as ME) -> astream {select: (select p0, sum(p1) from ME)}"); EPDataFlowInstance df = env.runtime().getDataFlowService().instantiate(env.deploymentId("flow"), "MyDataFlowOne"); EPDataFlowEmitterOperator emitter = df.startCaptive().getEmitters().get("E1"); long start = System.currentTimeMillis(); for (int i = 0; i < 1; i++) { emitter.submit(new Object[]{"E1", 1L}); } long end = System.currentTimeMillis(); //System.out.println("delta=" + (end - start) / 1000d); env.undeployAll(); } }
private static void runAssertion(RegressionEnvironment env) { DefaultSupportCaptureOp<Object> future = new DefaultSupportCaptureOp<Object>(1); MyObjectArrayGraphSource source = new MyObjectArrayGraphSource(Arrays.asList( new Object[]{"trade", "GE", 100d, 1000L, null, null}, // vwap = 100, minPrice=100 new Object[]{"quote", "GE", null, null, 99.5d, 2000L} // ).iterator()); EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions() .operatorProvider(new DefaultSupportGraphOpProvider(future, source)); env.runtime().getDataFlowService().instantiate(env.deploymentId("flow"), "VWAPSample", options).start(); Object[] received; try { received = future.get(5, TimeUnit.SECONDS); } catch (Throwable t) { throw new RuntimeException(t); } assertEquals(1, received.length); EPAssertionUtil.assertProps(received[0], "index".split(","), new Object[]{2000 * Math.exp(100 - 99.5)}); env.undeployAll(); }
public static void tryInvalidInstantiate(RegressionEnvironment env, String name, String epl, String message) { env.compileDeploy("@name('flow') " + epl); try { env.runtime().getDataFlowService().instantiate(env.deploymentId("flow"), name); Assert.fail(); } catch (EPDataFlowInstantiationException ex) { log.info("Expected exception: " + ex.getMessage(), ex); assertException(message, ex.getMessage()); } finally { env.undeployModuleContaining("flow"); } }
public void run(RegressionEnvironment env) { if (env.isHA()) { return; } String epl = "@name('flow') create dataflow TheGraph\n" + "create schema ABC as " + SupportBean.class.getName() + "," + "DefaultSupportSourceOp -> outstream<SupportBean> {}\n" + "Select(outstream) -> selectedData {select: (select theString, intPrimitive from outstream) }\n" + "DefaultSupportCaptureOp(selectedData) {};"; Module module = null; try { module = EPCompilerProvider.getCompiler().parseModule(epl); } catch (Exception e) { fail(e.getMessage()); } assertEquals(1, module.getItems().size()); env.compileDeploy(epl); env.runtime().getDataFlowService().instantiate(env.deploymentId("flow"), "TheGraph"); env.undeployAll(); } }
private static void runAssertionAllTypes(RegressionEnvironment env, String typeName, Object[] events) { String graph = "@name('flow') create dataflow MySelect\n" + "DefaultSupportSourceOp -> instream<" + typeName + ">{}\n" + "Select(instream as ME) -> outstream {select: (select myString, sum(myInt) as total from ME)}\n" + "DefaultSupportCaptureOp(outstream) {}"; env.compileDeploy(graph); DefaultSupportSourceOp source = new DefaultSupportSourceOp(events); DefaultSupportCaptureOp<Object> capture = new DefaultSupportCaptureOp<>(2); EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions(); options.operatorProvider(new DefaultSupportGraphOpProvider(source, capture)); EPDataFlowInstance instance = env.runtime().getDataFlowService().instantiate(env.deploymentId("flow"), "MySelect", options); instance.run(); Object[] result = capture.getAndReset().get(0).toArray(); EPAssertionUtil.assertPropsPerRow(result, "myString,total".split(","), new Object[][]{{"one", 1}, {"two", 3}}); instance.cancel(); env.undeployAll(); }
public void run(RegressionEnvironment env) { RegressionPath path = new RegressionPath(); env.compileDeploy("create map schema MyMap (p0 String, p1 int)", path); env.compileDeploy("@name('flow') create dataflow MyDataFlowOne " + "DefaultSupportSourceOp -> outstream<MyMap> {}" + "MyMapOutputOp(outstream) {}" + "DefaultSupportCaptureOp(outstream) {}", path); DefaultSupportSourceOp source = new DefaultSupportSourceOp(new Object[]{makeMap("E1", 1)}); MyMapOutputOp outputOne = new MyMapOutputOp(); DefaultSupportCaptureOp<SupportBean> outputTwo = new DefaultSupportCaptureOp<SupportBean>(); EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions().operatorProvider(new DefaultSupportGraphOpProvider(source, outputOne, outputTwo)); EPDataFlowInstance dfOne = env.runtime().getDataFlowService().instantiate(env.deploymentId("flow"), "MyDataFlowOne", options); dfOne.run(); EPAssertionUtil.assertPropsPerRow(outputOne.getAndReset().toArray(), "p0,p1".split(","), new Object[][]{{"E1", 1}}); EPAssertionUtil.assertPropsPerRow(outputTwo.getAndReset().get(0).toArray(), "p0,p1".split(","), new Object[][]{{"E1", 1}}); env.undeployAll(); } }
public void run(RegressionEnvironment env) { env.compileDeploy("@name('flow') create dataflow MyDataFlowOne " + "DefaultSupportSourceOp -> outstream<SupportBean> {}" + "MySupportBeanOutputOp(outstream) {}" + "SupportGenericOutputOpWPort(outstream) {}"); DefaultSupportSourceOp source = new DefaultSupportSourceOp(new Object[]{new SupportBean("E1", 1)}); MySupportBeanOutputOp outputOne = new MySupportBeanOutputOp(); SupportGenericOutputOpWPort<SupportBean> outputTwo = new SupportGenericOutputOpWPort<>(); EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions().operatorProvider(new DefaultSupportGraphOpProvider(source, outputOne, outputTwo)); EPDataFlowInstance dfOne = env.runtime().getDataFlowService().instantiate(env.deploymentId("flow"), "MyDataFlowOne", options); dfOne.run(); SupportBean.compare(outputOne.getAndReset().toArray(), "theString,intPrimitive".split(","), new Object[][]{{"E1", 1}}); Pair<List<SupportBean>, List<Integer>> received = outputTwo.getAndReset(); SupportBean.compare(received.getFirst().toArray(), "theString,intPrimitive".split(","), new Object[][]{{"E1", 1}}); EPAssertionUtil.assertEqualsExactOrder(new Integer[]{0}, received.getSecond().toArray()); env.undeployAll(); } }
private void runAssertion(RegressionEnvironment env, String format, Boolean log, String layout, String title, Boolean linefeed) { String graph = "@name('flow') create dataflow MyConsoleOut\n" + "Emitter -> instream<SupportBean>{name : 'e1'}\n" + "LogSink(instream) {\n" + (format == null ? "" : " format: '" + format + "',\n") + (log == null ? "" : " log: " + log + ",\n") + (layout == null ? "" : " layout: '" + layout + "',\n") + (title == null ? "" : " title: '" + title + "',\n") + (linefeed == null ? "" : " linefeed: " + linefeed + ",\n") + "}"; env.compileDeploy(graph); EPDataFlowInstance instance = env.runtime().getDataFlowService().instantiate(env.deploymentId("flow"), "MyConsoleOut"); EPDataFlowEmitterOperator emitterOp = instance.startCaptive().getEmitters().get("e1"); emitterOp.submit(new SupportBean("E1", 1)); instance.cancel(); env.undeployAll(); } }
public static void tryInvalidRun(RegressionEnvironment env, String epl, String name, String message) { env.compileDeploy("@name('flow') " + epl); EPDataFlowInstance df = env.runtime().getDataFlowService().instantiate(env.deploymentId("flow"), name); try { df.run(); Assert.fail(); } catch (EPDataFlowExecutionException ex) { assertException(message, ex.getMessage()); } env.undeployModuleContaining("flow"); }
public void run(RegressionEnvironment env) { RegressionPath path = new RegressionPath(); env.compileDeploy("create schema SomeType ()", path); env.compileDeploy("@name('flow') create dataflow MyDataFlowOne MyOp -> outstream<SomeType> {propOne:'abc', propThree:'xyz'}", path); MyOperatorProvider myOperatorProvider = new MyOperatorProvider(); EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions(); options.operatorProvider(myOperatorProvider); env.runtime().getDataFlowService().instantiate(env.deploymentId("flow"), "MyDataFlowOne", options); assertEquals(1, myOperatorProvider.contextMap.size()); EPDataFlowOperatorProviderContext context = myOperatorProvider.contextMap.get("MyOp"); assertEquals("MyOp", context.getOperatorName()); assertEquals("MyDataFlowOne", context.getDataFlowName()); env.undeployAll(); } }
private static Object runAssertionBeans(RegressionEnvironment env, String typeName) { env.compileDeploy("@name('flow') create dataflow MyDataFlowOne " + "" + "BeaconSource -> BeaconStream<" + typeName + "> {" + " myfield : 'abc', iterations : 1" + "}" + "DefaultSupportCaptureOp(BeaconStream) {}"); DefaultSupportCaptureOp<Object> future = new DefaultSupportCaptureOp<>(1); EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions() .operatorProvider(new DefaultSupportGraphOpProvider(future)); EPDataFlowInstance df = env.runtime().getDataFlowService().instantiate(env.deploymentId("flow"), "MyDataFlowOne", options); df.start(); Object[] output = new Object[0]; try { output = future.get(2, TimeUnit.SECONDS); } catch (Throwable t) { throw new RuntimeException(t); } assertEquals(1, output.length); env.undeployAll(); return output[0]; }
private static void runAssertionAllTypes(RegressionEnvironment env, String typeName, Object[] events) { String graph = "@name('flow') create dataflow MyGraph " + "DefaultSupportSourceOp -> instream<" + typeName + ">{}" + "EventBusSink(instream) {}"; env.compileDeploy(graph); env.compileDeploy("@name('s0') select * from " + typeName).addListener("s0"); DefaultSupportSourceOp source = new DefaultSupportSourceOp(events); EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions(); options.operatorProvider(new DefaultSupportGraphOpProvider(source)); EPDataFlowInstance instance = env.runtime().getDataFlowService().instantiate(env.deploymentId("flow"), "MyGraph", options); instance.run(); EPAssertionUtil.assertPropsPerRow(env.listener("s0").getNewDataListFlattened(), "myDouble,myInt,myString".split(","), new Object[][]{{1.1d, 1, "one"}, {2.2d, 2, "two"}}); env.undeployAll(); }
private static void runAssertionOA(RegressionEnvironment env, RegressionPath path, boolean underlying) { env.compileDeploy("@name('flow') create dataflow MyDataFlowOne " + "EventBusSource -> ReceivedStream<" + (underlying ? "MyEventOA" : "EventBean<MyEventOA>") + "> {} " + "DefaultSupportCaptureOp(ReceivedStream) {}", path); DefaultSupportCaptureOp<Object> future = new DefaultSupportCaptureOp<>(1); EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions() .operatorProvider(new DefaultSupportGraphOpProvider(future)); EPDataFlowInstance instance = env.runtime().getDataFlowService().instantiate(env.deploymentId("flow"), "MyDataFlowOne", options); instance.start(); env.sendEventObjectArray(new Object[]{"abc", 100L}, "MyEventOA"); Object[] rows = new Object[0]; try { rows = future.get(1, TimeUnit.SECONDS); } catch (Throwable t) { throw new RuntimeException(t); } assertEquals(1, rows.length); if (underlying) { EPAssertionUtil.assertEqualsExactOrder((Object[]) rows[0], new Object[]{"abc", 100L}); } else { EPAssertionUtil.assertProps((EventBean) rows[0], "p0,p1".split(","), new Object[]{"abc", 100L}); } instance.cancel(); env.undeployModuleContaining("flow"); }
public void run(RegressionEnvironment env) { if (env.isHA()) { return; } String graph = "@name('flow') create dataflow MySelect\n" + "Emitter -> instream_s0<SupportBean_S0>{name: 'emitterS0'}\n" + "Emitter -> instream_s1<SupportBean_S1>{name: 'emitterS1'}\n" + "Select(instream_s0 as S0, instream_s1 as S1) -> outstream {\n" + " select: (select p00, p10 from S0#keepall full outer join S1#keepall)\n" + "}\n" + "DefaultSupportCaptureOp(outstream) {}\n"; env.compileDeploy(graph); DefaultSupportCaptureOp<Object> capture = new DefaultSupportCaptureOp<>(); Map<String, Object> operators = CollectionUtil.populateNameValueMap("DefaultSupportCaptureOp", capture); EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions().operatorProvider(new DefaultSupportGraphOpProviderByOpName(operators)); EPDataFlowInstance instance = env.runtime().getDataFlowService().instantiate(env.deploymentId("flow"), "MySelect", options); EPDataFlowInstanceCaptive captive = instance.startCaptive(); captive.getEmitters().get("emitterS0").submit(new SupportBean_S0(1, "S0_1")); EPAssertionUtil.assertProps(capture.getCurrentAndReset()[0], "p00,p11".split(","), new Object[]{"S0_1", null}); instance.cancel(); env.undeployAll(); } }
public void run(RegressionEnvironment env) { RegressionPath path = new RegressionPath(); env.compileDeploy("create schema SomeType ()", path); env.compileDeploy("@name('flow') create dataflow MyDataFlowOne " + "DefaultSupportSourceOp -> outstream<SomeType> {}" + "DefaultSupportCaptureOp(outstream) {}", path); DefaultSupportSourceOp src = new DefaultSupportSourceOp(new Object[]{new MyRuntimeException("TestException")}); DefaultSupportCaptureOp<Object> output = new DefaultSupportCaptureOp<Object>(); EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions().operatorProvider(new DefaultSupportGraphOpProvider(src, output)); final EPDataFlowInstance dfOne = env.runtime().getDataFlowService().instantiate(env.deploymentId("flow"), "MyDataFlowOne", options); try { dfOne.run(); fail(); } catch (EPDataFlowExecutionException ex) { assertTrue(ex.getCause().getCause() instanceof MyRuntimeException); assertEquals("Support-graph-source generated exception: TestException", ex.getCause().getMessage()); } assertEquals(EPDataFlowState.COMPLETE, dfOne.getState()); assertEquals(0, output.getAndReset().size()); env.undeployAll(); } }
public void run(RegressionEnvironment env) { RegressionPath path = new RegressionPath(); env.compileDeploy("create Schema SomeEvent()", path); env.compileDeploy("create variable int var_iterations=3", path); env.compileDeploy("@name('flow') create dataflow MyDataFlowOne " + "BeaconSource -> BeaconStream<SomeEvent> {" + " iterations : var_iterations" + "}" + "DefaultSupportCaptureOp(BeaconStream) {}", path); DefaultSupportCaptureOp<Object> future = new DefaultSupportCaptureOp<>(3); EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions() .operatorProvider(new DefaultSupportGraphOpProvider(future)); EPDataFlowInstance df = env.runtime().getDataFlowService().instantiate(env.deploymentId("flow"), "MyDataFlowOne", options); df.start(); Object[] output; try { output = future.get(2, TimeUnit.SECONDS); } catch (Throwable t) { throw new RuntimeException(t); } assertEquals(3, output.length); env.undeployAll(); } }
private static void runAssertionAllTypes(RegressionEnvironment env, String typeName, Object[] events) { String graph = "@name('flow') create dataflow MySelect\n" + "DefaultSupportSourceOp -> instream.with.dot<" + typeName + ">{}\n" + "Filter(instream.with.dot) -> outstream.dot {filter: myString = 'two'}\n" + "DefaultSupportCaptureOp(outstream.dot) {}"; env.compileDeploy(graph); DefaultSupportSourceOp source = new DefaultSupportSourceOp(events); DefaultSupportCaptureOp<Object> capture = new DefaultSupportCaptureOp<>(2); EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions(); options.setDataFlowInstanceUserObject("myuserobject"); options.setDataFlowInstanceId("myinstanceid"); options.operatorProvider(new DefaultSupportGraphOpProvider(source, capture)); EPDataFlowInstance instance = env.runtime().getDataFlowService().instantiate(env.deploymentId("flow"), "MySelect", options); assertEquals("myuserobject", instance.getUserObject()); assertEquals("myinstanceid", instance.getInstanceId()); instance.run(); Object[] result = capture.getAndReset().get(0).toArray(); assertEquals(1, result.length); assertSame(events[1], result[0]); instance.cancel(); env.undeployAll(); } }
public void run(RegressionEnvironment env) { RegressionPath path = new RegressionPath(); env.compileDeploy("create schema SomeType ()", path); env.compileDeploy("@name('flow') create dataflow MyDataFlowOne " + "DefaultSupportSourceOp -> outstream<SomeType> {}" + "DefaultSupportCaptureOp(outstream) {}", path); DefaultSupportSourceOp src = new DefaultSupportSourceOp(new Object[]{new MyRuntimeException("TestException")}); DefaultSupportCaptureOp<Object> output = new DefaultSupportCaptureOp<Object>(); EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions().operatorProvider(new DefaultSupportGraphOpProvider(src, output)); final EPDataFlowInstance dfOne = env.runtime().getDataFlowService().instantiate(env.deploymentId("flow"), "MyDataFlowOne", options); dfOne.start(); sleep(200); assertEquals(EPDataFlowState.COMPLETE, dfOne.getState()); assertEquals(0, output.getAndReset().size()); env.undeployAll(); } }