public void TestEndOfFileMarker() { CompileDeploy(runtime, "@public @buseventtype create objectarray schema MyBOF (filename string)"); CompileDeploy(runtime, "@public @buseventtype create objectarray schema MyEOF (filename string)"); CompileDeploy(runtime, "@public @buseventtype create objectarray schema MyLine (filename string, line string)"); CompileDeploy( runtime, "@public create context FileContext " + "initiated by MyBOF as mybof " + "terminated by MyEOF(filename=mybof.filename)"); var stmtCount = CompileDeploy( runtime, "context FileContext " + "select context.mybof.filename as filename, count(*) as cnt " + "from MyLine(filename=context.mybof.filename) " + "output snapshot when terminated") .Statements[0]; var listener = new SupportUpdateListener(); stmtCount.AddListener(listener); var epl = "create dataflow MyEOFEventFileReader " + "FileSource -> mylines<MyLine>, mybof<MyBOF>, myeof<MyEOF> { " + "numLoops: 1, format: 'line', " + "propertyNameLine: 'line', propertyNameFile: 'filename'}\n" + "EventBusSink(mylines, mybof, myeof) {}\n"; var deployment = CompileDeploy(runtime, epl); foreach (var filename in new[] { "../../../etc/regression/line_file_1.txt", "../../../etc/regression/line_file_2.txt" }) { var options = new EPDataFlowInstantiationOptions(); options.AddParameterURI("FileSource/file", filename); var instance = runtime.DataFlowService.Instantiate(deployment.DeploymentId, "MyEOFEventFileReader", options); instance.Run(); Assert.AreEqual(1, instance.Parameters.Count); Assert.AreEqual(filename, instance.Parameters.Get("FileSource/file")); } EPAssertionUtil.AssertPropsPerRowAnyOrder( listener.NewDataListFlattened, "filename,cnt".SplitCsv(), new[] { new object[] {"../../../etc/regression/line_file_1.txt", 3L}, new object[] {"../../../etc/regression/line_file_2.txt", 2L} }); }
public void TestBeaconFields() { RunAssertionFields(EventRepresentationEnum.MAP, true); RunAssertionFields(EventRepresentationEnum.OBJECTARRAY, true); RunAssertionFields(EventRepresentationEnum.MAP, false); RunAssertionFields(EventRepresentationEnum.OBJECTARRAY, false); // test doc samples _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("GenerateTagId", GetType().FullName, "GenerateTagId"); var epl = "create dataflow MyDataFlow\n" + " create schema SampleSchema(tagId string, locX double, locY double)," + " " + " // BeaconSource that produces empty object-array events without delay or interval\n" + " // until cancelled.\n" + " BeaconSource -> stream.one {}\n" + " \n" + " // BeaconSource that produces one RFIDSchema event populating event properties\n" + " // from a user-defined function \"generateTagId\" and values.\n" + " BeaconSource -> stream.two<SampleSchema> {\n" + " iterations : 1,\n" + " tagId : GenerateTagId(),\n" + " locX : 10,\n" + " locY : 20 \n" + " }\n" + " \n" + " // BeaconSource that produces 10 object-array events populating the price property \n" + " // with a random value.\n" + " BeaconSource -> stream.three {\n" + " iterations : 1,\n" + " interval : 10, // every 10 seconds\n" + " initialDelay : 5, // start after 5 seconds\n" + " price : MyMath.Random() * 100,\n" + " }"; _epService.EPAdministrator.CreateEPL(epl); _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlow"); // test options-provided beacon field _epService.EPAdministrator.Configuration.AddEventType(typeof(SupportBean)); var eplMinimal = "create dataflow MyGraph " + "BeaconSource -> outstream<SupportBean> {iterations:1} " + "EventBusSink(outstream) {}"; _epService.EPAdministrator.CreateEPL(eplMinimal); var options = new EPDataFlowInstantiationOptions(); options.AddParameterURI("BeaconSource/TheString", "E1"); var instance = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyGraph", options); var listener = new SupportUpdateListener(); _epService.EPAdministrator.CreateEPL("select * from SupportBean").Events += listener.Update; instance.Run(); Thread.Sleep(200); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), "TheString".Split(','), new Object[] { "E1" }); // invalid: no output stream SupportDataFlowAssertionUtil.TryInvalidInstantiate(_epService, "DF1", "create dataflow DF1 BeaconSource {}", "Failed to instantiate data flow 'DF1': Failed initialization for operator 'BeaconSource': BeaconSource operator requires one output stream but produces 0 streams"); }
public void Run(RegressionEnvironment env) { foreach (var rep in new[] {EventRepresentationChoice.AVRO}) { RunAssertionFields(env, rep, true); RunAssertionFields(env, rep, false); } // test doc samples var epl = "@Name('flow') create dataflow MyDataFlow\n" + " create schema SampleSchema(tagId string, locX double, locY double)," + " " + " // BeaconSource that produces empty object-array events without delay or interval\n" + " // until cancelled.\n" + " BeaconSource -> stream.one {}\n" + " \n" + " // BeaconSource that produces one RFIDSchema event populating event properties\n" + " // from a user-defined function \"generateTagId\" and values.\n" + " BeaconSource -> stream.two<SampleSchema> {\n" + " iterations : 1,\n" + " tagId : generateTagId(),\n" + " locX : 10,\n" + " locY : 20 \n" + " }\n" + " \n" + " // BeaconSource that produces 10 object-array events populating the Price property \n" + " // with a random value.\n" + " BeaconSource -> stream.three {\n" + " iterations : 1,\n" + " interval : 10, // every 10 seconds\n" + " initialDelay : 5, // start after 5 seconds\n" + " price : Randomizer.Random() * 100,\n" + " }"; env.CompileDeploy(epl); env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlow"); env.UndeployAll(); // test options-provided beacon field var eplMinimal = "@Name('flow') create dataflow MyGraph " + "BeaconSource -> outstream<SupportBean> {iterations:1} " + "EventBusSink(outstream) {}"; env.CompileDeploy(eplMinimal); var options = new EPDataFlowInstantiationOptions(); options.AddParameterURI("BeaconSource/TheString", "E1"); var instance = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyGraph", options); env.CompileDeploy("@Name('s0') select * from SupportBean").AddListener("s0"); instance.Run(); Sleep(200); EPAssertionUtil.AssertProps( env.Listener("s0").AssertOneGetNewAndReset(), new [] { "TheString" }, new object[] {"E1"}); // invalid: no output stream TryInvalidCompile( env, "create dataflow DF1 BeaconSource {}", "Failed to obtain operator 'BeaconSource': BeaconSource operator requires one output stream but produces 0 streams"); env.UndeployAll(); }