Beispiel #1
0
        public void TestRuntimePropertyTypes()
        {
            CompileDeploy(_runtime, "@public @buseventtype create schema propertyTypeEvent(MyInt int, MyDouble double, MyString string)");

            var adapterSpec = new CSVInputAdapterSpec(
                new AdapterInputSource(_container, "regression/noTimestampOne.csv"),
                "propertyTypeEvent");
            adapterSpec.EventsPerSec = 10;
            adapterSpec.PropertyOrder = new[] {"MyInt", "MyDouble", "MyString"};
            adapterSpec.PropertyTypes = _propertyTypes;
            adapterSpec.IsUsingEngineThread = true;
            _adapter = new CSVInputAdapter(_runtime, adapterSpec);

            const string statementText = "select * from propertyTypeEvent#length(5)";
            var statement = CompileDeploy(_runtime, statementText).Statements[0];
            statement.Events += _listener.Update;

            _adapter.Start();

            SendTimeEvent(100);
            AssertEvent(1, 1.1, "noTimestampOne.one");

            SendTimeEvent(100);
            AssertEvent(2, 2.2, "noTimestampOne.two");

            SendTimeEvent(100);
            AssertEvent(3, 3.3, "noTimestampOne.three");
        }
Beispiel #2
0
        public void TestRuntimePropertyTypes()
        {
            var adapterSpec = new CSVInputAdapterSpec(new AdapterInputSource("regression/noTimestampOne.csv"),
                                                      "propertyTypeEvent");

            adapterSpec.EventsPerSec        = 10;
            adapterSpec.PropertyOrder       = new[] { "myInt", "myDouble", "myString" };
            adapterSpec.PropertyTypes       = propertyTypes;
            adapterSpec.IsUsingEngineThread = true;
            adapter = new CSVInputAdapter(epService, adapterSpec);

            const string statementText = "select * from propertyTypeEvent#length(5)";
            EPStatement  statement     = epService.EPAdministrator.CreateEPL(statementText);

            statement.Events += listener.Update;

            adapter.Start();

            SendTimeEvent(100);
            AssertEvent(1, 1.1, "noTimestampOne.one");

            SendTimeEvent(100);
            AssertEvent(2, 2.2, "noTimestampOne.two");

            SendTimeEvent(100);
            AssertEvent(3, 3.3, "noTimestampOne.three");
        }
        public void SetUp()
        {
            _container = SupportContainer.Reset();

            IDictionary <String, Object> propertyTypes = new LinkedHashMap <String, Object>();

            propertyTypes.Put("myInt", typeof(int));
            propertyTypes.Put("myDouble", typeof(double?));
            propertyTypes.Put("myString", typeof(String));

            _eventTypeName = "mapEvent";
            var configuration = new Configuration(_container);

            configuration.Runtime.Threading.IsInternalTimerEnabled = false;
            configuration.Common.AddEventType(_eventTypeName, propertyTypes);

            _runtime = EPRuntimeProvider.GetRuntime("Adapter", configuration);
            _runtime.Initialize();

            var statementText = "select * from mapEvent#length(5)";
            var statement     = CompileUtil.CompileDeploy(_runtime, statementText).Statements[0];

            _listener         = new SupportUpdateListener();
            statement.Events += _listener.Update;

            // Set the clock to 0
            _currentTime = 0;
            SendTimeEvent(0);

            _coordinator = new AdapterCoordinatorImpl(_runtime, true);

            _propertyOrderNoTimestamp = new[] { "myInt", "myDouble", "myString" };
            var propertyOrderTimestamp = new[] { "timestamp", "myInt", "myDouble", "myString" };

            // A CSVPlayer for a file with timestamps, not looping
            _timestampsNotLooping = new CSVInputAdapterSpec(new AdapterInputSource(_container, "regression/timestampOne.csv"), _eventTypeName);
            _timestampsNotLooping.IsUsingEngineThread = true;
            _timestampsNotLooping.PropertyOrder       = propertyOrderTimestamp;
            _timestampsNotLooping.TimestampColumn     = "timestamp";

            // A CSVAdapter for a file with timestamps, looping
            _timestampsLooping                     = new CSVInputAdapterSpec(new AdapterInputSource(_container, "regression/timestampTwo.csv"), _eventTypeName);
            _timestampsLooping.IsLooping           = true;
            _timestampsLooping.IsUsingEngineThread = true;
            _timestampsLooping.PropertyOrder       = propertyOrderTimestamp;
            _timestampsLooping.TimestampColumn     = "timestamp";

            // A CSVAdapter that sends 10 events per sec, not looping
            _noTimestampsNotLooping = new CSVInputAdapterSpec(new AdapterInputSource(_container, "regression/noTimestampOne.csv"), _eventTypeName);
            _noTimestampsNotLooping.EventsPerSec        = 10;
            _noTimestampsNotLooping.PropertyOrder       = _propertyOrderNoTimestamp;
            _noTimestampsNotLooping.IsUsingEngineThread = true;

            // A CSVAdapter that sends 5 events per sec, looping
            _noTimestampsLooping = new CSVInputAdapterSpec(new AdapterInputSource(_container, "regression/noTimestampTwo.csv"), _eventTypeName);
            _noTimestampsLooping.EventsPerSec        = 5;
            _noTimestampsLooping.IsLooping           = true;
            _noTimestampsLooping.PropertyOrder       = _propertyOrderNoTimestamp;
            _noTimestampsLooping.IsUsingEngineThread = true;
        }
        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);
        }
