public void PerformTest(int numberOfThreads,
                                int numberOfTicksToSend,
                                int ratioPriceOutOfLimit,
                                int numberOfSecondsWaitForCompletion)
        {
            var totalNumTicks = numberOfTicksToSend + 2 * TestStockTickerGenerator.NUM_STOCK_NAMES;

            Log.Info(
                ".performTest Generating data, numberOfTicksToSend=" +
                numberOfTicksToSend +
                "  ratioPriceOutOfLimit=" +
                ratioPriceOutOfLimit);

            var generator = new StockTickerEventGenerator();
            var stream    = generator.MakeEventStream(
                numberOfTicksToSend,
                ratioPriceOutOfLimit,
                TestStockTickerGenerator.NUM_STOCK_NAMES,
                PRICE_LIMIT_PCT_LOWER_LIMIT,
                PRICE_LIMIT_PCT_UPPER_LIMIT,
                PRICE_LOWER_LIMIT,
                PRICE_UPPER_LIMIT,
                true);

            var eventService = _runtime.EventService;

            Log.Info(".performTest Send limit and initial tick events - singlethreaded");
            for (var i = 0; i < TestStockTickerGenerator.NUM_STOCK_NAMES * 2; i++)
            {
                var @event = stream.First();
                stream.RemoveAt(0);
                eventService.SendEventBean(@event, @event.GetType().Name);
            }

            Log.Info(".performTest Loading thread pool work queue, numberOfRunnables=" + stream.Count);

            var executorService = new DedicatedExecutorService(string.Empty, numberOfThreads, new LinkedBlockingQueue <Runnable>());

            foreach (var @event in stream)
            {
                var innerEvent = @event;
                executorService.Submit(() => eventService.SendEventBean(
                                           innerEvent, innerEvent.GetType().Name));
            }

            Log.Info(".performTest Listening for completion");
            EPRuntimeUtil.AwaitCompletion(_runtime, totalNumTicks, numberOfSecondsWaitForCompletion, 1, 10);

            executorService.Shutdown();

            // Check results : make sure the given ratio of out-of-limit stock prices was reported
            var expectedNumEmitted = numberOfTicksToSend / ratioPriceOutOfLimit + 1;

            Assert.IsTrue(_listener.Count == expectedNumEmitted);

            Log.Info(".performTest Done test");
        }
        public void TestMakeStream()
        {
            var generator = new StockTickerEventGenerator();

            const int NUM_EVENTS = 1000;

            IList <object> stream = generator.MakeEventStream(NUM_EVENTS, 1000, NUM_STOCK_NAMES, 25, 30, 46, 54, true);

            Assert.IsTrue(stream.Count == (NUM_STOCK_NAMES * 2 + NUM_EVENTS));
        }
예제 #3
0
        public void Run()
        {
            var container = ContainerExtensions.CreateDefaultContainer(false)
                            .InitializeDefaultServices()
                            .InitializeDatabaseDrivers();

            var configuration = new Configuration(container);

            configuration.Common.AddEventType("PriceLimit", typeof(PriceLimit));
            configuration.Common.AddEventType("StockTick", typeof(StockTick));

            Log.Info("Setting up EPL");

            var runtime = EPRuntimeProvider.GetRuntime(_engineURI, configuration);

            runtime.Initialize();

            var eventService = runtime.EventService;

            new StockTickerMonitor(runtime, new StockTickerResultListener());

            Log.Info("Generating test events: 1 million ticks, ratio 2 hits, 100 stocks");
            var generator = new StockTickerEventGenerator();
            var stream    = generator.MakeEventStream(1000000, 500000, 100, 25, 30, 48, 52, false);

            Log.Info("Generating " + stream.Count + " events");

            Log.Info("Sending " + stream.Count + " limit and tick events");
            foreach (var @event in stream)
            {
                eventService.SendEventBean(@event, @event.GetType().Name);

                if (_continuousSimulation)
                {
                    try {
                        Thread.Sleep(200);
                    }
                    catch (ThreadInterruptedException e) {
                        Log.Debug("Interrupted", e);
                        break;
                    }
                }
            }

            Log.Info("Done.");
        }
예제 #4
0
        public void TestFlow()
        {
            var generator = new StockTickerEventGenerator();

            var limitBeans = generator.MakeLimits(
                "nunit",
                NUM_STOCK_NAMES,
                PRICE_LIMIT_PCT_LOWER_LIMIT,
                PRICE_LIMIT_PCT_UPPER_LIMIT);

            Assert.IsTrue(limitBeans.Length == NUM_STOCK_NAMES);
            Assert.IsTrue(limitBeans[0].UserId.Equals("nunit"));
            for (var i = 0; i < limitBeans.Length; i++)
            {
                Assert.IsTrue(limitBeans[i].LimitPct >= PRICE_LIMIT_PCT_LOWER_LIMIT);
                Assert.IsTrue(limitBeans[i].LimitPct <= PRICE_LIMIT_PCT_UPPER_LIMIT);
            }

            var initialPrices = generator.MakeInitialPriceStockTicks(
                limitBeans,
                PRICE_LOWER_LIMIT,
                PRICE_LOWER_LIMIT);

            Assert.IsTrue(initialPrices.Length == NUM_STOCK_NAMES);
            for (var i = 0; i < initialPrices.Length; i++)
            {
                Assert.IsTrue(initialPrices[i].Price >= PRICE_LOWER_LIMIT);
                Assert.IsTrue(initialPrices[i].Price <= PRICE_UPPER_LIMIT);
            }

            for (var i = 0; i < 100000; i++)
            {
                var tick = generator.MakeStockTick(limitBeans[0], initialPrices[0]);

                var initialPrice = initialPrices[0].Price;
                var range        = initialPrice * limitBeans[0].LimitPct / 100;

                Assert.IsTrue(tick.Price > initialPrice - range - 1);
                Assert.IsTrue(tick.Price < initialPrice + range + 1);
            }
        }
예제 #5
0
        public void Run()
        {
            var configuration = new Configuration();

            configuration.AddEventType("PriceLimit", typeof(PriceLimit).FullName);
            configuration.AddEventType("StockTick", typeof(StockTick).FullName);

            Log.Info("Setting up EPL");

            var epService = EPServiceProviderManager.GetProvider(_engineURI, configuration);

            epService.Initialize();

            new StockTickerMonitor(epService, new StockTickerResultListener());

            Log.Info("Generating test events: 1 million ticks, ratio 2 hits, 100 stocks");
            var generator = new StockTickerEventGenerator();
            var stream    = generator.MakeEventStream(1000000, 500000, 100, 25, 30, 48, 52, false);

            Log.Info("Generating " + stream.Count + " events");

            Log.Info("Sending " + stream.Count + " limit and tick events");
            foreach (var @event in stream)
            {
                epService.EPRuntime.SendEvent(@event);

                if (_continuousSimulation)
                {
                    try {
                        Thread.Sleep(200);
                    }
                    catch (ThreadInterruptedException e) {
                        Log.Debug("Interrupted", e);
                        break;
                    }
                }
            }

            Log.Info("Done.");
        }