Exemplo n.º 1
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 void InProcSocket_maps_to_MessageFrameQueueWriter()
        {
            var socket = new InProcSocket();

            var factory = new MessageFrameWriterFactory();
            var writer = factory.CreateWriterFromSocket(socket);

            Assert.IsInstanceOf<MessageFrameQueueWriter>(writer);
        }
        public void InProcSocket_maps_to_MessageFrameQueueWriter()
        {
            var socket = new InProcSocket();

            var factory = new NodeGreetingMessageNegotiatorFactory();
            var negotiator = factory.CreateFromSocket(socket);

            Assert.IsInstanceOf<NodeGreetingMessageQueueSocketNegotiator>(negotiator);
        }
        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);
        }
 private bool TryFireClientConnectedEvent(InProcSocket socket, ISocketConfiguration socketConfiguration)
 {
     try
     {
         socket.Disconnected += () => ClientDisconnected(socket);
         ClientConnected(socket, socketConfiguration);
         return true;
     }
     catch
     {
         return false;
     }
 }
 private bool TryFireClientConnectedEvent(InProcSocket socket, ISocketConfiguration socketConfiguration)
 {
     try
     {
         socket.Disconnected += () => ClientDisconnected(socket);
         ClientConnected(socket, socketConfiguration);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 8
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();
            }
        }
        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();
        }