示例#1
0
        protected override void OnCommand(ITransport sender, Command command)
        {
            if (command.IsResponse)
            {
                Response       response      = (Response)command;
                int            correlationId = response.CorrelationId;
                FutureResponse future        = (FutureResponse)requestMap[correlationId];

                if (future != null)
                {
                    requestMap.Remove(correlationId);
                    future.Response = response;

                    if (response is ExceptionResponse)
                    {
                        ExceptionResponse er          = response as ExceptionResponse;
                        BrokerError       brokerError = er.Exception;
                        BrokerException   exception   = new BrokerException(brokerError);
                        this.exceptionHandler(this, exception);
                    }
                }
                else
                {
                    if (Tracer.IsDebugEnabled)
                    {
                        Tracer.Debug("Unknown response ID: " + response.CommandId + " for response: " + response);
                    }
                }
            }
            else
            {
                this.commandHandler(sender, command);
            }
        }
示例#2
0
        protected override void OnCommand(ITransport sender, ICommand command)
        {
            if (command is Response)
            {
                var response      = (Response)command;
                var correlationId = response.CorrelationId;
                var future        = (FutureResponse)_requestMap[correlationId];

                if (future != null)
                {
                    _requestMap.Remove(correlationId);
                    future.Response = response;

                    if (!(response is ExceptionResponse))
                    {
                        return;
                    }
                    var er          = response as ExceptionResponse;
                    var brokerError = er.Exception;
                    var exception   = new BrokerException(brokerError);
                    Exception(this, exception);
                }
                else
                {
                    Tracer.Warn("Unknown response ID: " + response.CommandId + " for response: " + response);
                }
            }
            else
            {
                Command(sender, command);
            }
        }
        public void ShouldSerializeOffsetKafkaEndpointNull()
        {
            var expected = new BrokerException("a", null);
            var actual   = SerializeDeserialize(expected);

            Assert.AreEqual(expected.BrokerEndPoint, actual.BrokerEndPoint);
        }
示例#4
0
        protected override void OnCommand(ITransport sender, ICommand command)
        {
            if (command is Response)
            {
                var response      = (Response)command;
                var correlationId = response.CorrelationId;

                if (_requestMap.TryGetValue(correlationId, out FutureResponse future))
                {
                    if (!_requestMap.TryRemove(correlationId, out FutureResponse _))
                    {
                        Tracer.Warn($"Failed to remove future response with id: '{correlationId}'.");
                    }

                    future.Response = response;

                    if (!(response is ExceptionResponse))
                    {
                        return;
                    }
                    var er          = response as ExceptionResponse;
                    var brokerError = er.Exception;
                    var exception   = new BrokerException(brokerError);
                    Exception(this, exception);
                }
                else
                {
                    Tracer.Warn("Unknown response ID: " + response.CommandId + " for response: " + response);
                }
            }
            else
            {
                Command(sender, command);
            }
        }
 protected override void OnCommand(ITransport sender, Command command)
 {
     if (command is Response)
     {
         Response       response = (Response)command;
         FutureResponse future   = (FutureResponse)requestMap[response.CorrelationId];
         if (future != null)
         {
             if (response is ExceptionResponse)
             {
                 ExceptionResponse er          = (ExceptionResponse)response;
                 BrokerError       brokerError = er.Exception;
                 BrokerException   exception   = new BrokerException(brokerError);
                 this.exceptionHandler(this, exception);
             }
             future.Response = response;
         }
         else
         {
             if (command is ShutdownInfo)
             {
                 // lets shutdown
                 this.commandHandler(sender, command);
             }
             else
             {
                 Tracer.Error("Unknown response ID: " + response.CommandId + " for response: " + response);
             }
         }
     }
     else
     {
         this.commandHandler(sender, command);
     }
 }
        public void ShouldSerializeOffsetKafkaEndpointInnerObjectAreNull()
        {
            var expected = new BrokerException("a", new KafkaEndpoint());
            var actual   = SerializeDeserialize(expected);

            Assert.AreEqual(expected.BrokerEndPoint.ServeUri, actual.BrokerEndPoint.ServeUri);
            Assert.AreEqual(expected.BrokerEndPoint.Endpoint, actual.BrokerEndPoint.Endpoint);
        }
示例#7
0
        public void ConstructorInner()
        {
            Exception       e         = new Exception();
            BrokerException exception = new BrokerException("Message", e);

            Assert.AreEqual("Message", exception.Message);
            Assert.AreEqual(e, exception.InnerException);
        }
        public void ShouldSerializeOffsetKafkaEndpoint()
        {
            var expected = new BrokerException("a", new KafkaEndpoint()
            {
                Endpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8888), ServeUri = new Uri("http://S1.com")
            });
            var actual = SerializeDeserialize(expected);

            Assert.AreEqual(expected.BrokerEndPoint.ServeUri, actual.BrokerEndPoint.ServeUri);
            Assert.AreEqual(expected.BrokerEndPoint.Endpoint, actual.BrokerEndPoint.Endpoint);
        }
