public void TestClientServerWithProtoFormat() { ExampleHttpServer server = new ExampleHttpServer(new ExampleSearchImpl()); //obviously if this was a 'real' transport we would not use the server, rather the server would be listening, the client transmitting IHttpTransfer wire = server; ISearchService client = new SearchService(new ExampleClient(wire, "application/x-protobuf")); //now the client has a real, typed, interface to work with: SearchResponse result = client.Search(SearchRequest.CreateBuilder().AddCriteria("Test").Build()); Assert.AreEqual(1, result.ResultsCount); Assert.AreEqual("Test", result.ResultsList[0].Name); Assert.AreEqual("http://search.com", result.ResultsList[0].Url); //The test part of this, call the only other method result = client.RefineSearch( RefineSearchRequest.CreateBuilder().SetPreviousResults(result).AddCriteria("Refine").Build()); Assert.AreEqual(2, result.ResultsCount); Assert.AreEqual("Test", result.ResultsList[0].Name); Assert.AreEqual("http://search.com", result.ResultsList[0].Url); Assert.AreEqual("Refine", result.ResultsList[1].Name); Assert.AreEqual("http://refine.com", result.ResultsList[1].Url); }
public void InprocPerformanceTest() { using ( SearchService client = new SearchService(new InprocRpcClient(new SearchService.ServerStub(new AuthenticatedSearch())))) { SearchResponse previous = client.Search(SearchRequest.CreateBuilder() .AddCriteria("one").AddCriteria("two").AddCriteria("three"). Build()); RefineSearchRequest req = RefineSearchRequest.CreateBuilder() .AddCriteria("four").SetPreviousResults(previous).Build(); Stopwatch w = new Stopwatch(); w.Start(); for (int i = 0; i < 1000; i++) { client.RefineSearch(req); } w.Stop(); Trace.TraceInformation("Inproc Performance = {0}", w.ElapsedMilliseconds); } }
public void LrpcPerformanceTest() { Win32RpcServer.VerboseLogging = false; try { using (RpcServer.CreateRpc(iid, new SearchService.ServerStub(new AuthenticatedSearch())) .AddAuthNegotiate() .AddProtocol("ncalrpc", "lrpctest") .StartListening()) { using ( SearchService client = new SearchService( RpcClient.ConnectRpc(iid, "ncalrpc", null, "lrpctest").Authenticate( RpcAuthenticationType.Self))) { SearchResponse previous = client.Search(SearchRequest.CreateBuilder() .AddCriteria("one").AddCriteria("two").AddCriteria( "three").Build()); RefineSearchRequest req = RefineSearchRequest.CreateBuilder() .AddCriteria("four").SetPreviousResults(previous).Build(); Stopwatch w = new Stopwatch(); w.Start(); for (int i = 0; i < 1000; i++) { client.RefineSearch(req); } w.Stop(); Trace.TraceInformation("Lrpc Performance = {0}", w.ElapsedMilliseconds); } } } finally { Win32RpcServer.VerboseLogging = true; } }
public void TestClientServerWithCustomFormat() { ExampleHttpServer server = new ExampleHttpServer(new ExampleSearchImpl()); //Setup our custom mime-type format as the only format supported: server.Options.MimeInputTypes.Clear(); server.Options.MimeInputTypes.Add("foo/bar", CodedInputStream.CreateInstance); server.Options.MimeOutputTypes.Clear(); server.Options.MimeOutputTypes.Add("foo/bar", CodedOutputStream.CreateInstance); //obviously if this was a 'real' transport we would not use the server, rather the server would be listening, the client transmitting IHttpTransfer wire = server; ExampleClient exclient = new ExampleClient(wire, "foo/bar"); //Add our custom mime-type format exclient.Options.MimeInputTypes.Add("foo/bar", CodedInputStream.CreateInstance); exclient.Options.MimeOutputTypes.Add("foo/bar", CodedOutputStream.CreateInstance); ISearchService client = new SearchService(exclient); //now the client has a real, typed, interface to work with: SearchResponse result = client.Search(SearchRequest.CreateBuilder().AddCriteria("Test").Build()); Assert.AreEqual(1, result.ResultsCount); Assert.AreEqual("Test", result.ResultsList[0].Name); Assert.AreEqual("http://search.com", result.ResultsList[0].Url); //The test part of this, call the only other method result = client.RefineSearch( RefineSearchRequest.CreateBuilder().SetPreviousResults(result).AddCriteria("Refine").Build()); Assert.AreEqual(2, result.ResultsCount); Assert.AreEqual("Test", result.ResultsList[0].Name); Assert.AreEqual("http://search.com", result.ResultsList[0].Url); Assert.AreEqual("Refine", result.ResultsList[1].Name); Assert.AreEqual("http://refine.com", result.ResultsList[1].Url); }