Created
February 3, 2016 10:29
-
-
Save jirkapenzes/bdb14af031d610b4dfbd to your computer and use it in GitHub Desktop.
Request sender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PerfRequest { | |
public static void main(String[] args) throws Exception { | |
int index = 0; | |
int numberOfErrors = 0; | |
while(index < 100000) | |
{ | |
URL url = new URL("http://localhost:8080"); | |
HttpURLConnection connection = (HttpURLConnection)url.openConnection(); | |
connection.setRequestMethod("GET"); | |
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"); | |
connection.connect(); | |
int code = connection.getResponseCode(); | |
if (code != 200) { | |
System.out.println("Error: Request[" + index + "]: returning code: " + code); | |
numberOfErrors++; | |
} | |
if (index % 100 == 0) { | |
System.out.println("Tested: " + index); | |
} | |
index++; | |
} | |
System.out.println("----------------"); | |
System.out.println("Total errors: " + numberOfErrors);; | |
System.out.println("Complete :)"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment