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
1[Test ("ES Base")]2 Public classEs_searchurltester:iurltester3 {4 5 PublicEs_searchurltester ()6 {7 8 9 }Ten Public stringURL One { A Get; - Set; - } the - - 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" }; + A Private Static LongMindex =0; at - Private Staticlist<string>mwords; - - protected Staticilist<string>Words () - { - in if(Mwords = =NULL) - { to Lock(typeof(es_searchurltester)) + { - if(Mwords = =NULL) the { *Mwords =Newlist<string>(); $ using(System.IO.StreamReader reader =NewStreamReader (@"D:\main.dic"))Panax Notoginseng { - stringLine ; the + while(line = reader.) ReadLine ())! =NULL) A { the Mwords.add (line); + } - } $ } $ } - } - returnmwords; the } - /*Wuyi {"Query": the { - "bool": { Wu "should": [{ - "field": { About " title": "#key" $ } - }, { - "field": { - "kw": "#key" A } + } ] the } - }, $ from:0, the size:10 the } the */ the Private Static stringGetsearchurlword () - { inilist<string> words=Words (); theSystem.Threading.Interlocked.Increment (refmindex); the returnResource1.QueryString.Replace ("#key", words[(int) (Mindex%words. Count)]); About } the the PublicSystem.Net.HttpWebRequest createrequest () the { + varHttpWebRequest = (HttpWebRequest) webrequest.create (urls[mindex%URLs. Length]); -Httpwebrequest.contenttype ="Application/json"; theHttpwebrequest.keepalive =false;BayiHttpwebrequest.method ="POST"; the stringJSON =Getsearchurlword (); the using(varStreamWriter =NewStreamWriter (Httpwebrequest.getrequeststream ())) - { - the StreamWriter.Write (JSON); the StreamWriter.Flush (); the } the returnHttpWebRequest; - the } the the PublicTesttype Type94 { the Get the { the returnTesttype.post;98 } About } -}
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
Download httptest4net
Build Elasticsearch cluster Stress test cases for httptest4net