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

            Assert.Throws<OperationCanceledException>(() => 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();
            }
        }
Пример #3
0
 public InProcSocket(RedFoxEndpoint endpoint, BlockingConcurrentQueue<MessageFrame> writeStream, BlockingConcurrentQueue<MessageFrame> readStream)
 {
     if (writeStream == null) throw new ArgumentNullException("writeStream");
     if (readStream == null) throw new ArgumentNullException("readStream");
     Endpoint = endpoint;
     _writeStream = writeStream;
     _readStream = readStream;
 }
        public void enqueue_then_does_not_wait_on_dequeue()
        {
            var queue = new BlockingConcurrentQueue<int>();
            var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(30));

            queue.Enqueue(1);
            Assert.AreEqual(1, 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 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 }));
        }
        public void WriteGreetingAsync_writes_full_NodeGreetingMessage()
        {
            var blockingQueue = new BlockingConcurrentQueue<MessageFrame>();
            var socket = new InProcSocket(RedFoxEndpoint.Empty, blockingQueue, blockingQueue);

            var negotiator = new NodeGreetingMessageQueueSocketNegotiator(socket);

            var message = new NodeGreetingMessage(NodeType.Responder);
            negotiator.WriteGreetingAsync(message, CancellationToken.None).Wait();

            Assert.AreEqual(message.Serialize(), blockingQueue.Dequeue(CancellationToken.None).RawMessage);
        }
Пример #9
0
        public InProcSocket Connect(RedFoxEndpoint endpoint)
        {
            if (endpoint.Transport != RedFoxTransport.Inproc)
                throw new ArgumentException("Only InProcess transport endpoints are allowed to be registered");

            BlockingCollection<InProcSocketPair> accepter;
            if (!_registeredAccepterPorts.TryGetValue(endpoint, out accepter))
            {
                throw new InvalidOperationException("Endpoint not listening to InProcess clients");
            }

            var clientStream = new BlockingConcurrentQueue<MessageFrame>();
            var serverStream = new BlockingConcurrentQueue<MessageFrame>();
            var clientSocket = new InProcSocket(endpoint, clientStream, serverStream);
            var serverSocket = new InProcSocket(endpoint, serverStream, clientStream);

            var socketPair = new InProcSocketPair(clientSocket, serverSocket);
            accepter.Add(socketPair);

            return clientSocket;
        }
        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();
            }
        }