コード例 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowThrottleExceptionWhenMaxDurationIsReached() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowThrottleExceptionWhenMaxDurationIsReached()
        {
            // given
            TestThrottleLock  lockOverride = new TestThrottleLock();
            FakeClock         clock        = Clocks.fakeClock(1, TimeUnit.SECONDS);
            TransportThrottle throttle     = NewThrottleAndInstall(_channel, lockOverride, clock, Duration.ofSeconds(5));

            when(_channel.Writable).thenReturn(false);

            // when
            Future <Void> future = OtherThread.execute(state =>
            {
                throttle.Acquire(_channel);
                return(null);
            });

            OtherThread.get().waitUntilWaiting();
            clock.Forward(6, TimeUnit.SECONDS);

            // expect
            try
            {
                future.get(1, TimeUnit.MINUTES);

                fail("expecting ExecutionException");
            }
            catch (ExecutionException ex)
            {
                assertThat(ex.InnerException, instanceOf(typeof(TransportThrottleException)));
                assertThat(ex.Message, containsString("will be closed because the client did not consume outgoing buffers for"));
            }
        }
コード例 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotLockWhenWritable() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotLockWhenWritable()
        {
            // given
            TestThrottleLock  lockOverride = new TestThrottleLock();
            TransportThrottle throttle     = NewThrottleAndInstall(_channel, lockOverride);

            when(_channel.Writable).thenReturn(true);

            // when
            Future future = OtherThread.execute(state =>
            {
                throttle.Acquire(_channel);
                return(null);
            });

            // expect
            try
            {
                future.get(2000, TimeUnit.MILLISECONDS);
            }
            catch (Exception)
            {
                fail("should not throw");
            }

            assertTrue(future.Done);
            assertThat(lockOverride.LockCallCount(), @is(0));
            assertThat(lockOverride.UnlockCallCount(), @is(0));
        }
コード例 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldResumeWhenWritabilityChanged() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldResumeWhenWritabilityChanged()
        {
            TestThrottleLock lockOverride = new TestThrottleLock();

            // given
            TransportThrottle throttle = NewThrottleAndInstall(_channel, lockOverride);

            when(_channel.Writable).thenReturn(false);

            Future <Void> completionFuture = OtherThread.execute(state =>
            {
                throttle.Acquire(_channel);
                return(null);
            });

            OtherThread.get().waitUntilWaiting();

            // when
            when(_channel.Writable).thenReturn(true);
            ArgumentCaptor <ChannelInboundHandler> captor = ArgumentCaptor.forClass(typeof(ChannelInboundHandler));

            verify(_channel.pipeline()).addLast(captor.capture());
            captor.Value.channelWritabilityChanged(_context);

            OtherThread.get().awaitFuture(completionFuture);

            assertThat(lockOverride.LockCallCount(), greaterThan(0));
            assertThat(lockOverride.UnlockCallCount(), @is(1));
        }
コード例 #4
0
        private TransportThrottle NewThrottleAndInstall(Channel channel, ThrottleLock lockOverride, Clock clock, Duration maxLockDuration)
        {
            TransportThrottle throttle = NewThrottle(lockOverride, clock, maxLockDuration);

            throttle.Install(channel);

            return(throttle);
        }
コード例 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldResumeWhenWritableOnceAgain() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldResumeWhenWritableOnceAgain()
        {
            // given
            TransportThrottle throttle = NewThrottleAndInstall(_channel);

            when(_channel.Writable).thenReturn(false).thenReturn(true);

            // when
            throttle.Acquire(_channel);

            // expect
            verify(@lock, atLeast(1)).@lock(any(), anyLong());
            verify(@lock, never()).unlock(any());
        }
コード例 #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSetWriteBufferWatermarkOnChannelConfigWhenInstalled()
        public virtual void ShouldSetWriteBufferWatermarkOnChannelConfigWhenInstalled()
        {
            // given
            TransportThrottle throttle = NewThrottle();

            // when
            throttle.Install(_channel);

            // expect
            ArgumentCaptor <WriteBufferWaterMark> argument = ArgumentCaptor.forClass(typeof(WriteBufferWaterMark));

            verify(_config, times(1)).WriteBufferWaterMark = argument.capture();

            assertEquals(64, argument.Value.low());
            assertEquals(256, argument.Value.high());
        }
コード例 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLockWhenNotWritable() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldLockWhenNotWritable()
        {
            // given
            TestThrottleLock  lockOverride = new TestThrottleLock();
            TransportThrottle throttle     = NewThrottleAndInstall(_channel, lockOverride);

            when(_channel.Writable).thenReturn(false);

            // when
            Future <Void> future = OtherThread.execute(state =>
            {
                throttle.Acquire(_channel);
                return(null);
            });

            // expect
            try
            {
                future.get(2000, TimeUnit.MILLISECONDS);

                fail("should timeout");
            }
            catch (TimeoutException)
            {
                // expected
            }

            assertFalse(future.Done);
            assertThat(lockOverride.LockCallCount(), greaterThan(0));
            assertThat(lockOverride.UnlockCallCount(), @is(0));

            // stop the thread that is trying to acquire the lock
            // otherwise it remains actively spinning even after the test
            future.cancel(true);
            try
            {
                OtherThread.get().awaitFuture(future);
                fail("Exception expected");
            }
            catch (CancellationException)
            {
            }
        }
コード例 #8
0
 public TransportThrottleGroup(Config config, Clock clock)
 {
     this._writeThrottle = CreateWriteThrottle(config, clock);
 }
コード例 #9
0
 private TransportThrottleGroup()
 {
     this._writeThrottle = NoOpTransportThrottle.Instance;
 }