Beispiel #1
0
        public async Task messages_arent_sent_back_to_origin()
        {
            var myEvent = new MyEvent();
            var env=new EnvelopeFromClient()
            {
                From =Setup.TestEndpoint.Host,
                Messages = new IMessage[] {myEvent,new OtherEvent()}
            };

            EnvelopeToClient dest = null;
          
            await _sut.Route(env);

            await _transporter.DidNotReceiveWithAnyArgs().Send(null);

        }
        public Task Route(EnvelopeFromClient envelope)
        {
            var delivery = _state.GetEnvelopes(envelope)
                .Select(d =>
                {
                    var transporter = _config.Transporters.GetTransporter(d.To);
                    if (transporter == null)
                    {
                        this.LogError($"There is no transporter defined for {d.To}");
                        return TasksUtils.EmptyTask();
                    }
                    return Send(transporter,d);
                }).ToArray();

           return Task.WhenAll(delivery);
        }
Beispiel #3
0
        public EnvelopeToClient[] GetEnvelopes(EnvelopeFromClient envelope)
        {
            IEnumerable<KeyValuePair<EndpointId, string[]>> items= Items;
          
            return items
                    .Where(d => d.Key.Host != envelope.From)
                    .Select(kv =>
                        new EnvelopeToClient()
                        {
                            To = kv.Key,
                            Messages = FilterEndpointMessages(kv.Value, envelope.Messages).ToArray()
                        })
                    .Where(e => e.Messages.Any())
                    .ToArray();

        }
Beispiel #4
0
        public async Task routing_messages_for_each_endpoint()
        {
            var myEvent = new MyEvent();
            var env=new EnvelopeFromClient()
            {
                From ="some host",
                Messages = new IMessage[] {myEvent,new OtherEvent()}
            };

            EnvelopeToClient dest = null;
            await _transporter.Send(Arg.Do<EnvelopeToClient>(e => dest = e));

            await _sut.Route(env);

            dest.To.Should().Be(Setup.TestEndpoint);
            dest.Messages.ShouldAllBeEquivalentTo(new[] {myEvent});

        }
        /// <exception cref="CouldntSendMessagesException"></exception>
        public async Task SendMessages(EnvelopeFromClient envelope)
        {
            try
            {
                await _db.HandleTransientErrorsAsync(CancellationToken.None, (db, tok) =>

                    db.InsertAsync(new ClientToServerRow()
                    {
                        DataId = envelope.Id.ToString(),
                        Type = ClientMessageType.Envelope,
                        Data = envelope.Serialize().ToByteArray()
                    }, tok), wait: 200).ConfigureFalse();
            }
            catch (DbException ex)
            {
                throw new CouldntSendMessagesException(envelope,"Error adding to storage",ex);
            }
        }
 protected override void MarkAsHandled(EnvelopeFromClient envs)
 {
     _db.HandleTransientErrors(
         db => db.DeleteFrom<ClientToServerRow>(t => t.DataId==envs.Id.ToString() && t.Type==ClientMessageType.Envelope));
 }
 public CouldntSendMessagesException(EnvelopeFromClient from, string message, Exception inner) : base(message, inner)
 {
     From = @from;
 }
 protected override void MarkAsHandled(EnvelopeFromClient envs)
 {
     if (Handled!=null) throw new Exception("Already handled");
     Handled = envs;
 }
 protected abstract void MarkAsHandled(EnvelopeFromClient envs);
 public Task SendMessages(EnvelopeFromClient envelope) => TasksUtils.EmptyTask();
Beispiel #11
0
 protected abstract void MarkAsHandled(EnvelopeFromClient envs);
Beispiel #12
0
        public async Task if_transport_doesnt_exist_nothing_happens()
        {
            var env = new EnvelopeFromClient()
            {
                From = Setup.TestEndpoint.Host,
                Messages = new IMessage[] { new MyEvent(), new OtherEvent() }
            };
            _sut.ReceiveConfigurations(new [] {new EndpointMessagesConfig()
            {
                Endpoint = new EndpointId("other","local")
                ,MessageTypes = new [] {typeof(OtherEvent).AsMessageName()}
            } });

            await _sut.Route(env);
        }
Beispiel #13
0
 public async Task transporter_error_goes_to_err_queue()
 {
     var exception = new CouldntSendMessagesException(new EnvelopeToClient(), "", new Exception());
     _transporter.Send(Arg.Any<EnvelopeToClient>()).Throws(exception);
     var env = new EnvelopeFromClient()
     {
         From = "other",
         Messages = new IMessage[] { new MyEvent(), new OtherEvent() }
     };
     await _sut.Route(env);
     _err.Received(1).TransporterError(exception);
 }
Beispiel #14
0
 public CouldntSendMessagesException(EnvelopeFromClient from, string message, Exception inner) : base(message, inner)
 {
     From = @from;
 }
 public async Task send_receive_client_messages()
 {
     var envelope = new EnvelopeFromClient()
     {
         From = "local",
         Id = Guid.NewGuid(),
         Messages = Setup.Fixture.CreateMany<MyEvent>().ToArray()
     };
     await
         _clientToServer.SendMessages(envelope);
     _cfg.MessageNotifier.Start();
   await Task.Delay(100).ConfigureFalse();
     await _serverRoute.ReceivedWithAnyArgs(1).Route(null);
     _serverRoute.ReceivedCalls().First().GetArguments()[0].ShouldBeEquivalentTo(envelope);
   
 }
 public Task Route(EnvelopeFromClient envelope)
 {
     envelope.MustNotBeNull();
     Routed++;
     return Task.WhenAll();
 }