예제 #1
0
 public void CloseListenerShouldBeNotifiedOnlyOneTime()
 {
     _handler = NewHandler();
     _future  = TaskUtil.Completed;
     //doAnswer(new Answer<ChannelFuture>() {
     //    @Override
     //    public ChannelFuture answer(InvocationOnMock invocation) throws Throwable {
     //        Object[] args = invocation.getArguments();
     //        GenericFutureListener<ChannelFuture> listener = (GenericFutureListener<ChannelFuture>) args[0];
     //        // Simulate that all streams have become inactive by the time the future completes.
     //        doAnswer(new Answer<Http2Stream>() {
     //            @Override
     //            public Http2Stream answer(InvocationOnMock in) throws Throwable {
     //                return null;
     //            }
     //        }).when(connection).forEachActiveStream(any(Http2StreamVisitor_class));
     //        when(connection.numActiveStreams()).thenReturn(0);
     //        // Simulate the future being completed.
     //        listener.operationComplete(future);
     //        return future;
     //    }
     //}).when(future).addListener(any(GenericFutureListener_class));
     _handler.Close(_ctx.Object, _promise);
     _connection
     .Setup(x => x.ForEachActiveStream(It.IsAny <IHttp2StreamVisitor>()))
     .Returns(default(IHttp2Stream));
     _connection
     .Setup(x => x.ForEachActiveStream(It.IsAny <Func <IHttp2Stream, bool> >()))
     .Returns(default(IHttp2Stream));
     if (_future.IsCompleted)
     {
         _connection.Setup(x => x.NumActiveStreams).Returns(0);
     }
     _handler.CloseStream(_stream.Object, _future);
     // Simulate another stream close call being made after the context should already be closed.
     _handler.CloseStream(_stream.Object, _future);
     _ctx.Verify(x => x.CloseAsync(It.IsAny <IPromise>()), Times.Once);
 }