public void TestRedeliver() { using( var send = new TmMqSender( "TestRedeliver" ) ) { var msg = new TmMqMessage(); msg.Text = "msg1"; send.Send( msg ); } using( var recv = new TmMqReceiver( "TestRedeliver" ) ) { var count = recv.CountPending(); Assert.AreEqual( 1, count, "Should be one pending item" ); ITmMqMessage recieved = null; int retry = 0; using( var evt = new ManualResetEvent( false ) ) { recv.StartReceiving( 1, msg => { if( retry++ == 0 ) { throw new Exception( "fail " + retry ); } recieved = msg; evt.Set(); } ); evt.WaitOne( 5000 ); } Assert.IsNotNull( recieved ); Assert.AreEqual( "msg1", recieved.Text ); Assert.AreEqual( 1, recieved.Errors.Count, "An error should have been logged" ); } }
public void TestStartReceive() { using( var recv = new TmMqReceiver( "TestStartReceive" ) ) { ITmMqMessage recieved = null; using( var evt = new ManualResetEvent( false ) ) { using( var send = new TmMqSender( "TestStartReceive" ) ) { recv.StartReceiving( 1, m => { recieved = m; evt.Set(); } ); var msg = new TmMqMessage(); msg.Text = "msg1"; send.Send( msg ); } evt.WaitOne( 500 ); } Assert.IsNotNull( recieved ); Assert.AreEqual( "msg1", recieved.Text ); } }
public void TestErrorQueue() { using( var send = new TmMqSender( "TestErrorQueue" ) ) { var msg = new TmMqMessage(); msg.Text = "msg1 - fail"; send.Send( msg ); } using( var recv = new TmMqReceiver( "TestErrorQueue" ) ) { int fail = 0; using( var evt = new ManualResetEvent( false ) ) { recv.StartReceiving( 1, msg => { if( fail++ == 2 ) { evt.Set(); } throw new Exception( "fail " ); } ); evt.WaitOne( 5000 ); } } using( var recv = new TmMqReceiver( "error" ) ) { ITmMqMessage errorMsg = null; using( var evt = new ManualResetEvent( false ) ) { recv.StartReceiving( 1, msg => { errorMsg = msg; evt.Set(); } ); evt.WaitOne( 5000 ); } Assert.IsNotNull( errorMsg ); Assert.AreEqual( "msg1 - fail", errorMsg.Text ); Assert.AreEqual( "TestErrorQueue", errorMsg.OriginalQueue ); } }