Construction of Elasticsearch cluster pressure test case for Httptest4net

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.