public void StopConsumingShouldNotLogWarnWhenAlreadyClosedConnectionTest() { var model = new Mock <IModel>(); var consumer = new Mock <IConsumer>(); var actor = new Mock <IActorRef>(); var logger = new Mock <ILog>(); consumer.SetupGet(c => c.Id).Returns("Consumer1Id"); var test = new StreamSubscriber(model.Object, consumer.Object, actor.Object); var loggerField = test.GetType().GetField("_logger", BindingFlags.Instance | BindingFlags.NonPublic); loggerField.SetValue(test, logger.Object); model.Setup(x => x.BasicConsume("test", true, consumer.Object.Id, false, false, null, test)).Callback(() => { }); test.StartConsuming("test"); model.SetupGet(m => m.IsClosed).Returns(true); model.Setup(x => x.BasicCancel(consumer.Object.Id)).Callback(() => { throw new AlreadyClosedException( new ShutdownEventArgs(ShutdownInitiator.Application, 0, "Already closed")); }); test.StopConsuming(); logger.Verify( l => l.Warn(It.Is <string>( msg => msg.StartsWith($"Connection already closed for consumerId={consumer.Object.Id}"))), Times.Never, "Connection already closed warning should not be logged."); }
public void DoubleStopShouldNotCauseErrorTest() { var model = new Mock <IModel>(); var consumer = new Mock <IConsumer>(); var actor = new Mock <IActorRef>(); var test = new StreamSubscriber(model.Object, consumer.Object, actor.Object); model.Setup(x => x.BasicConsume("test", true, consumer.Object.Id, false, false, null, test)).Callback(() => { }); test.StartConsuming("test"); test.StopConsuming(); test.StopConsuming(); }
public void StopShouldsENDdIApatchesRemoveMessageTest() { var model = new Mock <IModel>(); var consumer = new Mock <IConsumer>(); var actor = new Mock <IActorRef>(); var test = new StreamSubscriber(model.Object, consumer.Object, actor.Object); model.Setup(x => x.BasicConsume("test", true, consumer.Object.Id, false, false, null, test)).Callback(() => { }); //test.IsDisposed.Should().Be(false); test.StartConsuming("test"); test.StopConsuming(); //TODO check RemoveSubscriberMessage }
public void StartConsumingTest() { var model = new Mock <IModel>(); var consumer = new Mock <IConsumer>(); var actor = new Mock <IActorRef>(); var test = new StreamSubscriber(model.Object, consumer.Object, actor.Object); int startConsume = 0; model.Setup(x => x.BasicConsume("test", true, consumer.Object.Id, false, false, null, test)).Callback(() => startConsume++); test.StartConsuming("test"); startConsume.Should().Be(1); }
private bool ProcessNewConsumer(IConsumer consumer) { Logger.LogDebug($"Method=ProcessNewConsumer triggered fixtureId={consumer?.Id} currentState={State.ToString()} connectionStatus={ConnectionStatus}"); var queue = consumer.GetQueueDetails(); Logger.LogDebug($"Method=ProcessNewConsumer queueName={queue?.Name}"); if (string.IsNullOrEmpty(queue?.Name)) { Logger.LogWarning($"Method=ProcessNewConsumer Invalid queue details, fixtureId={consumer?.Id}"); return(false); } if (!IsModelValid) { Logger.LogWarning($"Method=ProcessNewConsumer AMQP model not initialized, fixtureId={consumer?.Id}"); Self.Tell(new CreateModelMessage()); return(false); } StreamSubscriber subscriber = null; try { subscriber = new StreamSubscriber(Model, consumer, Dispatcher, LoggerFactory.CreateLogger <StreamSubscriber>()); subscriber.StartConsuming(queue.Name); } catch (Exception e) { ProcessNewConsumerErrorCounter++; Logger.LogWarning( $"Method=ProcessNewConsumer StartConsuming errored errorsCout={ProcessNewConsumerErrorCounter} for fixtureId={consumer.Id} {e}"); if (ProcessNewConsumerErrorCounter > NewConsumerErrorLimit) { ProcessNewConsumerErrorHandler(e); } return(false); } Logger.LogDebug($"Method=ProcessNewConsumer successfully executed fixtureId={consumer.Id}"); ProcessNewConsumerErrorCounter = 0; return(true); }
protected virtual void AddConsumerToQueue(IConsumer consumer) { if (consumer == null) { Logger.LogWarning("Method=AddConsumerToQueue Consumer is null"); return; } Logger.LogDebug($"Method=AddConsumerToQueue triggered fixtureId={consumer.Id}"); var queue = consumer.GetQueueDetails(); if (string.IsNullOrEmpty(queue?.Name)) { Logger.LogWarning("Method=AddConsumerToQueue Invalid queue details"); return; } if (StreamConnection == null) { Logger.LogWarning($"Method=AddConsumerToQueue StreamConnection is null currentState={State.ToString()}"); Self.Tell(new DisconnectedMessage { IDConnection = StreamConnection?.GetHashCode() }); Stash.Stash(); return; } if (!StreamConnection.IsOpen) { Logger.LogWarning($"Method=AddConsumerToQueue StreamConnection is closed currentState={State.ToString()}"); Self.Tell(new DisconnectedMessage { IDConnection = StreamConnection?.GetHashCode() }); Stash.Stash(); return; } if (!IsModelValid) { Logger.LogWarning($"Method=ProcessNewConsumer AMQP model not initialized, fixtureId={consumer?.Id}"); Self.Tell(new CreateModelMessage()); return; } StreamSubscriber subscriber = null; try { subscriber = new StreamSubscriber(Model, consumer, Dispatcher, LoggerFactory.CreateLogger <StreamSubscriber>()); subscriber.StartConsuming(queue.Name); Logger.LogDebug($"Consumer with id={consumer.Id} added to queueName={queue.Name}"); } catch (Exception e) { ProcessNewConsumerErrorCounter++; Logger.LogWarning($"Method=AddConsumerToQueue StartConsuming errored for fixtureId={consumer.Id} {e}"); if (ProcessNewConsumerErrorCounter > NewConsumerErrorLimit) { throw; } } Logger.LogDebug($"Method=AddConsumerToQueue successfully executed fixtureId={consumer.Id}"); }