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();
        }
Example #2
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();
        }