Beispiel #5
0
        public void SetUp()
        {
            IDictionary <String, Object> propertyTypes = new LinkedHashMap <String, Object>();

            propertyTypes.Put("myInt", typeof(int));
            propertyTypes.Put("myDouble", typeof(double?));
            propertyTypes.Put("myString", typeof(String));

            eventTypeName = "mapEvent";
            Configuration configuration = new Configuration();

            configuration.AddEventType(eventTypeName, propertyTypes);

            epService = EPServiceProviderManager.GetProvider("Adapter", configuration);
            epService.Initialize();
            EPAdministrator administrator = epService.EPAdministrator;
            String          statementText = "select * from mapEvent.win:length(5)";
            EPStatement     statement     = administrator.CreateEPL(statementText);

            listener          = new SupportUpdateListener();
            statement.Events += listener.Update;

            // Turn off external clocking
            epService.EPRuntime.SendEvent(new TimerControlEvent(TimerControlEvent.ClockTypeEnum.CLOCK_EXTERNAL));

            // Set the clock to 0
            currentTime = 0;
            SendTimeEvent(0);

            coordinator = new AdapterCoordinatorImpl(epService, true);

            propertyOrderNoTimestamp = new String[] { "myInt", "myDouble", "myString" };
            String[] propertyOrderTimestamp = new String[] { "timestamp", "myInt", "myDouble", "myString" };

            // A CSVPlayer for a file with timestamps, not looping
            timestampsNotLooping = new CSVInputAdapterSpec(new AdapterInputSource("/regression/timestampOne.csv"), eventTypeName);
            timestampsNotLooping.IsUsingEngineThread = true;
            timestampsNotLooping.PropertyOrder       = propertyOrderTimestamp;
            timestampsNotLooping.TimestampColumn     = "timestamp";

            // A CSVAdapter for a file with timestamps, looping
            timestampsLooping                     = new CSVInputAdapterSpec(new AdapterInputSource("/regression/timestampTwo.csv"), eventTypeName);
            timestampsLooping.IsLooping           = true;
            timestampsLooping.IsUsingEngineThread = true;
            timestampsLooping.PropertyOrder       = propertyOrderTimestamp;
            timestampsLooping.TimestampColumn     = "timestamp";

            // A CSVAdapter that sends 10 events per sec, not looping
            noTimestampsNotLooping = new CSVInputAdapterSpec(new AdapterInputSource("/regression/noTimestampOne.csv"), eventTypeName);
            noTimestampsNotLooping.EventsPerSec        = 10;
            noTimestampsNotLooping.PropertyOrder       = propertyOrderNoTimestamp;
            noTimestampsNotLooping.IsUsingEngineThread = true;

            // A CSVAdapter that sends 5 events per sec, looping
            noTimestampsLooping = new CSVInputAdapterSpec(new AdapterInputSource("/regression/noTimestampTwo.csv"), eventTypeName);
            noTimestampsLooping.EventsPerSec        = 5;
            noTimestampsLooping.IsLooping           = true;
            noTimestampsLooping.PropertyOrder       = propertyOrderNoTimestamp;
            noTimestampsLooping.IsUsingEngineThread = true;
        }
