Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void mustRecoverFromExceptions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void MustRecoverFromExceptions()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean broken = new java.util.concurrent.atomic.AtomicBoolean(true);
            AtomicBoolean broken = new AtomicBoolean(true);
            Adder         adder  = new AdderAnonymousInnerClass(this, broken);

            _sync = new WorkSync <Adder, AddWork>(adder);

            try
            {
                // Run this in a different thread to account for reentrant locks.
                _executor.submit(new CallableWork(this, new AddWork(10))).get();
                fail("Should have thrown");
            }
            catch (ExecutionException exception)
            {
                // Outermost ExecutionException from the ExecutorService
                assertThat(exception.InnerException, instanceOf(typeof(ExecutionException)));

                // Inner ExecutionException from the WorkSync
                exception = ( ExecutionException )exception.InnerException;
                assertThat(exception.InnerException, instanceOf(typeof(System.InvalidOperationException)));
            }

            broken.set(false);
            _sync.apply(new AddWork(20));

            assertThat(_sum.sum(), @is(20L));
            assertThat(_count.sum(), @is(1L));
        }
Example #2
0
 private void InitializeInstanceFields()
 {
     _adder = new Adder(this);
     _sync  = new WorkSync <Adder, AddWork>(_adder);
 }