public void ContainerHostRequestProcessorTest() { string name = MethodInfo.GetCurrentMethod().Name; var processor = new TestRequestProcessor(); this.host.RegisterRequestProcessor(name, processor); int count = 500; var connection = new Connection(Address); var session = new Session(connection); string replyTo = "client-reply-to"; Attach recvAttach = new Attach() { Source = new Source() { Address = name }, Target = new Target() { Address = replyTo } }; var doneEvent = new ManualResetEvent(false); List<string> responses = new List<string>(); ReceiverLink receiver = new ReceiverLink(session, "request-client-receiver", recvAttach, null); receiver.Start( 20, (link, message) => { responses.Add(message.GetBody<string>()); link.Accept(message); if (responses.Count == count) { doneEvent.Set(); } }); SenderLink sender = new SenderLink(session, "request-client-sender", name); for (int i = 0; i < count; i++) { Message request = new Message("Hello"); request.Properties = new Properties() { MessageId = "request" + i, ReplyTo = replyTo }; sender.Send(request, SendTimeout); } Assert.IsTrue(doneEvent.WaitOne(10000), "Not completed in time"); receiver.Close(); sender.Close(); session.Close(); connection.Close(); Assert.AreEqual(count, processor.TotalCount); Assert.AreEqual(count, responses.Count); for (int i = 1; i <= count; i++) { Assert.AreEqual("OK" + i, responses[i - 1]); } }
public void ContainerHostRequestProcessorTest() { string name = MethodInfo.GetCurrentMethod().Name; var processor = new TestRequestProcessor(); this.host.RegisterRequestProcessor(name, processor); int count = 500; var connection = new Connection(Address); var session = new Session(connection); string replyTo = "client-reply-to"; Attach recvAttach = new Attach() { Source = new Source() { Address = name }, Target = new Target() { Address = replyTo } }; var doneEvent = new ManualResetEvent(false); List <string> responses = new List <string>(); ReceiverLink receiver = new ReceiverLink(session, "request-client-receiver", recvAttach, null); receiver.Start( 20, (link, message) => { responses.Add(message.GetBody <string>()); link.Accept(message); if (responses.Count == count) { doneEvent.Set(); } }); SenderLink sender = new SenderLink(session, "request-client-sender", name); for (int i = 0; i < count; i++) { Message request = new Message("Hello"); request.Properties = new Properties() { MessageId = "request" + i, ReplyTo = replyTo }; sender.Send(request, SendTimeout); } Assert.IsTrue(doneEvent.WaitOne(10000), "Not completed in time"); receiver.Close(); sender.Close(); session.Close(); connection.Close(); Assert.AreEqual(count, processor.TotalCount); Assert.AreEqual(count, responses.Count); for (int i = 1; i <= count; i++) { Assert.AreEqual("OK" + i, responses[i - 1]); } }