Esempio n. 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.");
        }
Esempio n. 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.");
        }
Esempio n. 3
0
        private Sender[] CreateSenders(MemoryChannel channel, int[] sentDataSizes, DataOracle oracle)
        {
            Sender[] senders = new Sender[this.senderCount];
            for (int i = 0; i < senders.Length; ++i)
            {
                int  bufferSize = sentDataSizes[i % sentDataSizes.Length];
                byte fill       = (byte)(i + 1);
                senders[i] = new Sender(channel, this.logger, bufferSize, fill, new Delay(2, 1));
                oracle.AddPattern(fill, bufferSize);
            }

            return(senders);
        }
 public ValidatingReceiver(MemoryChannel channel, Logger logger, int bufferSize, DataOracle oracle)
 {
     this.receiver = new Receiver(channel, logger, bufferSize);
     this.oracle = oracle;
     this.receiver.DataReceived += this.OnDataReceived;
 }
Esempio n. 5
0
 public ValidatingReceiver(MemoryChannel channel, Logger logger, int bufferSize, DataOracle oracle)
 {
     this.receiver = new Receiver(channel, logger, bufferSize);
     this.oracle   = oracle;
     this.receiver.DataReceived += this.OnDataReceived;
 }
Esempio n. 6
0
        private Sender[] CreateSenders(MemoryChannel channel, int[] sentDataSizes, DataOracle oracle)
        {
            Sender[] senders = new Sender[this.senderCount];
            for (int i = 0; i < senders.Length; ++i)
            {
                int bufferSize = sentDataSizes[i % sentDataSizes.Length];
                byte fill = (byte)(i + 1);
                senders[i] = new Sender(channel, this.logger, bufferSize, fill, new Delay(2, 1));
                oracle.AddPattern(fill, bufferSize);
            }

            return senders;
        }