private LinkedBlockingQueue<String> PopulatedDeque(int n)
 {
     LinkedBlockingQueue<String> q = new LinkedBlockingQueue<String>(n);
     Assert.IsTrue(q.IsEmpty());
     for(int i = 0; i < n; i++)
     {
         Assert.IsTrue(q.Offer(i.ToString()));
     }
     Assert.IsFalse(q.IsEmpty());
     Assert.AreEqual(0, q.RemainingCapacity());
     Assert.AreEqual(n, q.Size());
     return q;
 }
        // Test dispatcher should timeout on draining events.
        /// <exception cref="System.Exception"/>
        public virtual void TestDispatchStopOnTimeout()
        {
            BlockingQueue <Org.Apache.Hadoop.Yarn.Event.Event> eventQueue = new LinkedBlockingQueue
                                                                            <Org.Apache.Hadoop.Yarn.Event.Event>();

            eventQueue = Org.Mockito.Mockito.Spy(eventQueue);
            // simulate dispatcher is not drained.
            Org.Mockito.Mockito.When(eventQueue.IsEmpty()).ThenReturn(false);
            YarnConfiguration conf = new YarnConfiguration();

            conf.SetInt(YarnConfiguration.DispatcherDrainEventsTimeout, 2000);
            DrainDispatcher disp = new DrainDispatcher(eventQueue);

            disp.Init(conf);
            disp.SetDrainEventsOnStop();
            disp.Start();
            disp.WaitForEventThreadToWait();
            disp.Close();
        }
 public void TestEmptyFull()
 {
     LinkedBlockingQueue<String> q = new LinkedBlockingQueue<String>(2);
     Assert.IsTrue(q.IsEmpty());
     Assert.AreEqual(2, q.RemainingCapacity(), "should have room for 2");
     q.Add(one);
     Assert.IsFalse(q.IsEmpty());
     q.Add(two);
     Assert.IsFalse(q.IsEmpty());
     Assert.AreEqual(0, q.RemainingCapacity());
     Assert.IsFalse(q.Offer(three));
 }
示例#4
0
        public void Run(RegressionEnvironment env)
        {
            // configure
            var numThreads = 2;
            var numStatements = 100;
            var numEvents = 50000;

            // set up threading
            var queue = new LinkedBlockingQueue<Runnable>();
            var threadPool = Executors.NewFixedThreadPool(
                numThreads,
                new SupportThreadFactory(typeof(MultithreadPatternTimer)).ThreadFactory);

            // create statements
            log.Info("Creating statements");
            for (var i = 0; i < numStatements; i++) {
                var statementName = "s" + i;
                var stmtText =
                    $"@Name('s{i}')select * from pattern" +
                    $" [ every e1=SupportByteArrEventLongId(Id={i}) -> timer:interval(1 seconds)]";

                var supportCountListener = new SupportCountListener();
                _supportCountListeners[statementName] = supportCountListener;
                
                env.CompileDeploy(
                    stmtText,
                    options => options.SetStatementUserObject(
                        _ => supportCountListener));

                var statement = env.Statement(statementName);
                statement.AddListener(supportCountListener);
            }

            // submit events
            var startTime = DateTimeHelper.CurrentTimeMillis;
            log.Info("Submitting " + numEvents + " events to queue");
            var random = new Random();
            for (var i = 0; i < numEvents; i++) {
                var @event = new SupportByteArrEventLongId(random.Next(numStatements), 0);
                threadPool.Submit(() => env.SendEventBean(@event));
            }

            log.Info("Waiting for completion");
            while (!queue.IsEmpty()) {
                try {
                    Thread.Sleep(5000);
                }
                catch (ThreadInterruptedException) {
                    Assert.Fail();
                }

                log.Info("Queue size is " + queue.Count);
            }

            var endTime = DateTimeHelper.CurrentTimeMillis;
            log.Info("Time to complete: " + (endTime - startTime) / 1000 + " sec");

            // wait for completion
            log.Info("Waiting for remaining callbacks");
            var startWaitTime = DateTimeHelper.CurrentTimeMillis;
            while (true) {
                try {
                    Thread.Sleep(1000);
                }
                catch (ThreadInterruptedException) {
                    Assert.Fail();
                }

                var countTotal = GetCount(env, numStatements);
                if (countTotal >= numEvents) {
                    break;
                }

                if (DateTimeHelper.CurrentTimeMillis - startWaitTime > 20000) {
                    Assert.Fail();
                }

                log.Info("Waiting for remaining callbacks: " + countTotal + " of " + numEvents);
            }

            // assert
            var total = GetCount(env, numStatements);
            Assert.AreEqual(numEvents, total);

            env.UndeployAll();
        }