Ejemplo n.º 1
0
        public virtual void ShouldKeepHighest()
        {
            // GIVEN
            Race      race      = new Race();
            HighestId highestId = new HighestId();
            int       threads   = Runtime.Runtime.availableProcessors();

            System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(threads);
            AtomicLongArray highestIds            = new AtomicLongArray(threads);

            for (int c = 0; c < threads; c++)
            {
                int cc = c;
                race.AddContestant(new RunnableAnonymousInnerClass(this, highestId, latch, highestIds, cc));
            }
            race.WithEndCondition(() => latch.CurrentCount == 0);

            // WHEN
            race.Go();

            long highest = 0;

            for (int i = 0; i < threads; i++)
            {
                highest = max(highest, highestIds.get(i));
            }
            assertEquals(highest, highestId.Get());
        }
Ejemplo n.º 2
0
 public override long getCountAtIndex(int index)
 {
     return(counts.get(index));
 }