static void Main(string[] arguments) { const string address = "tcp://localhost:5555"; //const string service_name = "echo"; SetParameter(arguments); Console.WriteLine("[TitanicClient] Staring Titanic Client\n"); Console.WriteLine("[TitanicClient] {0} / #{1} Messages\n\n", s_verbose ? "verbose" : "silent", s_runs); // wait to allow MDP/Titanic Broker to complete start up Thread.Sleep(500); using (ITitanicClient client = new TitanicClient(address)) { if (s_verbose) { client.LogInfoReady += (s, e) => Console.WriteLine(e.Info); } for (var i = 0; i < s_runs; i++) { Console.WriteLine("[TitanicClient] Loop #{0} entered ...", i); var data = "ERROR! NO REPLY"; // does 5 retries to get the reply var reply = client.GetResult("echo", "Hallo World", 5); if (reply == null) { Console.WriteLine("\t[TitanicClient] ran into a problem, received 'null' in loop #{0}", i); continue; } data = reply.Item1 != null?Encoding.UTF8.GetString(reply.Item1) : data; if (data != "Hallo World") { Console.WriteLine("\t[TitanicClient] Hallo World != {0} on loop #{1} with status {2}", data, i, reply.Item2); } if (!ReferenceEquals(reply.Item1, null) && reply.Item2 == TitanicReturnCode.Ok) { Console.WriteLine("\t[TitanicClient] Status = {0} - Reply = {1}", reply.Item2, data); } } } Console.WriteLine("\n[TitanicClient] To exit press any key!"); Console.ReadKey(); }
public void GetResult_StringString_ShouldReturnExpectedResult() { const string expected_phrase = "Thank God Its Friday"; var replyFrame = new NetMQFrame(expected_phrase); var fakeMDPClient = new MDPTestClientForTitanicClient { ReplyDataFrame = replyFrame }; var sut = new TitanicClient(fakeMDPClient); var result = sut.GetResult("echo", expected_phrase); result.Item2.Should().Be(TitanicReturnCode.Ok); result.Item1.Should().BeSameAs(replyFrame.Buffer); }
public void GetResult_StringIntegerGeneric_ReturnExpectedResult() { var expected = new TestEntity(); var replyFrame = new NetMQFrame(expected.ConvertToBytes()); var fakeMDPClient = new MDPTestClientForTitanicClient { ReplyDataFrame = replyFrame }; var sut = new TitanicClient(fakeMDPClient); var result = sut.GetResult <TestEntity, TestEntity> ("echo", expected); result.Item2.Should().Be(TitanicReturnCode.Ok); result.Item1.Id.Should().Be(expected.Id); result.Item1.Name.Should().Be(expected.Name); }
private static void Main (string[] arguments) { const string address = "tcp://localhost:5555"; //const string service_name = "echo"; SetParameter (arguments); Console.WriteLine ("[TitanicClient] Staring Titanic Client\n"); Console.WriteLine ("[TitanicClient] {0} / #{1} Messages\n\n", s_verbose ? "verbose" : "silent", s_runs); // wait to allow MDP/Titanic Broker to complete start up Thread.Sleep (500); using (ITitanicClient client = new TitanicClient (address)) { if (s_verbose) client.LogInfoReady += (s, e) => Console.WriteLine (e.Info); for (var i = 0; i < s_runs; i++) { Console.WriteLine ("[TitanicClient] Loop #{0} entered ...", i); var data = "ERROR! NO REPLY"; // does 5 retries to get the reply var reply = client.GetResult ("echo", "Hallo World", 5); if (reply == null) { Console.WriteLine ("\t[TitanicClient] ran into a problem, received 'null' in loop #{0}", i); continue; } data = reply.Item1 != null ? Encoding.UTF8.GetString (reply.Item1) : data; if (data != "Hallo World") Console.WriteLine ("\t[TitanicClient] Hallo World != {0} on loop #{1} with status {2}", data, i, reply.Item2); if (!ReferenceEquals (reply.Item1, null) && reply.Item2 == TitanicReturnCode.Ok) Console.WriteLine ("\t[TitanicClient] Status = {0} - Reply = {1}", reply.Item2, data); } } Console.WriteLine ("\n[TitanicClient] To exit press any key!"); Console.ReadKey (); }
public void GetResult_StringIntegerGeneric_ReturnExpectedResult () { var expected = new TestEntity (); var replyFrame = new NetMQFrame (expected.ConvertToBytes ()); var fakeMDPClient = new MDPTestClientForTitanicClient { ReplyDataFrame = replyFrame }; var sut = new TitanicClient (fakeMDPClient); var result = sut.GetResult<TestEntity, TestEntity> ("echo", expected); result.Item2.Should ().Be (TitanicReturnCode.Ok); result.Item1.Id.Should ().Be (expected.Id); result.Item1.Name.Should ().Be (expected.Name); }
public void GetResult_StringStringEncoding_ShouldReturnExpectedResult () { var enc = Encoding.Unicode; const string expected_phrase = "Thank God Its Friday"; var replyFrame = new NetMQFrame (enc.GetBytes (expected_phrase)); var fakeMDPClient = new MDPTestClientForTitanicClient { ReplyDataFrame = replyFrame }; var sut = new TitanicClient (fakeMDPClient); var result = sut.GetResult ("echo", expected_phrase, enc); result.Item2.Should ().Be (TitanicReturnCode.Ok); result.Item1.Should ().Be (enc.GetString (replyFrame.Buffer)); }