public async Task cache_many_requests() { using (var inputWriter = new QueueWriter(cacheInputFormatName)) using (var rr = new RequestReply(cacheInputFormatName, replyFormatName, postman)) { var cachedMsg = new Message { Label = "some.value.1", AppSpecific = 1 }; await inputWriter.DeliverAsync(cachedMsg, postman, QueueTransaction.None); var cachedMsg2 = new Message { Label = "some.value.2", AppSpecific = 2 }; await inputWriter.DeliverAsync(cachedMsg2, postman, QueueTransaction.None); var sw = new Stopwatch(); for (int j = 0; j < 5; j++) { for (int i = 1; i <= 2; i++) { sw.Restart(); var request = new Message { Label = "cache.some.value." + i }; var reply = await rr.SendRequestAsync(request); Console.WriteLine($"took {sw.Elapsed.TotalMilliseconds:N1}MS"); Assert.AreEqual("some.value." + i, reply.Label, "Label"); Assert.AreEqual(i, reply.AppSpecific, "AppSpecific"); } } } }
public async Task cache_returns_empty_message_when_label_not_in_cache() { using (var rr = new RequestReply(cacheInputFormatName, replyFormatName, postman)) { var msg = new Message { Label = "cache.some.value" }; var sw = new Stopwatch(); sw.Start(); var reply = await rr.SendRequestAsync(msg); Console.WriteLine($"took {sw.ElapsedMilliseconds:N0}MS"); Assert.AreEqual(null, reply.Body, "Body"); Assert.AreEqual("some.value", reply.Label, "Label"); } }
public async Task can_get_reply_async() { var key = Environment.TickCount; var serverTask = Task.Run(() => Server(1)); using (var rr = new RequestReply(requestQueueFormatName, replyQueueFormatName, postman)) { var sw = new Stopwatch(); sw.Start(); var request = new Message { Label = "my.sq", AppSpecific = key }; var reply = await rr.SendRequestAsync(request); Assert.AreEqual(request.Label, reply?.Label); Assert.AreEqual(request.AppSpecific, reply?.AppSpecific); sw.Stop(); Console.WriteLine($"took {sw.ElapsedMilliseconds:N0}ms"); } }
public async Task cache_returns_message_stored_for_label() { using (var inputWriter = new QueueWriter(cacheInputFormatName)) using (var rr = new RequestReply(cacheInputFormatName, replyFormatName, postman)) { var cachedMsg = new Message { Label = "some.value", AppSpecific = 234 }; cachedMsg.BodyASCII("hello world!"); await inputWriter.DeliverAsync(cachedMsg, postman, QueueTransaction.None); var request = new Message { Label = "cache.some.value" }; var sw = new Stopwatch(); sw.Start(); var reply = await rr.SendRequestAsync(request); Console.WriteLine($"took {sw.ElapsedMilliseconds:N0}MS"); Assert.AreEqual(cachedMsg.Label, reply.Label, "Label"); Assert.AreEqual(cachedMsg.AppSpecific, reply.AppSpecific, "AppSpecific"); Assert.AreEqual("hello world!", reply.BodyASCII(), "Body"); } }