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 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;
        }
Exemple #3
0
        public void TestEngineThread1PerSec()
        {
            _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_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);
        }
Exemple #4
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();

            InputAdapter feed = new CSVInputAdapter(_runtime, spec);

            var stmt     = CompileUtil.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);
        }
Exemple #5
0
        public void TestNestedMapProperties()
        {
            var configuration = new Configuration(_container);
            var point         = new Dictionary <string, object>();

            point.Put("X", typeof(int));
            point.Put("Y", typeof(int));

            var figure = new Dictionary <string, object>();

            figure.Put("Name", typeof(string));
            figure.Put("Point", point);

            configuration.Common.AddEventType("Figure", figure);
            var runtime = EPRuntimeProvider.GetRuntime("testNestedMapProperties", configuration);
            var ul      = new SupportUpdateListener();
            var stmt    = CompileUtil.CompileDeploy(runtime, "select * from Figure").Statements[0];

            stmt.Events += ul.Update;

            var source  = new AdapterInputSource(_container, "regression/nestedProperties.csv");
            var spec    = new CSVInputAdapterSpec(source, "Figure");
            var adapter = new CSVInputAdapter(runtime, spec);

            adapter.Start();

            Assert.IsTrue(ul.IsInvoked());
            var e = ul.AssertOneGetNewAndReset();

            Assert.AreEqual(1, e.Get("Point.X"));
        }
Exemple #6
0
        public void TestNestedProperties()
        {
            var container = ContainerExtensions.CreateDefaultContainer();

            var configuration = new Configuration(container);

            configuration.Common.AddEventType(typeof(Figure));

            var runtime = EPRuntimeProvider.GetRuntime("testNestedProperties", configuration);
            var ul      = new SupportUpdateListener();

            var stmt = CompileUtil.CompileDeploy(runtime, "select * from Figure").Statements[0];

            stmt.Events += ul.Update;

            var source  = new AdapterInputSource(_container, "regression/nestedProperties.csv");
            var spec    = new CSVInputAdapterSpec(source, "Figure");
            var adapter = new CSVInputAdapter(runtime, spec);

            adapter.Start();

            Assert.IsTrue(ul.IsInvoked());
            var e = ul.AssertOneGetNewAndReset();
            var f = (Figure)e.Underlying;

            Assert.AreEqual(1, f.Point.X);
        }
Exemple #7
0
 public static void Compile(IFrameworkDetectionHelper frameworkDetectionHelper, FileSystemPath source, FileSystemPath dll,
                            string[] references, Version version)
 {
     // The 9.1 tests are using the test nuget packages to allow testing any framework,
     // but there's a bug in the JetBrains.Tests.Platform.NetFramework.Binaries.4.0 package
     // that means csc.exe doesn't work. Use the system 4.x compiler.
     // https://youtrack.jetbrains.com/issue/RSRP-437176
     CompileUtil.CompileCs(new SystemFrameworkLocationHelper(), source, dll, references, false,
                           false, version);
 }
Exemple #8
0
        public void TestExistingTypeNoOptions()
        {
            _runtime = EPRuntimeProvider.GetRuntime("testExistingTypeNoOptions", MakeConfig("TypeA", _useBean));
            _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;

            (new CSVInputAdapter(_runtime, new AdapterInputSource(_container, CSV_FILENAME_ONELINE_TRADE), "TypeA")).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, 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 string GetAssembly(string filename, string[] references)
        {
            var source   = GetTestDataFilePath2(filename);
            var assembly = source.ChangeExtension("dll");

            CompileUtil.CompileCs(
                PlatformManager,
                source,
                assembly,
                references,
                false,
                false,
                new Version(_framework.Version.Major, _framework.Version.Minor));

            return(assembly.Name);
        }
Exemple #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);
        }
Exemple #12
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    = CompileUtil.CompileDeploy(_runtime, "select symbol, price from PriceEvent#length(100)").Statements[0];
            var listenerPrice = new SupportUpdateListener();

            stmtPrices.Events += listenerPrice.Update;
            var stmtTrade     = CompileUtil.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();
        }