示例#9
0
        protected override void OnCommand(ITransport sender, ICommand command)
        {
            if (command is Response response)
            {
                var correlationId = response.CorrelationId;

                if (_requestMap.TryGetValue(correlationId, out var future))
                {
                    if (!_requestMap.TryRemove(correlationId, out _) && Tracer.IsWarnEnabled)
                    {
                        Tracer.Warn($"Failed to remove future response with id: '{correlationId}'.");
                    }

                    future.Response = response;

                    if (!(response is ExceptionResponse))
                    {
                        return;
                    }

                    var er = response as ExceptionResponse;
                    if (Tracer.IsErrorEnabled)
                    {
                        Tracer.Error($"Response is exception response, exception: {er.Exception} ({er.Exception.Message})");
                    }

                    var brokerError = er.Exception;
                    var exception   = new BrokerException(brokerError);
                    Exception(this, exception);
                }
                else
                {
                    if (Tracer.IsWarnEnabled)
                    {
                        Tracer.Warn($"Unknown response ID: {response.CommandId} for response: {response}");
                    }
                    if (!(response is ExceptionResponse exResponse))
                    {
                        return;
                    }

                    if (Tracer.IsErrorEnabled)
                    {
                        Tracer.Error($"Response is exception response, exception: {exResponse.Exception} ({exResponse.Exception.Message})");
                    }
                    var exception = new BrokerException(exResponse.Exception);
                    Exception(this, exception);
                }
            }
            else
            {
                Command(sender, command);
            }
        }
        protected override async Task HandleErrorsAsync(HttpResponseMessage response)
        {
            if (response.StatusCode == HttpStatusCode.Gone)
            {
                var error = await response.Content.ReadAsAsync <Error>(new[] { Serializer });

                if (error != null)
                {
                    throw BrokerException.FromResponse(error, response.StatusCode);
                }
            }

            response.EnsureSuccessStatusCode();
        }
示例#11
0
        public async Task HandleAsync(HttpResponseMessage response)
        {
            if (response.IsSuccessStatusCode)
            {
                return;
            }

            var error = await GetErrorAsync(response);

            if (error != null)
            {
                throw BrokerException.FromResponse(error, response.StatusCode);
            }

            response.EnsureSuccessStatusCode();
        }
示例#12
0
        public void ConstructorDeserialize()
        {
            BrokerException exception = new BrokerException("Message");
            BinaryFormatter formatter = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.All));

            byte[] buffer = null;
            using (MemoryStream ms = new MemoryStream()) {
                formatter.Serialize(ms, exception);
                buffer = ms.ToArray();
            }

            BrokerException deserializeException = null;

            using (MemoryStream ms = new MemoryStream(buffer)) {
                deserializeException = (BrokerException)formatter.Deserialize(ms);
            }

            Assert.AreEqual("Message", deserializeException.Message);
        }
        public async Task HandleAsync(HttpResponseMessage response)
        {
            if (response.Content != null)
            {
                Error error = null;
                try
                {
                    error = await response.Content.ReadAsAsync <Error>(new[] { Serializer });
                }
                catch
                {
                    // Error responses without a response in standard format will be handled below
                }
                if (error != null)
                {
                    throw BrokerException.FromResponse(error, response.StatusCode);
                }
            }

            response.EnsureSuccessStatusCode();
        }
        protected override async Task HandleErrorsAsync(HttpResponseMessage response)
        {
            if (!response.IsSuccessStatusCode && response.Content != null)
            {
                Error error = null;
                try
                {
                    error = await FromContentAsync <Error>(response);
                }
                catch
                {
                    // Error responses without a response in standard format will be handled below
                }
                if (error != null)
                {
                    throw BrokerException.FromResponse(error, response.StatusCode);
                }
            }

            response.EnsureSuccessStatusCode();
        }
示例#15
0
 public void ConstructorDefault()
 {
     BrokerException exception = new BrokerException();
 }
        protected override void OnCommand(ITransport sender, Command command)
        {
            if( command is Response ) {

                Response response = (Response) command;
                FutureResponse future = (FutureResponse) requestMap[response.CorrelationId];
                if (future != null)
                {
                    if (response is ExceptionResponse)
                    {
                        ExceptionResponse er = (ExceptionResponse) response;
                        BrokerError brokerError = er.Exception;
                        BrokerException exception = new BrokerException(brokerError);
                        this.exceptionHandler(this, exception);
                    }
                    future.Response = response;
                }
                else
                {
                    if (command is ShutdownInfo)
                    {
                        // lets shutdown
                        this.commandHandler(sender, command);
                    }
                    else {
                        Tracer.Error("Unknown response ID: " + response.CommandId + " for response: " + response);
                    }
                }
            } else {
                this.commandHandler(sender, command);
            }
        }
示例#17
0
        public void ConstructorMessage()
        {
            BrokerException exception = new BrokerException("Message");

            Assert.AreEqual("Message", exception.Message);
        }
示例#18
0
        protected override void OnCommand(ITransport sender, Command command)
        {
            if(command.IsResponse)
            {
                Response response = (Response) command;
                int correlationId = response.CorrelationId;
                FutureResponse future = (FutureResponse) requestMap[correlationId];

                if(future != null)
                {
                    requestMap.Remove(correlationId);
                    future.Response = response;

                    if(response is ExceptionResponse)
                    {
                        ExceptionResponse er = response as ExceptionResponse;
                        BrokerError brokerError = er.Exception;
                        BrokerException exception = new BrokerException(brokerError);
                        this.exceptionHandler(this, exception);
                    }
                }
                else
                {
                    if(Tracer.IsDebugEnabled)
                    {
                        Tracer.Debug("Unknown response ID: " + response.CommandId + " for response: " + response);
                    }
                }
            }
            else
            {
                this.commandHandler(sender, command);
            }
        }