public void SetUp()
        {
            var container = ContainerExtensions.CreateDefaultContainer()
                            .InitializeDefaultServices()
                            .InitializeDatabaseDrivers();

            var configuration = new Configuration(container);

            configuration.EngineDefaults.Threading.IsInternalTimerEnabled = false;
            configuration.AddEventType("MarketDataEvent", typeof(MarketDataEvent).FullName);
            configuration.EngineDefaults.EventMeta.ClassPropertyResolutionStyle = PropertyResolutionStyle.CASE_INSENSITIVE;

            _epService = EPServiceProviderManager.GetProvider(container, "TestTicksPerSecondStatement", configuration);
            _epService.Initialize();
            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(0));

            TicksPerSecondStatement.Create(_epService.EPAdministrator);
            var stmt = TicksFalloffStatement.Create(_epService.EPAdministrator);

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

            // Use external clocking for the test
            _epService.EPRuntime.SendEvent(new TimerControlEvent(TimerControlEvent.ClockTypeEnum.CLOCK_EXTERNAL));
        }
Esempio n. 2
0
        public void SetUp()
        {
            var container = ContainerExtensions.CreateDefaultContainer()
                            .InitializeDefaultServices()
                            .InitializeDatabaseDrivers();

            var configuration = new Configuration(container);

            configuration.Runtime.Threading.IsInternalTimerEnabled = false;
            configuration.Common.AddEventType("MarketDataEvent", typeof(MarketDataEvent).FullName);
            configuration.Common.EventMeta.ClassPropertyResolutionStyle = PropertyResolutionStyle.CASE_INSENSITIVE;

            _runtime = EPRuntimeProvider.GetRuntime("TestTicksPerSecondStatement", configuration);
            _runtime.Initialize();
            _runtime.EventService.AdvanceTime(0);

            TicksPerSecondStatement.Create(_runtime);
            var stmt = TicksFalloffStatement.Create(_runtime);

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

            // Use external clocking for the test
            _runtime.EventService.ClockExternal();
        }
Esempio n. 3
0
        public void Run()
        {
            if (_isWaitKeypress)
            {
                Console.WriteLine("...press enter to start simulation...");
                Console.ReadKey();
            }

            var container = ContainerExtensions.CreateDefaultContainer()
                            .InitializeDefaultServices()
                            .InitializeDatabaseDrivers();

            // Configure engine with event names to make the statements more readable.
            // This could also be done in a configuration file.
            var configuration = new Configuration(container);

            configuration.AddEventType("MarketDataEvent", typeof(MarketDataEvent).FullName);

            // Get engine instance
            var epService = EPServiceProviderManager.GetProvider(container, _engineURI, configuration);

            // Set up statements
            var tickPerSecStmt = TicksPerSecondStatement.Create(epService.EPAdministrator);

            tickPerSecStmt.Events += LogRate;

            var falloffStmt = TicksFalloffStatement.Create(epService.EPAdministrator);

            falloffStmt.Events += MonitorRate;

            // Send events
            var threadPool = new DedicatedExecutorService(string.Empty, _numberOfThreads);
            var runnables  = new MarketDataSendRunnable[_numberOfThreads];

            for (var i = 0; i < _numberOfThreads; i++)
            {
                runnables[i] = new MarketDataSendRunnable(epService);
                threadPool.Submit(runnables[i].Run);
            }

            var seconds = 0;
            var random  = new Random();

            while (seconds < _numSeconds)
            {
                seconds++;
                Thread.Sleep(1000);

                FeedEnum?feedToDropOff;
                if (random.NextDouble() * 100 < _dropProbability)
                {
                    feedToDropOff = FeedEnum.FEED_A;
                    if (random.Next(0, 2) == 1)
                    {
                        feedToDropOff = FeedEnum.FEED_B;
                    }
                    Log.Info("Setting drop-off for feed {0}", feedToDropOff);
                }
                else
                {
                    feedToDropOff = null;
                }

                foreach (var t in runnables)
                {
                    t.SetRateDropOffFeed(feedToDropOff);
                }
            }

            Log.Info("Shutting down threadpool");
            for (var i = 0; i < runnables.Length; i++)
            {
                runnables[i].SetShutdown();
            }
            threadPool.Shutdown();
            threadPool.AwaitTermination(new TimeSpan(0, 0, 0, 10));
        }