Beispiel #6
0
        public void TestConflictingPropertyOrder()
        {
            CompileDeploy(_runtime, "@public @buseventtype create schema intsTitleRowEvent(intOne string, intTwo string)");

            var adapterSpec = new CSVInputAdapterSpec(
                new AdapterInputSource(_container, "regression/intsTitleRow.csv"),
                "intsTitleRowEvent");
            adapterSpec.EventsPerSec = 10;
            adapterSpec.PropertyOrder = new[] {"intTwo", "intOne"};
            adapterSpec.IsUsingEngineThread = true;
            _adapter = new CSVInputAdapter(_runtime, adapterSpec);

            const string statementText = "select * from intsTitleRowEvent#length(5)";
            var statement = CompileDeploy(_runtime, statementText).Statements[0];
            statement.Events += _listener.Update;

            _adapter.Start();

            SendTimeEvent(100);

            Assert.IsTrue(_listener.GetAndClearIsInvoked());
            Assert.AreEqual(1, _listener.GetLastNewData().Length);
            Assert.AreEqual("1", _listener.GetLastNewData()[0].Get("intTwo"));
            Assert.AreEqual("0", _listener.GetLastNewData()[0].Get("intOne"));
        }
        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(_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);
        }
Beispiel #9
0
        public void TestNoPropertyTypes()
        {
            var adapterSpec = new CSVInputAdapterSpec(new AdapterInputSource("regression/noTimestampOne.csv"),
                                                      "allStringEvent");

            adapterSpec.EventsPerSec        = 10;
            adapterSpec.PropertyOrder       = new[] { "myInt", "myDouble", "myString" };
            adapterSpec.IsUsingEngineThread = true;
            _adapter = new CSVInputAdapter(_container, _epService, adapterSpec);

            const string statementText = "select * from allStringEvent#length(5)";
            EPStatement  statement     = _epService.EPAdministrator.CreateEPL(statementText);

            statement.Events += _listener.Update;

            _adapter.Start();

            SendTimeEvent(100);
            AssertEvent("1", "1.1", "noTimestampOne.one");

            SendTimeEvent(100);
            AssertEvent("2", "2.2", "noTimestampOne.two");

            SendTimeEvent(100);
            AssertEvent("3", "3.3", "noTimestampOne.three");
        }
        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);
        }
Beispiel #11
0
        public void TestNoPropertyTypes()
        {
            CompileDeploy(_runtime, "@public @buseventtype create schema allStringEvent(myInt string, myDouble string, myString string)");

            var adapterSpec = new CSVInputAdapterSpec(
                new AdapterInputSource(_container, "regression/noTimestampOne.csv"),
                "allStringEvent");

            adapterSpec.EventsPerSec        = 10;
            adapterSpec.PropertyOrder       = new[] { "myInt", "myDouble", "myString" };
            adapterSpec.IsUsingEngineThread = true;
            _adapter = new CSVInputAdapter(_runtime, adapterSpec);

            const string statementText = "select * from allStringEvent#length(5)";
            var          statement     = CompileDeploy(_runtime, statementText).Statements[0];

            statement.Events += _listener.Update;

            _adapter.Start();

            SendTimeEvent(100);
            AssertEvent("1", "1.1", "noTimestampOne.one");

            SendTimeEvent(100);
            AssertEvent("2", "2.2", "noTimestampOne.two");

            SendTimeEvent(100);
            AssertEvent("3", "3.3", "noTimestampOne.three");
        }
        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);
        }
Beispiel #13
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);
        }
