Beispiel #1
0
        public void SetUp()
        {
            Configuration configuration = new Configuration();

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

            _epService = EPServiceProviderManager.GetProvider("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));
        }
Beispiel #2
0
        public void Run()
        {
            if (_isWaitKeypress)
            {
                Console.WriteLine("...press enter to start simulation...");
                Console.ReadKey();
            }

            // Configure engine with event names to make the statements more readable.
            // This could also be done in a configuration file.
            Configuration configuration = new Configuration();
            configuration.AddEventType("MarketDataEvent", typeof(MarketDataEvent).FullName);

            // Get engine instance
            EPServiceProvider epService = EPServiceProviderManager.GetProvider(_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);
            MarketDataSendRunnable[] runnables = new MarketDataSendRunnable[_numberOfThreads];
            for (int i = 0; i < _numberOfThreads; i++)
            {
                runnables[i] = new MarketDataSendRunnable(epService);
                threadPool.Submit(runnables[i].Run);
            }

            int seconds = 0;
            Random 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 (MarketDataSendRunnable t in runnables) 
                {
                    t.SetRateDropOffFeed(feedToDropOff);
                }
            }

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