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); } }
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); }
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); }
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); }
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(); }
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(); }
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(); }
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); } }
public void ConstructorMessage() { BrokerException exception = new BrokerException("Message"); Assert.AreEqual("Message", exception.Message); }
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); } }