public void enqueue_enqueue_does_not_wait_on_both_dequeue()
        {
            var queue = new BlockingConcurrentQueue<int>();
            var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(30));

            queue.Enqueue(1);
            queue.Enqueue(2);

            Assert.AreEqual(1, queue.Dequeue(cts.Token));
            Assert.AreEqual(2, queue.Dequeue(cts.Token));
        }
        public void enqueue_enqueue_does_not_wait_on_both_dequeue()
        {
            var queue = new BlockingConcurrentQueue <int>();
            var cts   = new CancellationTokenSource(TimeSpan.FromMilliseconds(30));

            queue.Enqueue(1);
            queue.Enqueue(2);

            Assert.AreEqual(1, queue.Dequeue(cts.Token));
            Assert.AreEqual(2, queue.Dequeue(cts.Token));
        }
        public async Task VerifyRemoteGreetingAsync_not_matching_expected_NodeType()
        {
            var blockingQueue = new BlockingConcurrentQueue <MessageFrame>();
            var socket        = new InProcSocket(RedFoxEndpoint.Empty, blockingQueue, blockingQueue);

            var negotiator = new NodeGreetingMessageQueueSocketNegotiator(socket);
            var message    = new NodeGreetingMessage(NodeType.Responder);

            blockingQueue.Enqueue(new MessageFrame {
                RawMessage = message.Serialize()
            });

            try
            {
                await negotiator.VerifyRemoteGreetingAsync(new HashSet <NodeType> {
                    NodeType.Requester
                }, CancellationToken.None);

                Assert.Fail();
            }
            catch (RedFoxProtocolException)
            {
                Assert.Pass();
            }
        }
        public void enqueue_dequeue_then_wait_on_dequeue()
        {
            var queue = new BlockingConcurrentQueue <int>();
            var cts   = new CancellationTokenSource(TimeSpan.FromMilliseconds(30));

            queue.Enqueue(1);
            queue.Dequeue(cts.Token);
            Assert.Throws <OperationCanceledException>(() => queue.Dequeue(cts.Token));
        }
        public void enqueue_dequeue_then_wait_on_dequeue()
        {
            var queue = new BlockingConcurrentQueue<int>();
            var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(30));

            queue.Enqueue(1);
            queue.Dequeue(cts.Token);
            Assert.Throws<OperationCanceledException>(() => queue.Dequeue(cts.Token));
        }
        public void VerifyRemoteGreeting_not_matching_expected_NodeType()
        {
            var blockingQueue = new BlockingConcurrentQueue<MessageFrame>();
            var socket = new InProcSocket(RedFoxEndpoint.Empty, blockingQueue, blockingQueue);

            var negotiator = new NodeGreetingMessageQueueSocketNegotiator(socket);
            var message = new NodeGreetingMessage(NodeType.Responder);
            blockingQueue.Enqueue(new MessageFrame { RawMessage = message.Serialize() });

            Assert.Throws<RedFoxProtocolException>(() => negotiator.VerifyRemoteGreeting(new HashSet<NodeType> { NodeType.Requester }));
        }
        public void VerifyRemoteGreetingAsync_matching_expected_NodeType()
        {
            var blockingQueue = new BlockingConcurrentQueue <MessageFrame>();
            var socket        = new InProcSocket(RedFoxEndpoint.Empty, blockingQueue, blockingQueue);

            var negotiator = new NodeGreetingMessageQueueSocketNegotiator(socket);
            var message    = new NodeGreetingMessage(NodeType.Responder);

            blockingQueue.Enqueue(new MessageFrame {
                RawMessage = message.Serialize()
            });

            negotiator.VerifyRemoteGreetingAsync(new HashSet <NodeType> {
                NodeType.Responder
            }, CancellationToken.None).Wait();
        }
        public void VerifyRemoteGreeting_not_matching_expected_NodeType()
        {
            var blockingQueue = new BlockingConcurrentQueue <MessageFrame>();
            var socket        = new InProcSocket(RedFoxEndpoint.Empty, blockingQueue, blockingQueue);

            var negotiator = new NodeGreetingMessageQueueSocketNegotiator(socket);
            var message    = new NodeGreetingMessage(NodeType.Responder);

            blockingQueue.Enqueue(new MessageFrame {
                RawMessage = message.Serialize()
            });

            Assert.Throws <RedFoxProtocolException>(() => negotiator.VerifyRemoteGreeting(new HashSet <NodeType> {
                NodeType.Requester
            }));
        }
예제 #9
0
 public void SendPacket(Packet p)
 {
     _packetsToSend.Enqueue(p);
 }
예제 #10
0
 void LogMessage(string message)
 {
     Debug.WriteLine($"[tid:{Thread.CurrentThread.ManagedThreadId}] {message}");
     _queue.Enqueue($"[tid:{Thread.CurrentThread.ManagedThreadId}] {message}");
 }
        public async Task VerifyRemoteGreetingAsync_not_matching_expected_NodeType()
        {
            var blockingQueue = new BlockingConcurrentQueue<MessageFrame>();
            var socket = new InProcSocket(RedFoxEndpoint.Empty, blockingQueue, blockingQueue);

            var negotiator = new NodeGreetingMessageQueueSocketNegotiator(socket);
            var message = new NodeGreetingMessage(NodeType.Responder);
            blockingQueue.Enqueue(new MessageFrame { RawMessage = message.Serialize() });

            try
            {
                await negotiator.VerifyRemoteGreetingAsync(new HashSet<NodeType> { NodeType.Requester }, CancellationToken.None);
                Assert.Fail();
            }
            catch (RedFoxProtocolException)
            {
                Assert.Pass();
            }
        }
        public void VerifyRemoteGreetingAsync_matching_expected_NodeType()
        {
            var blockingQueue = new BlockingConcurrentQueue<MessageFrame>();
            var socket = new InProcSocket(RedFoxEndpoint.Empty, blockingQueue, blockingQueue);

            var negotiator = new NodeGreetingMessageQueueSocketNegotiator(socket);
            var message = new NodeGreetingMessage(NodeType.Responder);
            blockingQueue.Enqueue(new MessageFrame { RawMessage = message.Serialize() });

            negotiator.VerifyRemoteGreetingAsync(new HashSet<NodeType> { NodeType.Responder }, CancellationToken.None).Wait();
        }