public async Task ClientWebSocketChannelReadWithoutConnectTest() { var websocket = new ClientWebSocket(); clientWebSocketChannel = new ClientWebSocketChannel(null, websocket); var threadLoop = new SingleThreadEventLoop("MQTTExecutionThread", TimeSpan.FromSeconds(1)); await threadLoop.RegisterAsync(clientWebSocketChannel); clientWebSocketChannel.Read(); }
public SingleInstanceEventLoopGroup() { this.eventLoop = new SingleThreadEventLoop(); }
public async Task ClientWebSocketChannelReadAfterCloseTest() { var websocket = new ClientWebSocket(); websocket.Options.AddSubProtocol(WebSocketConstants.SubProtocols.Mqtt); var uri = new Uri("ws://" + IotHubName + ":" + Port + WebSocketConstants.UriSuffix); await websocket.ConnectAsync(uri, CancellationToken.None); var clientReadListener = new ReadListeningHandler(); var clientChannel = new ClientWebSocketChannel(null, websocket); clientChannel .Option(ChannelOption.Allocator, UnpooledByteBufferAllocator.Default) .Option(ChannelOption.AutoRead, true) .Option(ChannelOption.RcvbufAllocator, new AdaptiveRecvByteBufAllocator()) .Option(ChannelOption.MessageSizeEstimator, DefaultMessageSizeEstimator.Default); clientChannel.Pipeline.AddLast( clientReadListener); var threadLoop = new SingleThreadEventLoop("MQTTExecutionThread", TimeSpan.FromSeconds(1)); await threadLoop.RegisterAsync(clientChannel); await clientChannel.CloseAsync(); // Test Read API try { await clientReadListener.ReceiveAsync(DefaultTimeout); Assert.Fail("Should have thrown InvalidOperationException"); } catch (InvalidOperationException e) { Assert.IsTrue(e.Message.Contains("Channel is closed")); } done = true; }
public async Task ClientWebSocketChannelWriteAfterCloseTest() { var websocket = new ClientWebSocket(); websocket.Options.AddSubProtocol(WebSocketConstants.SubProtocols.Mqtt); var uri = new Uri("ws://" + IotHubName + ":" + Port + WebSocketConstants.UriSuffix); await websocket.ConnectAsync(uri, CancellationToken.None); clientWebSocketChannel = new ClientWebSocketChannel(null, websocket); var threadLoop = new SingleThreadEventLoop("MQTTExecutionThread", TimeSpan.FromSeconds(1)); await threadLoop.RegisterAsync(clientWebSocketChannel); await clientWebSocketChannel.CloseAsync(); // Test Write API try { await clientWebSocketChannel.WriteAndFlushAsync(Unpooled.Buffer()); Assert.Fail("Should have thrown ClosedChannelException"); } catch (AggregateException e) { var innerException = e.InnerException as ClosedChannelException; Assert.IsNotNull(innerException); } done = true; }