Beispiel #14
0
        public void TestRuntimePropertyTypesInvalid()
        {
            var propertyTypesInvalid = new Dictionary <String, Object>(_propertyTypes);

            propertyTypesInvalid.Put("anotherProperty", typeof(String));
            try {
                var adapterSpec = new CSVInputAdapterSpec(
                    new AdapterInputSource(_container, "regression/noTimestampOne.csv"),
                    "mapEvent");
                adapterSpec.PropertyTypes = propertyTypesInvalid;
                (new CSVInputAdapter(_runtime, adapterSpec)).Start();
                Assert.Fail();
            }
            catch (EPException) {
                // Expected
            }

            propertyTypesInvalid = new Dictionary <String, Object>(_propertyTypes);
            propertyTypesInvalid.Put("myInt", typeof(String));
            try {
                var adapterSpec = new CSVInputAdapterSpec(
                    new AdapterInputSource(_container, "regression/noTimestampOne.csv"),
                    "mapEvent");
                adapterSpec.PropertyTypes = propertyTypesInvalid;
                (new CSVInputAdapter(_runtime, adapterSpec)).Start();
                Assert.Fail();
            }
            catch (EPException) {
                // Expected
            }

            propertyTypesInvalid = new Dictionary <String, Object>(_propertyTypes);
            propertyTypesInvalid.Remove("myInt");
            propertyTypesInvalid.Put("anotherInt", typeof(int?));
            try {
                var adapterSpec = new CSVInputAdapterSpec(
                    new AdapterInputSource(_container, "regression/noTimestampOne.csv"),
                    "mapEvent");
                adapterSpec.PropertyTypes = propertyTypesInvalid;
                (new CSVInputAdapter(_runtime, adapterSpec)).Start();
                Assert.Fail();
            }
            catch (EPException) {
                // Expected
            }
        }
Beispiel #15
0
        public void TestInputStream()
        {
            var stream = _container.ResourceManager().GetResourceAsStream("regression/noTimestampOne.csv");
            var adapterSpec = new CSVInputAdapterSpec(new AdapterInputSource(_container, stream), _eventTypeName);
            adapterSpec.PropertyOrder = _propertyOrderNoTimestamps;

            new CSVInputAdapter(_runtime, adapterSpec);

            adapterSpec.IsLooping = true;
            try {
                new CSVInputAdapter(_runtime, adapterSpec);
                Assert.Fail();
            }
            catch (EPException) {
                // Expected
            }
        }
Beispiel #16
0
        private void StartAdapter(String filename, int eventsPerSec, bool isLooping, bool usingEngineThread,
                                  String timestampColumn, String[] propertyOrder)
        {
            var adapterSpec = new CSVInputAdapterSpec(new AdapterInputSource(filename), eventTypeName);

            if (eventsPerSec != -1)
            {
                adapterSpec.EventsPerSec = eventsPerSec;
            }
            adapterSpec.IsLooping           = isLooping;
            adapterSpec.PropertyOrder       = propertyOrder;
            adapterSpec.IsUsingEngineThread = usingEngineThread;
            adapterSpec.TimestampColumn     = timestampColumn;

            adapter = new CSVInputAdapter(epService, adapterSpec);
            adapter.Start();
        }
Beispiel #17
0
        public void TestInputStream()
        {
            Stream stream      = ResourceManager.GetResourceAsStream("regression/noTimestampOne.csv");
            var    adapterSpec = new CSVInputAdapterSpec(new AdapterInputSource(stream), eventTypeName);

            adapterSpec.PropertyOrder = propertyOrderNoTimestamps;

            new CSVInputAdapter(epService, adapterSpec);

            adapterSpec.IsLooping = true;
            try {
                new CSVInputAdapter(epService, adapterSpec);
                Assert.Fail();
            }
            catch (EPException) {
                // Expected
            }
        }
Beispiel #18
0
        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 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);
        }
Beispiel #21
0
        public void TestConflictingPropertyOrder()
        {
            var adapterSpec = new CSVInputAdapterSpec(new AdapterInputSource("regression/intsTitleRow.csv"),
                                                      "intsTitleRowEvent");

            adapterSpec.EventsPerSec        = 10;
            adapterSpec.PropertyOrder       = new[] { "intTwo", "intOne" };
            adapterSpec.IsUsingEngineThread = true;
            adapter = new CSVInputAdapter(epService, adapterSpec);

            const string statementText = "select * from intsTitleRowEvent#length(5)";
            EPStatement  statement     = epService.EPAdministrator.CreateEPL(statementText);

            statement.Events += listener.Update;

            adapter.Start();

            SendTimeEvent(100);

            Assert.IsTrue(listener.GetAndClearIsInvoked());
            Assert.AreEqual(1, listener.GetLastNewData().Length);
            Assert.AreEqual("1", listener.GetLastNewData()[0].Get("intTwo"));
            Assert.AreEqual("0", listener.GetLastNewData()[0].Get("intOne"));
        }
        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();
        }