示例#1
0
        internal static async Task UseBusInterface(SocketConfiguration _)
        {
            using var socket = Zer0Mq.Go().BuildWithInProc("bus-interface");

            socket.Respond <Request, Response>((r) => new Response());

            var response = await socket.RequestAsync <Request, Response>(new Request());

            System.Console.WriteLine(response.InsideResponse);
        }
示例#2
0
        public async Task TryPublish_returns_false_if_it_cannot_publish()
        {
            // Arrange
            var socket = Zer0Mq.Go().BuildWithInProc("try-pubish");

            // Act
            bool published = await socket.TryPublishAsync(new Message());

            // Assert
            Assert.False(published);
        }
示例#3
0
 // socket came late, for now no refactoring of all tests desired
 private static ISocket ToSocket(SocketConfiguration configuration)
 {
     if (configuration is SocketConfiguration.Tcp tcp)
     {
         string port = tcp.Address().Split(":").Last();
         return(Zer0Mq.Go().BuildWithTcp("localhost", port));
     }
     else
     {
         return(Zer0Mq.Go().BuildWithInProc(configuration.Address().Split("//").Last()));
     }
 }
示例#4
0
        public void Single_instance_of_SendReceive_trying_to_setup_another_responder_or_receiver_on_same_instance_throws()
        {
            // Arrange
            using var socket = Zer0Mq.Go().SilenceLogger().BuildWithInProc("send-pipe-throw");
            socket.Receiver <Message>((r) => { });

            // Act
            Action setupReceiverThatThrows        = () => socket.Receiver <Message>((r) => {});
            Action setupResponderActionThatThrows = () => socket.Respond <Message, Message>((r) => r);

            // Assert
            Assert.Throws <ZeroMqXtSocketException>(setupReceiverThatThrows);
            Assert.Throws <ZeroMqXtSocketException>(setupResponderActionThatThrows);
        }
示例#5
0
        public async Task Subscriber_Cancellation_works()
        {
            // Arrange
            var  socket      = Zer0Mq.Go().SilenceLogger().BuildWithInProc(Guid.NewGuid().ToString() + "-Subscriber-cancellation");
            bool wasReceived = false;
            var  tokenSource = new CancellationTokenSource();
            var  token       = tokenSource.Token;

            tokenSource.Cancel();
            socket.RegisterSubscriber <Message>(msg => wasReceived = true, token);

            // Act
            await socket.PublishAsync <Message>(new Message());

            // Assert
            Assert.False(wasReceived);
        }
示例#6
0
        public void Multiple_Socket_instances_and_multiple_responders_on_same_configuration_and_address_throws()
        {
            const string          inpipeThrows   = "send-pipe-throws";
            Func <IZer0MqBuilder> builderFactory = () => Zer0Mq.Go().SilenceLogger();

            // Arrange
            using var socket = builderFactory().BuildWithInProc(inpipeThrows);
            socket.Receiver <Message>((r) => { });

            // Act
            using var socket2 = builderFactory().BuildWithInProc(inpipeThrows);
            Action throwingAction = () => socket2.Respond <Message, Message>((r) => r);

            using var socket3 = builderFactory().BuildWithInProc(inpipeThrows);
            Action throwingAction2 = () => socket2.Receiver <Message>((r) => { });

            // Assert
            Assert.Throws <ZeroMqXtSocketException>(throwingAction);
            Assert.Throws <ZeroMqXtSocketException>(throwingAction2);
        }
示例#7
0
        internal static Task Contest(SocketConfiguration _)
        {
            using var socket = Zer0Mq.Go().BuildWithInProc("contestion");
            socket.Respond <Request, Response>(rq => new Response {
                InsideResponse = "first-server"
            });
            try
            {
                var socket2 = Zer0Mq.Go().BuildWithInProc("contestion");
                socket2.Respond <Request, Response>(rq => new Response {
                    InsideResponse = "second-server"
                });
            }
            catch (ZeroMqXtSocketException socketException)
            {
                System.Console.WriteLine("expected exception was thrown: " + socketException.ToString());
                return(Task.CompletedTask);
            }

            throw new InvalidOperationException("Socketexception (AdressAlready In Use) expected");
        }
示例#8
0
 public static ISocket BuildInprocSocketInstanceForTest(string pipeName)
 {
     return(Zer0Mq.Go().SilenceLogger().BuildWithInProc(pipeName));
 }
示例#9
0
 internal static ISocket BuildInProcSocketInstanceForTest(string pipeName)
 => Zer0Mq.Go().SilenceLogger().BuildWithInProc(pipeName);