public void SetUp() { persistentConnection = MockRepository.GenerateStub<IPersistentConnection>(); var eventBus = MockRepository.GenerateStub<IEventBus>(); var configuration = new ConnectionConfiguration { Timeout = 1 }; var shutdownArgs = new ShutdownEventArgs( ShutdownInitiator.Peer, AmqpException.ConnectionClosed, "connection closed by peer"); var exception = new OperationInterruptedException(shutdownArgs); persistentConnection.Stub(x => x.CreateModel()).WhenCalled(x => { throw exception; }); var logger = MockRepository.GenerateStub<IEasyNetQLogger>(); persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus); }
public void SetUp() { persistentConnection = MockRepository.GenerateStub<IPersistentConnection>(); channel = MockRepository.GenerateStub<IModel>(); var eventBus = new EventBus(); var configuration = new ConnectionConfiguration(); var shutdownArgs = new ShutdownEventArgs( ShutdownInitiator.Peer, AmqpException.ConnectionClosed, "connection closed by peer"); var exception = new OperationInterruptedException(shutdownArgs); var first = true; persistentConnection.Stub(x => x.CreateModel()).WhenCalled(x => { if (first) { first = false; throw exception; } x.ReturnValue = channel; }); var logger = MockRepository.GenerateStub<IEasyNetQLogger>(); persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus); new Timer(_ => eventBus.Publish(new ConnectionCreatedEvent())).Change(10, Timeout.Infinite); persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct")); }
public void SetUp() { persistentConnection = MockRepository.GenerateStub<IPersistentConnection>(); channel = MockRepository.GenerateStub<IModel>(); var eventBus = new EventBus(); var configuration = new ConnectionConfiguration(); var shutdownArgs = new ShutdownEventArgs( ShutdownInitiator.Peer, AmqpException.ConnectionClosed, "connection closed by peer"); var exception = new OperationInterruptedException(shutdownArgs); persistentConnection.Stub(x => x.CreateModel()).Throw(exception).Repeat.Once(); persistentConnection.Stub(x => x.CreateModel()).Return(channel).Repeat.Any(); var logger = MockRepository.GenerateStub<IEasyNetQLogger>(); persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus); new Timer(_ => eventBus.Publish(new ConnectionCreatedEvent())).Change(10, Timeout.Infinite); persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct"),DateTime.UtcNow ); }
private static bool NeedRethrow(OperationInterruptedException exception) { try { var amqpException = AmqpExceptionGrammar.ParseExceptionString(exception.Message); return amqpException.Code != AmqpException.ConnectionClosed; } catch (ParseException) { return true; } }