private void TryListener(EPServiceProvider epService, int numThreads, int numRoutes)
        {
            EPStatement stmtTrigger = epService.EPAdministrator.CreateEPL(
                " select * from " + typeof(SupportBean).FullName);

            EPStatement stmtListen = epService.EPAdministrator.CreateEPL(
                " select * from " + typeof(SupportMarketDataBean).FullName);
            var listener = new SupportMTUpdateListener();

            stmtListen.Events += listener.Update;

            // Set of events routed by each listener
            var routed = CompatExtensions.AsSyncSet(new HashSet <SupportMarketDataBean>());

            var threadPool = Executors.NewFixedThreadPool(numThreads);
            var future     = new Future <bool> [numThreads];

            for (int i = 0; i < numThreads; i++)
            {
                var callable = new StmtListenerCreateStmtCallable(i, epService, stmtTrigger, numRoutes, routed);
                future[i] = threadPool.Submit(callable);
            }

            threadPool.Shutdown();
            threadPool.AwaitTermination(10, TimeUnit.SECONDS);

            for (int i = 0; i < numThreads; i++)
            {
                Assert.IsTrue(future[i].GetValueOrDefault());
            }

            // assert
            EventBean[] results = listener.GetNewDataListFlattened();
            Assert.IsTrue(results.Length >= numThreads * numRoutes);

            foreach (SupportMarketDataBean routedEvent in routed)
            {
                bool found = false;
                for (int i = 0; i < results.Length; i++)
                {
                    if (results[i].Underlying == routedEvent)
                    {
                        found = true;
                    }
                }
                Assert.IsTrue(found);
            }
        }
Example #2
0
        private void TryListener(int numThreads, int numRoutes)
        {
            EPStatement stmtTrigger = _engine.EPAdministrator.CreateEPL(
                " select * from " + typeof(SupportBean).FullName);

            EPStatement stmtListen = _engine.EPAdministrator.CreateEPL(
                " select * from " + typeof(SupportMarketDataBean).FullName);
            SupportMTUpdateListener listener = new SupportMTUpdateListener();

            stmtListen.Events += listener.Update;

            // Set of events routed by each listener
            ICollection <SupportMarketDataBean> routed = new HashSet <SupportMarketDataBean>().AsSyncCollection();

            var threadPool = Executors.NewFixedThreadPool(numThreads);
            var future     = new Future <bool> [numThreads];

            for (int i = 0; i < numThreads; i++)
            {
                var callable = new StmtListenerCreateStmtCallable(i, _engine, stmtTrigger, numRoutes, routed);
                future[i] = threadPool.Submit(callable);
            }

            threadPool.Shutdown();
            threadPool.AwaitTermination(TimeSpan.FromSeconds(10));

            for (int i = 0; i < numThreads; i++)
            {
                Assert.IsTrue(future[i].GetValueOrDefault());
            }

            // assert
            EventBean[] results = listener.GetNewDataListFlattened();
            Assert.IsTrue(results.Length >= numThreads * numRoutes);

            foreach (var found in routed.Select(routedEvent => results.Any(eventBean => eventBean.Underlying == routedEvent)))
            {
                Assert.IsTrue(found);
            }
        }