Exemplo n.º 1
0
        /// <exception cref="System.Exception"/>
        public virtual void TestTakeTriesNextQueue()
        {
            // Make a FCQ filled with calls in q 1 but empty in q 0
            RpcScheduler q1Scheduler = Org.Mockito.Mockito.Mock <RpcScheduler>();

            Org.Mockito.Mockito.When(q1Scheduler.GetPriorityLevel(Matchers.Any <Schedulable>()
                                                                  )).ThenReturn(1);
            fcq.SetScheduler(q1Scheduler);
            // A mux which only draws from q 0
            RpcMultiplexer q0mux = Org.Mockito.Mockito.Mock <RpcMultiplexer>();

            Org.Mockito.Mockito.When(q0mux.GetAndAdvanceCurrentIndex()).ThenReturn(0);
            fcq.SetMultiplexer(q0mux);
            Schedulable call = MockCall("c");

            fcq.Put(call);
            // Take from q1 even though mux said q0, since q0 empty
            Assert.Equal(call, fcq.Take());
            Assert.Equal(0, fcq.Count);
        }
Exemplo n.º 2
0
        /// <summary>Create a FairCallQueue.</summary>
        /// <param name="capacity">the maximum size of each sub-queue</param>
        /// <param name="ns">the prefix to use for configuration</param>
        /// <param name="conf">
        /// the configuration to read from
        /// Notes: the FairCallQueue has no fixed capacity. Rather, it has a minimum
        /// capacity of `capacity` and a maximum capacity of `capacity * number_queues`
        /// </param>
        public FairCallQueue(int capacity, string ns, Configuration conf)
        {
            /* Scheduler picks which queue to place in */
            /* Multiplexer picks which queue to draw from */
            /* Statistic tracking */
            int numQueues = ParseNumQueues(ns, conf);

            Log.Info("FairCallQueue is in use with " + numQueues + " queues.");
            this.queues          = new AList <BlockingQueue <E> >(numQueues);
            this.overflowedCalls = new AList <AtomicLong>(numQueues);
            for (int i = 0; i < numQueues; i++)
            {
                this.queues.AddItem(new LinkedBlockingQueue <E>(capacity));
                this.overflowedCalls.AddItem(new AtomicLong(0));
            }
            this.scheduler   = new DecayRpcScheduler(numQueues, ns, conf);
            this.multiplexer = new WeightedRoundRobinMultiplexer(numQueues, ns, conf);
            // Make this the active source of metrics
            FairCallQueue.MetricsProxy mp = FairCallQueue.MetricsProxy.GetInstance(ns);
            mp.SetDelegate(this);
        }
Exemplo n.º 3
0
 public virtual void SetMultiplexer(RpcMultiplexer newMux)
 {
     this.multiplexer = newMux;
 }