private void TrySendCountFollowedBy(int numThreads, int numEvents, ConfigurationEngineDefaults.Threading.Locking locking)
        {
            var config = SupportConfigFactory.GetConfiguration();

            config.EngineDefaults.ThreadingConfig.InsertIntoDispatchLocking = locking;
            config.EngineDefaults.ThreadingConfig.InsertIntoDispatchTimeout = 5000; // 5 second timeout
            // This should fail all test in this class
            // config.EngineDefaults.ThreadingConfig.InsertIntoDispatchPreserveOrder = false;

            var engine = EPServiceProviderManager.GetDefaultProvider(config);

            engine.Initialize();

            // setup statements
            var stmtInsert = engine.EPAdministrator.CreateEPL("insert into MyStream select count(*) as cnt from " + typeof(SupportBean).FullName);

            stmtInsert.Events += ((sender, e) => Log.Debug(".Update cnt=" + e.NewEvents[0].Get("cnt")));

            var listeners = new SupportUpdateListener[numEvents];

            for (var i = 0; i < numEvents; i++)
            {
                var text = "select * from pattern [MyStream(cnt=" + (i + 1) + ") -> MyStream(cnt=" + (i + 2) + ")]";
                var stmt = engine.EPAdministrator.CreateEPL(text);
                listeners[i] = new SupportUpdateListener();
                stmt.Events += listeners[i].Update;
            }

            // execute
            var threadPool      = Executors.NewFixedThreadPool(numThreads);
            var future          = new Future <bool> [numThreads];
            var sharedStartLock = ReaderWriterLockManager.CreateLock(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            using (sharedStartLock.AcquireWriteLock()) {
                for (var i = 0; i < numThreads; i++)
                {
                    future[i] = threadPool.Submit(new SendEventRWLockCallable(
                                                      i, sharedStartLock.ReadLock, engine,
                                                      EnumerationGenerator.Create(numEvents)));
                }
                Thread.Sleep(100);
            }

            threadPool.Shutdown();
            threadPool.AwaitTermination(new TimeSpan(0, 0, 10));

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

            // assert result
            for (var i = 0; i < numEvents - 1; i++)
            {
                Assert.AreEqual(1, listeners[i].NewDataList.Count, "Listener not invoked: #" + i);
            }
        }
Example #2
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="name">the factory name</param>
        /// <param name="stateless">if set to <c>true</c> [stateless].</param>
        /// <param name="msecWait">the number of milliseconds latches will await maximually</param>
        /// <param name="locking">the blocking strategy to employ</param>
        /// <param name="timeSourceService">time source provider</param>
        public InsertIntoLatchFactory(String name, bool stateless, long msecWait, ConfigurationEngineDefaults.Threading.Locking locking, TimeSourceService timeSourceService)
        {
            _name              = name;
            _msecWait          = msecWait;
            _timeSourceService = timeSourceService;
            _stateless         = stateless;

            _useSpin = (locking == ConfigurationEngineDefaults.Threading.Locking.SPIN);

            // construct a completed latch as an initial root latch
            if (_useSpin)
            {
                _currentLatchSpin = new InsertIntoLatchSpin(this);
            }
            else
            {
                _currentLatchWait = new InsertIntoLatchWait(this);
            }
        }
Example #3
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="name">the factory name</param>
        /// <param name="enabled"></param>
        /// <param name="msecWait">the number of milliseconds latches will await maximually</param>
        /// <param name="locking">the blocking strategy to employ</param>
        /// <param name="timeSourceService">time source provider</param>
        /// <param name="initializenow"></param>
        public NamedWindowConsumerLatchFactory(string name, bool enabled, long msecWait, ConfigurationEngineDefaults.Threading.Locking locking, TimeSourceService timeSourceService, bool initializenow)
        {
            Name              = name;
            Enabled           = enabled;
            MsecWait          = msecWait;
            TimeSourceService = timeSourceService;

            UseSpin = enabled && (locking == ConfigurationEngineDefaults.Threading.Locking.SPIN);

            // construct a completed latch as an initial root latch
            if (initializenow && UseSpin)
            {
                _currentLatchSpin = new NamedWindowConsumerLatchSpin(this);
            }
            else if (initializenow && enabled)
            {
                _currentLatchWait = new NamedWindowConsumerLatchWait(this);
            }
        }
Example #4
0
        private static IBlockingQueue <Runnable> MakeQueue(int?threadPoolTimerExecCapacity, ConfigurationEngineDefaults.Threading.Locking blocking)
        {
            if ((threadPoolTimerExecCapacity == null) ||
                (threadPoolTimerExecCapacity <= 0) ||
                (threadPoolTimerExecCapacity == int.MaxValue))
            {
                return(blocking == ConfigurationEngineDefaults.Threading.Locking.SPIN
                    ? (IBlockingQueue <Runnable>) new ImperfectBlockingQueue <Runnable>()
                    : (IBlockingQueue <Runnable>) new LinkedBlockingQueue <Runnable>());
            }

            return(blocking == ConfigurationEngineDefaults.Threading.Locking.SPIN
                       ? (IBlockingQueue <Runnable>) new ImperfectBlockingQueue <Runnable>(threadPoolTimerExecCapacity.Value)
                       : (IBlockingQueue <Runnable>) new BoundBlockingQueue <Runnable>(threadPoolTimerExecCapacity.Value));
        }