public void TestEngineThread1PerSec() { _runtime = EPRuntimeProvider.GetRuntime("testExistingTypeNoOptions", MakeConfig("TypeA")); _runtime.Initialize(); var stmt = CompileDeploy(_runtime, "select symbol, price, volume from TypeA#length(100)").Statements[0]; var listener = new SupportUpdateListener(); stmt.Events += listener.Update; var spec = new CSVInputAdapterSpec(new AdapterInputSource(_container, CSV_FILENAME_ONELINE_TRADE_MULTIPLE), "TypeA"); spec.EventsPerSec = 1; spec.IsUsingEngineThread = true; InputAdapter inputAdapter = new CSVInputAdapter(_runtime, spec); inputAdapter.Start(); Thread.Sleep(1500); Assert.AreEqual(1, listener.GetNewDataList().Count); listener.Reset(); Thread.Sleep(300); Assert.AreEqual(0, listener.GetNewDataList().Count); Thread.Sleep(2000); Assert.IsTrue(listener.GetNewDataList().Count >= 2); }
public void TestDynamicType() { var spec = new CSVInputAdapterSpec(new AdapterInputSource(CSV_FILENAME_ONELINE_TRADE), "TypeB"); var config = new Configuration(); config.EngineDefaults.ThreadingConfig.IsInternalTimerEnabled = false; EPService = EPServiceProviderManager.GetDefaultProvider(config); EPService.Initialize(); InputAdapter feed = new CSVInputAdapter(EPService, spec); EPStatement stmt = EPService.EPAdministrator.CreateEPL("select symbol, price, volume from TypeB.win:length(100)"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; Assert.AreEqual(typeof(String), stmt.EventType.GetPropertyType("symbol")); Assert.AreEqual(typeof(String), stmt.EventType.GetPropertyType("price")); Assert.AreEqual(typeof(String), stmt.EventType.GetPropertyType("volume")); feed.Start(); Assert.AreEqual(1, listener.GetNewDataList().Count); }
public void TestAutoTyped() { var config = new Configuration(); EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(config); var adapter = new CSVInputAdapter( epService, new AdapterInputSource(new StringReader("sym,price\nGOOG,22\nGOOG,33")), "MarketData" ); try { epService.EPAdministrator.CreateEPL("select Sum(price) from MarketData#length(2)"); Assert.Fail("should fail due to type conversion"); } catch (EPStatementException e) { Assert.IsTrue(e.Message.Contains("Implicit conversion")); } var adapter2 = new CSVInputAdapter( epService, new AdapterInputSource(new StringReader("sym,long price\nGOOG,22\nGOOG,33")), "MarketData2" ); epService.EPAdministrator.CreateEPL("select Sum(price) from MarketData2#length(2)"); }
public void TestDynamicType() { var spec = new CSVInputAdapterSpec( new AdapterInputSource(_container, CSV_FILENAME_ONELINE_TRADE), "TypeB"); var config = new Configuration(_container); config.Runtime.Threading.IsInternalTimerEnabled = false; _runtime = EPRuntimeProvider.GetDefaultRuntime(config); _runtime.Initialize(); CompileDeploy(_runtime, "@public @buseventtype create schema TypeB(symbol string, price string, volume string)"); InputAdapter feed = new CSVInputAdapter(_runtime, spec); var stmt = CompileDeploy(_runtime, "select symbol, price, volume from TypeB#length(100)").Statements[0]; var listener = new SupportUpdateListener(); stmt.Events += listener.Update; Assert.AreEqual(typeof(string), stmt.EventType.GetPropertyType("symbol")); Assert.AreEqual(typeof(string), stmt.EventType.GetPropertyType("price")); Assert.AreEqual(typeof(string), stmt.EventType.GetPropertyType("volume")); feed.Start(); Assert.AreEqual(1, listener.GetNewDataList().Count); }
public void TestReadWritePropsBean() { var configuration = new Configuration(_container); configuration.Common.AddEventType("ExampleMarketDataBeanReadWrite", typeof(ExampleMarketDataBeanReadWrite)); //configuration.Common.AddImportNamespace(typeof(FileSourceCSV)); configuration.Common.AddImportNamespace(typeof(DefaultSupportCaptureOp)); _runtime = EPRuntimeProvider.GetRuntime("testExistingTypeNoOptions", configuration); _runtime.Initialize(); var stmt = CompileUtil.CompileDeploy(_runtime, "select * from ExampleMarketDataBeanReadWrite#length(100)").Statements[0]; var listener = new SupportUpdateListener(); stmt.Events += listener.Update; var inputAdapter = new CSVInputAdapter( _runtime, // _baseUseCase.Runtime, new AdapterInputSource(_container, TestCSVAdapterUseCases.CSV_FILENAME_ONELINE_TRADE), "ReadWrite"); inputAdapter.Start(); Assert.AreEqual(1, listener.GetNewDataList().Count); var eb = listener.GetNewDataList()[0][0]; Assert.IsTrue(typeof(ExampleMarketDataBeanReadWrite) == eb.Underlying.GetType()); Assert.AreEqual(55.5 * 1000, eb.Get("value")); }
public void TestEngineThread1PerSec() { EPService = EPServiceProviderManager.GetProvider("testExistingTypeNoOptions", MakeConfig("TypeA")); EPService.Initialize(); EPStatement stmt = EPService.EPAdministrator.CreateEPL("select symbol, price, volume from TypeA.win:length(100)"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; var spec = new CSVInputAdapterSpec(new AdapterInputSource(CSV_FILENAME_ONELINE_TRADE_MULTIPLE), "TypeA"); spec.EventsPerSec = 1; spec.IsUsingEngineThread = true; InputAdapter inputAdapter = new CSVInputAdapter(EPService, spec); inputAdapter.Start(); Thread.Sleep(1500); Assert.AreEqual(1, listener.GetNewDataList().Count); listener.Reset(); Thread.Sleep(300); Assert.AreEqual(0, listener.GetNewDataList().Count); Thread.Sleep(2000); Assert.IsTrue(listener.GetNewDataList().Count >= 2); }
public void TestReadWritePropsBean() { Configuration configuration = new Configuration(); configuration.AddEventType("ReadWrite", typeof(ExampleMarketDataBeanReadWrite)); _baseUseCase.EPService = EPServiceProviderManager.GetProvider("testExistingTypeNoOptions", configuration); _baseUseCase.EPService.Initialize(); EPStatement stmt = _baseUseCase.EPService.EPAdministrator.CreateEPL("select * from ReadWrite.win:length(100)"); SupportUpdateListener listener = new SupportUpdateListener(); stmt.Events += listener.Update; var inputAdapter = new CSVInputAdapter(_baseUseCase.EPService, new AdapterInputSource( TestCSVAdapterUseCases.CSV_FILENAME_ONELINE_TRADE), "ReadWrite"); inputAdapter.Start(); Assert.AreEqual(1, listener.GetNewDataList().Count); EventBean eb = listener.GetNewDataList()[0][0]; Assert.IsTrue(typeof(ExampleMarketDataBeanReadWrite) == eb.Underlying.GetType()); Assert.AreEqual(55.5 * 1000, eb.Get("value")); }
public void TestNullEPService() { var adapter = new CSVInputAdapter(null, new AdapterInputSource("regression/titleRow.csv"), eventTypeName); RunNullEPService(adapter); listener.Reset(); adapter = new CSVInputAdapter(new AdapterInputSource("regression/titleRow.csv"), eventTypeName); RunNullEPService(adapter); }
public void TestReadWritePropsBean() { var configuration = new Configuration(_container); configuration.Common.AddEventType("ExampleMarketDataBeanReadWrite", typeof(ExampleMarketDataBeanReadWrite)); configuration.Common.AddImportNamespace(typeof(FileSourceCSV)); configuration.Common.AddImportNamespace(typeof(DefaultSupportCaptureOp)); _runtime = EPRuntimeProvider.GetRuntime("testExistingTypeNoOptions", configuration); _runtime.Initialize(); var stmt = CompileUtil.CompileDeploy(_runtime, "select * from ExampleMarketDataBeanReadWrite#length(100)").Statements[0]; var listener = new SupportUpdateListener(); stmt.Events += listener.Update; var inputAdapter = new CSVInputAdapter( _runtime, new AdapterInputSource(_container, CSV_FILENAME_ONELINE_TRADE), "ExampleMarketDataBeanReadWrite"); inputAdapter.Start(); Assert.AreEqual(1, listener.GetNewDataList().Count); var eb = listener.GetNewDataList()[0][0]; Assert.IsTrue(typeof(ExampleMarketDataBeanReadWrite) == eb.Underlying.GetType()); Assert.AreEqual(55.5 * 1000, eb.Get("value")); // test graph var graph = "create dataflow ReadCSV " + "FileSource -> mystream<ExampleMarketDataBeanReadWrite> { file: '" + CSV_FILENAME_ONELINE_TRADE + "', hasTitleLine: true }" + "DefaultSupportCaptureOp(mystream) {}"; var deployment = CompileUtil.CompileDeploy(_runtime, graph); var outputOp = new DefaultSupportCaptureOp(); var instance = _runtime.DataFlowService.Instantiate( deployment.DeploymentId, "ReadCSV", new EPDataFlowInstantiationOptions().WithOperatorProvider(new DefaultSupportGraphOpProvider(outputOp))); instance.Run(); var received = outputOp.GetAndReset()[0].ToArray(); Assert.That(received.Length, Is.EqualTo(1)); Assert.That(received[0], Is.InstanceOf <ExampleMarketDataBean>()); Assert.That( ((ExampleMarketDataBeanReadWrite)received[0]).Value, Is.EqualTo(55.5 * 1000.0)); }
private void TrySource(AdapterInputSource source) { var spec = new CSVInputAdapterSpec(source, "TypeC"); EPService = EPServiceProviderManager.GetProvider("testPlayFromInputStream", MakeConfig("TypeC")); EPService.Initialize(); InputAdapter feed = new CSVInputAdapter(EPService, spec); EPStatement stmt = EPService.EPAdministrator.CreateEPL("select * from TypeC.win:length(100)"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; feed.Start(); Assert.AreEqual(1, listener.GetNewDataList().Count); }
private void TrySource(AdapterInputSource source) { var spec = new CSVInputAdapterSpec(source, "TypeC"); _runtime = EPRuntimeProvider.GetRuntime("testPlayFromInputStream", MakeConfig("TypeC")); _runtime.Initialize(); InputAdapter feed = new CSVInputAdapter(_runtime, spec); var stmt = CompileUtil.CompileDeploy(_runtime, "select * from TypeC#length(100)").Statements[0]; var listener = new SupportUpdateListener(); stmt.Events += listener.Update; feed.Start(); Assert.AreEqual(1, listener.GetNewDataList().Count); }
public void TestAppThread() { _runtime = EPRuntimeProvider.GetRuntime("testExistingTypeNoOptions", MakeConfig("TypeA")); _runtime.Initialize(); var stmt = CompileUtil.CompileDeploy(_runtime, "select symbol, price, volume from TypeA#length(100)").Statements[0]; var listener = new SupportUpdateListener(); stmt.Events += listener.Update; var spec = new CSVInputAdapterSpec(new AdapterInputSource(_container, CSV_FILENAME_ONELINE_TRADE), "TypeA"); spec.EventsPerSec = 1000; InputAdapter inputAdapter = new CSVInputAdapter(_runtime, spec); inputAdapter.Start(); Assert.AreEqual(1, listener.GetNewDataList().Count); }
public void TestAppThread() { EPService = EPServiceProviderManager.GetProvider(_container, "testExistingTypeNoOptions", MakeConfig("TypeA")); EPService.Initialize(); EPStatement stmt = EPService.EPAdministrator.CreateEPL("select symbol, price, volume from TypeA#length(100)"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; var spec = new CSVInputAdapterSpec(new AdapterInputSource(CSV_FILENAME_ONELINE_TRADE), "TypeA"); spec.EventsPerSec = 1000; InputAdapter inputAdapter = new CSVInputAdapter(_container, EPService, spec); inputAdapter.Start(); Assert.AreEqual(1, listener.GetNewDataList().Count); }
private void RunNullEPService(CSVInputAdapter adapter) { try { adapter.Start(); Assert.Fail(); } catch (EPException ex) { // Expected } try { adapter.EPService = null; Assert.Fail(); } catch (ArgumentNullException) { // Expected } adapter.EPService = epService; adapter.Start(); Assert.AreEqual(3, listener.GetNewDataList().Count); }
private void TrySource(Supplier <AdapterInputSource> sourceSupplier) { var source = sourceSupplier.Invoke(); var spec = new CSVInputAdapterSpec(source, "TypeC"); _runtime = EPRuntimeProvider.GetRuntime("testPlayFromInputStream", MakeConfig("TypeC")); _runtime.Initialize(); InputAdapter feed = new CSVInputAdapter(_runtime, spec); var stmt = CompileDeploy(_runtime, "select * from TypeC#length(100)").Statements[0]; var listener = new SupportUpdateListener(); stmt.Events += listener.Update; feed.Start(); Assert.AreEqual(1, listener.GetNewDataList().Count); source = sourceSupplier.Invoke(); // test graph var graph = "create dataflow ReadCSV " + "FileSource -> mystream<TypeC> { hasTitleLine: true }" + "DefaultSupportCaptureOp(mystream) {}"; var deployment = CompileDeploy(_runtime, graph); var outputOp = new DefaultSupportCaptureOp(); var options = new EPDataFlowInstantiationOptions(); options.OperatorProvider = new DefaultSupportGraphOpProvider(outputOp); options.ParameterProvider = new DefaultSupportGraphParamProvider(Collections.SingletonDataMap("adapterInputSource", source)); var instance = _runtime.DataFlowService.Instantiate(deployment.DeploymentId, "ReadCSV", options); instance.Run(); var received = outputOp.GetAndReset()[0].ToArray(); Assert.AreEqual(1, received.Length); }
public void TestCoordinated() { IDictionary <string, object> priceProps = new Dictionary <string, object>(); priceProps.Put("timestamp", typeof(long?)); priceProps.Put("symbol", typeof(string)); priceProps.Put("price", typeof(double?)); IDictionary <string, object> tradeProps = new Dictionary <string, object>(); tradeProps.Put("timestamp", typeof(long?)); tradeProps.Put("symbol", typeof(string)); tradeProps.Put("notional", typeof(double?)); var config = new Configuration(_container); config.Common.AddEventType("TradeEvent", tradeProps); config.Common.AddEventType("PriceEvent", priceProps); _runtime = EPRuntimeProvider.GetRuntime("testCoordinated", config); _runtime.Initialize(); _runtime.EventService.ClockExternal(); _runtime.EventService.AdvanceTime(0); var sourcePrices = new AdapterInputSource(_container, CSV_FILENAME_TIMESTAMPED_PRICES); var inputPricesSpec = new CSVInputAdapterSpec(sourcePrices, "PriceEvent"); inputPricesSpec.TimestampColumn = "timestamp"; inputPricesSpec.PropertyTypes = priceProps; var inputPrices = new CSVInputAdapter(inputPricesSpec); var sourceTrades = new AdapterInputSource(_container, CSV_FILENAME_TIMESTAMPED_TRADES); var inputTradesSpec = new CSVInputAdapterSpec(sourceTrades, "TradeEvent"); inputTradesSpec.TimestampColumn = "timestamp"; inputTradesSpec.PropertyTypes = tradeProps; var inputTrades = new CSVInputAdapter(inputTradesSpec); var stmtPrices = CompileDeploy(_runtime, "select symbol, price from PriceEvent#length(100)").Statements[0]; var listenerPrice = new SupportUpdateListener(); stmtPrices.Events += listenerPrice.Update; var stmtTrade = CompileDeploy(_runtime, "select symbol, notional from TradeEvent#length(100)").Statements[0]; var listenerTrade = new SupportUpdateListener(); stmtTrade.Events += listenerTrade.Update; AdapterCoordinator coordinator = new AdapterCoordinatorImpl(_runtime, true); coordinator.Coordinate(inputPrices); coordinator.Coordinate(inputTrades); coordinator.Start(); _runtime.EventService.AdvanceTime(400); Assert.IsFalse(listenerTrade.IsInvoked()); Assert.IsFalse(listenerPrice.IsInvoked()); // invoke read of events at 500 (see CSV) _runtime.EventService.AdvanceTime(1000); Assert.AreEqual(1, listenerTrade.GetNewDataList().Count); Assert.AreEqual(1, listenerPrice.GetNewDataList().Count); listenerTrade.Reset(); listenerPrice.Reset(); // invoke read of price events at 1500 (see CSV) _runtime.EventService.AdvanceTime(2000); Assert.AreEqual(0, listenerTrade.GetNewDataList().Count); Assert.AreEqual(1, listenerPrice.GetNewDataList().Count); listenerTrade.Reset(); listenerPrice.Reset(); // invoke read of trade events at 2500 (see CSV) _runtime.EventService.AdvanceTime(3000); Assert.AreEqual(1, listenerTrade.GetNewDataList().Count); Assert.AreEqual(0, listenerPrice.GetNewDataList().Count); listenerTrade.Reset(); listenerPrice.Reset(); }
public void TestCoordinated() { IDictionary <String, Object> priceProps = new Dictionary <String, Object>(); priceProps.Put("timestamp", typeof(long?)); priceProps.Put("symbol", typeof(String)); priceProps.Put("price", typeof(double?)); IDictionary <String, Object> tradeProps = new Dictionary <String, Object>(); tradeProps.Put("timestamp", typeof(long?)); tradeProps.Put("symbol", typeof(String)); tradeProps.Put("notional", typeof(double?)); var config = new Configuration(); config.AddEventType("TradeEvent", tradeProps); config.AddEventType("PriceEvent", priceProps); EPService = EPServiceProviderManager.GetProvider("testCoordinated", config); EPService.Initialize(); EPService.EPRuntime.SendEvent(new TimerControlEvent(TimerControlEvent.ClockTypeEnum.CLOCK_EXTERNAL)); EPService.EPRuntime.SendEvent(new CurrentTimeEvent(0)); var sourcePrices = new AdapterInputSource(CSV_FILENAME_TIMESTAMPED_PRICES); var inputPricesSpec = new CSVInputAdapterSpec(sourcePrices, "PriceEvent"); inputPricesSpec.TimestampColumn = "timestamp"; inputPricesSpec.PropertyTypes = priceProps; var inputPrices = new CSVInputAdapter(inputPricesSpec); var sourceTrades = new AdapterInputSource(CSV_FILENAME_TIMESTAMPED_TRADES); var inputTradesSpec = new CSVInputAdapterSpec(sourceTrades, "TradeEvent"); inputTradesSpec.TimestampColumn = "timestamp"; inputTradesSpec.PropertyTypes = tradeProps; var inputTrades = new CSVInputAdapter(inputTradesSpec); EPStatement stmtPrices = EPService.EPAdministrator.CreateEPL("select symbol, price from PriceEvent.win:length(100)"); var listenerPrice = new SupportUpdateListener(); stmtPrices.Events += listenerPrice.Update; EPStatement stmtTrade = EPService.EPAdministrator.CreateEPL("select symbol, notional from TradeEvent.win:length(100)"); var listenerTrade = new SupportUpdateListener(); stmtTrade.Events += listenerTrade.Update; AdapterCoordinator coordinator = new AdapterCoordinatorImpl(EPService, true); coordinator.Coordinate(inputPrices); coordinator.Coordinate(inputTrades); coordinator.Start(); EPService.EPRuntime.SendEvent(new CurrentTimeEvent(400)); Assert.IsFalse(listenerTrade.IsInvoked()); Assert.IsFalse(listenerPrice.IsInvoked()); // invoke read of events at 500 (see CSV) EPService.EPRuntime.SendEvent(new CurrentTimeEvent(1000)); Assert.AreEqual(1, listenerTrade.GetNewDataList().Count); Assert.AreEqual(1, listenerPrice.GetNewDataList().Count); listenerTrade.Reset(); listenerPrice.Reset(); // invoke read of price events at 1500 (see CSV) EPService.EPRuntime.SendEvent(new CurrentTimeEvent(2000)); Assert.AreEqual(0, listenerTrade.GetNewDataList().Count); Assert.AreEqual(1, listenerPrice.GetNewDataList().Count); listenerTrade.Reset(); listenerPrice.Reset(); // invoke read of trade events at 2500 (see CSV) EPService.EPRuntime.SendEvent(new CurrentTimeEvent(3000)); Assert.AreEqual(1, listenerTrade.GetNewDataList().Count); Assert.AreEqual(0, listenerPrice.GetNewDataList().Count); listenerTrade.Reset(); listenerPrice.Reset(); }