protected override ITcpServerSocketModel RunInternal(ITcpServerSocketModel obj0)
            {
                var cb = new ClientBootstrap()
                         .Group(ClientEventLoopGroup)
                         .Channel <TcpSocketChannel>()
                         .Handler(new ActionChannelInitializer <TcpSocketChannel>(ConstructClientPipeline));

                var connectTasks = new List <Task <IChannel> >();

                for (var i = 0; i < ClientCount; i++)
                {
                    connectTasks.Add(cb.ConnectAsync(obj0.BoundAddress));
                }

                if (!Task.WaitAll(connectTasks.ToArray(), TimeSpan.FromSeconds(ClientCount * 2)))
                {
                    throw new TimeoutException(
                              $"Waited {ClientCount} seconds to connect {ClientCount} clients to {obj0.BoundAddress}, but the operation timed out.");
                }

                foreach (var task in connectTasks)
                {
                    // storing our local address for comparison purposes
                    obj0 = obj0.AddLocalChannel(task.Result).AddClient((IPEndPoint)task.Result.LocalAddress);
                }
                return(obj0);
            }
            protected override ITcpServerSocketModel RunInternal(ITcpServerSocketModel obj0)
            {
                var channels = obj0.LocalChannels;
                var maxIndex = channels.Count - 1;

                // write and read order will be different, but our equality checker knows how to deal with that.
                var rValue = obj0.ClearMessages().WriteMessages(_writes).ReceiveMessages(_writes);

                var tasks = new ConcurrentBag <Task>();
                // generate a distribution of writes concurrently across all channels
                var loopResult = Parallel.ForEach(_writes, i =>
                {
                    var nextChannel = channels[ThreadLocalRandom.Current.Next(0, maxIndex)];

                    // do write and flush for all writes
                    tasks.Add(nextChannel.WriteAndFlushAsync(i));
                });

                // wait for tasks to finish queuing
                SpinWait.SpinUntil(() => loopResult.IsCompleted, TimeSpan.FromMilliseconds(100));

                // picking big timeouts here just in case the input list is large
                var timeout = TimeSpan.FromSeconds(5);

                if (!Task.WaitAll(tasks.ToArray(), timeout))
                {
                    throw new TimeoutException(
                              $"Expected to be able to complete {_writes.Length} operations in under {timeout.TotalSeconds} seconds, but the operation timed out.");
                }

                return(rValue);
            }
Exemplo n.º 3
0
 public override Task WriteAsync(IChannelHandlerContext context, object message)
 {
     if (message is int)
     {
         State = State.WriteMessages((int)message);
     }
     return(base.WriteAsync(context, message));
 }
 public override Task WriteAsync(IChannelHandlerContext context, object message)
 {
     if (message is int)
     {
         State = State.WriteMessages((int) message);
     }
     return base.WriteAsync(context, message);
 }
        public override void ChannelRead(IChannelHandlerContext context, object message)
        {
            if (message is int)
            {
                var i = (int) message;
                State = State.ReceiveMessages(i);

                // echo the reply back to the client
                context.WriteAndFlushAsync(i);
            }
        }
Exemplo n.º 6
0
        public override void ChannelRead(IChannelHandlerContext context, object message)
        {
            if (message is int)
            {
                var i = (int)message;
                State = State.ReceiveMessages(i);

                // echo the reply back to the client
                context.WriteAndFlushAsync(i);
            }
        }
            protected override Property CheckInternal(ITcpServerSocketModel obj0, ITcpServerSocketModel obj1)
            {
                // need to give the inbound side a chance to catch up if the load was large.
                Task.Delay(100).Wait();
                Debugger.Break();
                var result = TcpServerSocketModelComparer.Instance.Equals(obj0, obj1)
                             .Label(
                    $"Expected [{string.Join(",", obj1.LastReceivedMessages.OrderBy(x => x))}] received by clients, but found only [{string.Join(",", obj0.LastReceivedMessages.OrderBy(x => x))}]");

                obj0 = obj0.ClearMessages();
                obj1 = obj1.ClearMessages();

                return(result);
            }
            protected override ITcpServerSocketModel RunInternal(ITcpServerSocketModel obj0)
            {
                var clientsToBeDisconnected = obj0.LocalChannels.Take(ClientCount).ToList();
                var disconnectTasks         = new List <Task>();

                foreach (var client in clientsToBeDisconnected)
                {
                    disconnectTasks.Add(client.DisconnectAsync());
                }

                if (Task.WaitAll(disconnectTasks.ToArray(), TimeSpan.FromSeconds(ClientCount)))
                {
                    throw new TimeoutException(
                              $"Waited {ClientCount} seconds to disconnect {ClientCount} clients from {obj0.BoundAddress}, but the operation timed out.");
                }

                foreach (var client in clientsToBeDisconnected)
                {
                    obj0 = obj0.RemoveClient((IPEndPoint)client.LocalAddress).RemoveLocalChannel(client);
                }
                return(obj0);
            }
 public override bool Pre(ITcpServerSocketModel _arg1)
 {
     return(base.Pre(_arg1) &&
            _arg1.LocalChannels.Count > 0 && // need at least 1 local channel
            _writes.Length > 0);   // need at least 1 write
 }
 public override bool Pre(ITcpServerSocketModel _arg1)
 {
     return(base.Pre(_arg1) && ClientCount <= _arg1.LocalChannels.Count);
 }
 protected override Property CheckInternal(ITcpServerSocketModel obj0, ITcpServerSocketModel obj1)
 {
     return(TcpServerSocketModelComparer.Instance.Equals(obj0, obj1)
            .Label(
                $"Expected {obj1} (order doesn't matter) but was {obj0}"));
 }
 public override bool Pre(ITcpServerSocketModel _arg1)
 {
     // need at least 1 client
     return(base.Pre(_arg1) && ClientCount > 0);
 }
Exemplo n.º 13
0
 public override void ChannelInactive(IChannelHandlerContext context)
 {
     State = State.RemoveLocalChannel(context.Channel).RemoveClient((IPEndPoint) context.Channel.RemoteAddress);
 }
Exemplo n.º 14
0
 public TcpServerSocketStateHandler(ITcpServerSocketModel state)
 {
     State = state;
 }
Exemplo n.º 15
0
 public override void ChannelInactive(IChannelHandlerContext context)
 {
     State = State.RemoveLocalChannel(context.Channel).RemoveClient((IPEndPoint)context.Channel.RemoteAddress);
 }
Exemplo n.º 16
0
 public TcpServerSocketStateHandler(ITcpServerSocketModel state)
 {
     State = state;
 }