Httptest4net is a tool that can customize HTTP stress testing, and users can write test cases to load into httptest4net and run tests according to their own circumstances. Because of the recent need to test the Elasticsearch search cluster in a different situation, a simple test case was written for the test.
Code
[Test ("ES base")] public class Es_searchurltester:iurltester {public Es_searchurltester () { } public string Url {get; Set } static string[] urls = new string[] {"Http://192.168.20.156:9200/gindex/gindex/_search", "Http://192.168.20.158:9200/gindex/gindex/_search", "Http://192.168.20.160:9200/gindex/gindex/_search"}; private static Long Mindex = 0; private static list<string> mwords; protected static ilist<string> Words () {if (mwords = = null) {Lock (Typ EOF (Es_searchurltester)) {if (mwords = = null) { Mwords = new list<string> (); using (System.IO.StreamReader reader = new StreamReader (@ "D:\main.dic")) { String line; while (line = reader. ReadLine ()) = null) {Mwords.add (line); }}}}} return mwords; }/* {"query": {"bool": {"should": [{"field": {"title": "#key"}}, { "Field": {"kw": "#key"}}]}},from:0,size:10} */private static string Getsearchurl Word () {ilist<string> words= words (); System.Threading.Interlocked.Increment (ref Mindex); Return Resource1.QueryString.Replace ("#key", words[(int) (mindex% words. Count)]); } public System.Net.HttpWebRequest Createrequest () {var HttpWebRequest = (HttpWebRequest) webrequ Est. Create (Urls[mindex%urls. Length]); Httpwebrequest.contenttype = "Application/json"; Httpwebrequest.keepalIve = false; Httpwebrequest.method = "POST"; String json = Getsearchurlword (); using (var streamWriter = new StreamWriter (Httpwebrequest.getrequeststream ())) {STREAMWRITER.WR ITE (JSON); StreamWriter.Flush (); } return HttpWebRequest; } public Testtype Type {get {return testtype.post; } } }
The use case is simple to build URLs and JSON packets of different requests based on nodes and keywords. This use case can be loaded and tested by compiling the above code behind the DLL and putting it into the httptest4net run directory.
Test situation
Personal Station: www.ikende.com
Personal Open source project Github.com/ikende
Elastic communication component for. Net
Construction of Elasticsearch cluster pressure test case for Httptest4net