コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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"));
        }
コード例 #4
0
        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"));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        public void TestNotUsingEngineThread()
        {
            _coordinator = new AdapterCoordinatorImpl(_epService, false);
            _coordinator.Coordinate(new CSVInputAdapter(_container, _epService, _noTimestampsNotLooping));
            _coordinator.Coordinate(new CSVInputAdapter(_container, _epService, _timestampsNotLooping));

            long startTime = Environment.TickCount;

            _coordinator.Start();
            long endTime = Environment.TickCount;

            // The last event should be sent after 500 ms
            Assert.IsTrue(endTime - startTime > 500);

            Assert.AreEqual(6, _listener.GetNewDataList().Count);
            AssertEvent(0, 1, 1.1, "noTimestampOne.one");
            AssertEvent(1, 1, 1.1, "timestampOne.one");
            AssertEvent(2, 2, 2.2, "noTimestampOne.two");
            AssertEvent(3, 3, 3.3, "noTimestampOne.three");
            AssertEvent(4, 3, 3.3, "timestampOne.three");
            AssertEvent(5, 5, 5.5, "timestampOne.five");
        }
コード例 #9
0
        public void TestExistingTypeNoOptions()
        {
            EPService = EPServiceProviderManager.GetProvider("testExistingTypeNoOptions", MakeConfig("TypeA", _useBean));
            EPService.Initialize();

            EPStatement stmt     = EPService.EPAdministrator.CreateEPL("select symbol, price, volume from TypeA.win:length(100)");
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            (new CSVInputAdapter(EPService, new AdapterInputSource(CSV_FILENAME_ONELINE_TRADE), "TypeA")).Start();

            Assert.AreEqual(1, listener.GetNewDataList().Count);
        }
コード例 #10
0
        public void TestExistingTypeNoOptions()
        {
            _runtime = EPRuntimeProvider.GetRuntime("testExistingTypeNoOptions", MakeConfig("TypeA", _useBean));
            _runtime.Initialize();

            var stmt     = CompileDeploy(_runtime, "select symbol, price, volume from TypeA#length(100)").Statements[0];
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            (new CSVInputAdapter(_runtime, new AdapterInputSource(_container, CSV_FILENAME_ONELINE_TRADE), "TypeA")).Start();

            Assert.AreEqual(1, listener.GetNewDataList().Count);
        }
コード例 #11
0
        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);
        }
コード例 #12
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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
ファイル: TestCSVAdapter.cs プロジェクト: valmac/nesper
        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);
        }
コード例 #16
0
        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();
        }
コード例 #17
0
        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();
        }