Пример #1
0
        public void Run()
        {
            this.logger.WriteLine("Receive loop with {0} senders, {1:0.0} sec, send before receive={2}, receive buffer={3}...", this.senderCount, this.duration.TotalSeconds, this.sendBeforeReceive, this.receiveBufferSize);

            MemoryChannel channel = new MemoryChannel();

            int[] sentDataSizes = new int[] { 11, 19, 29, 41, 53, 71, 89, 101 };

            using (CancellationTokenSource cts = new CancellationTokenSource())
            {
                DataOracle oracle  = new DataOracle();
                Sender[]   senders = this.CreateSenders(channel, sentDataSizes, oracle);

                ValidatingReceiver receiver = new ValidatingReceiver(channel, this.logger, this.receiveBufferSize, oracle);

                Task <long>[] senderTasks  = new Task <long> [senders.Length];
                Task <long>   receiverTask = this.StartSendersAndReceiver(cts.Token, senders, receiver, senderTasks);
                Thread.Sleep(this.duration);

                cts.Cancel();
                Task.WaitAll(senderTasks);

                channel.Dispose();
                receiverTask.Wait();

                ValidateTransferredByteCount(senderTasks, receiverTask);
            }

            this.logger.WriteLine("Done.");
        }
Пример #2
0
        public void Run()
        {
            this.logger.WriteLine("Receive loop with {0} senders, {1:0.0} sec, send before receive={2}, receive buffer={3}...", this.senderCount, this.duration.TotalSeconds, this.sendBeforeReceive, this.receiveBufferSize);

            MemoryChannel channel = new MemoryChannel();
            int[] sentDataSizes = new int[] { 11, 19, 29, 41, 53, 71, 89, 101 };

            using (CancellationTokenSource cts = new CancellationTokenSource())
            {
                DataOracle oracle = new DataOracle();
                Sender[] senders = this.CreateSenders(channel, sentDataSizes, oracle);

                ValidatingReceiver receiver = new ValidatingReceiver(channel, this.logger, this.receiveBufferSize, oracle);

                Task<long>[] senderTasks = new Task<long>[senders.Length];
                Task<long> receiverTask = this.StartSendersAndReceiver(cts.Token, senders, receiver, senderTasks);
                Thread.Sleep(this.duration);

                cts.Cancel();
                Task.WaitAll(senderTasks);

                channel.Dispose();
                receiverTask.Wait();

                ValidateTransferredByteCount(senderTasks, receiverTask);
            }

            this.logger.WriteLine("Done.");
        }
Пример #3
0
        private Task <long> StartSendersAndReceiver(CancellationToken token, Sender[] senders, ValidatingReceiver receiver, Task <long>[] senderTasks)
        {
            Task <long> receiverTask;

            if (this.sendBeforeReceive)
            {
                StartSenders(token, senders, senderTasks);
                receiverTask = receiver.RunAsync();
            }
            else
            {
                receiverTask = receiver.RunAsync();
                StartSenders(token, senders, senderTasks);
            }

            return(receiverTask);
        }
Пример #4
0
        private Task<long> StartSendersAndReceiver(CancellationToken token, Sender[] senders, ValidatingReceiver receiver, Task<long>[] senderTasks)
        {
            Task<long> receiverTask;
            if (this.sendBeforeReceive)
            {
                StartSenders(token, senders, senderTasks);
                receiverTask = receiver.RunAsync();
            }
            else
            {
                receiverTask = receiver.RunAsync();
                StartSenders(token, senders, senderTasks);
            }

            return receiverTask;
        }