Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void mustCombineWork() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void MustCombineWork()
        {
            BinaryLatch       startLatch = new BinaryLatch();
            BinaryLatch       blockLatch = new BinaryLatch();
            FutureTask <Void> blocker    = new FutureTask <Void>(new CallableWork(this, new AddWorkAnonymousInnerClass(this, startLatch, blockLatch)));

            (new Thread(blocker)).Start();
            startLatch.Await();
            ICollection <FutureTask <Void> > tasks = new List <FutureTask <Void> >();

            tasks.Add(blocker);
            for (int i = 0; i < 20; i++)
            {
                CallableWork      task       = new CallableWork(this, new AddWork(1));
                FutureTask <Void> futureTask = new FutureTask <Void>(task);
                tasks.Add(futureTask);
                Thread thread = new Thread(futureTask);
                thread.Start();
                //noinspection StatementWithEmptyBody,LoopConditionNotUpdatedInsideLoop
                while (thread.State != Thread.State.TIMED_WAITING)
                {
                    // Wait for the thread to reach the lock.
                }
            }
            blockLatch.Release();
            foreach (FutureTask <Void> task in tasks)
            {
                task.get();
            }
            assertThat(_count.sum(), lessThan(_sum.sum()));
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void releaseThenAwaitDoesNotBlock()
        internal virtual void ReleaseThenAwaitDoesNotBlock()
        {
            assertTimeout(ofSeconds(3), () =>
            {
                BinaryLatch latch = new BinaryLatch();
                latch.Release();
                latch.Await();
            });
        }