//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())); }
//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(); }); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void releaseMustUnblockAwaiters() internal virtual void ReleaseMustUnblockAwaiters() { assertTimeout(ofSeconds(10), () => { BinaryLatch latch = new BinaryLatch(); ThreadStart awaiter = latch.await; int awaiters = 24; Future <object>[] futures = new Future <object> [awaiters]; for (int i = 0; i < awaiters; i++) { futures[i] = _executor.submit(awaiter); } assertThrows(typeof(TimeoutException), () => futures[0].get(10, TimeUnit.MILLISECONDS)); latch.Release(); foreach (Future <object> future in futures) { future.get(); } }); }