Search in sources :

Example 1 with SlowServlet

use of org.apache.hyracks.http.servlet.SlowServlet in project asterixdb by apache.

the class HttpServerTest method testOverloadingServer.

@Test
public void testOverloadingServer() throws Exception {
    WebManager webMgr = new WebManager();
    HttpServer server = new HttpServer(webMgr.getBosses(), webMgr.getWorkers(), PORT, NUM_EXECUTOR_THREADS, SERVER_QUEUE_SIZE);
    SlowServlet servlet = new SlowServlet(server.ctx(), new String[] { PATH });
    server.addServlet(servlet);
    webMgr.add(server);
    webMgr.start();
    try {
        request(NUM_OF_REQUESTS);
        for (Thread thread : THREADS) {
            thread.join();
        }
        Assert.assertEquals(32, SUCCESS_COUNT.get());
        Assert.assertEquals(16, UNAVAILABLE_COUNT.get());
        Assert.assertEquals(0, OTHER_COUNT.get());
    } finally {
        webMgr.stop();
    }
}
Also used : SlowServlet(org.apache.hyracks.http.servlet.SlowServlet) WebManager(org.apache.hyracks.http.server.WebManager) HttpServer(org.apache.hyracks.http.server.HttpServer) Test(org.junit.Test)

Example 2 with SlowServlet

use of org.apache.hyracks.http.servlet.SlowServlet in project asterixdb by apache.

the class HttpServerTest method testMalformedString.

@Test
public void testMalformedString() throws Exception {
    WebManager webMgr = new WebManager();
    HttpServer server = new HttpServer(webMgr.getBosses(), webMgr.getWorkers(), PORT, NUM_EXECUTOR_THREADS, SERVER_QUEUE_SIZE);
    SlowServlet servlet = new SlowServlet(server.ctx(), new String[] { PATH });
    server.addServlet(servlet);
    webMgr.add(server);
    webMgr.start();
    try {
        StringBuilder response = new StringBuilder();
        try (Socket s = new Socket(InetAddress.getLocalHost(), PORT)) {
            PrintWriter pw = new PrintWriter(s.getOutputStream());
            pw.println("GET /?handle=%7B%22handle%22%3A%5B0%2C%200%5D%7 HTTP/1.1");
            pw.println("Host: 127.0.0.1");
            pw.println();
            pw.flush();
            BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
            String line;
            while ((line = br.readLine()) != null) {
                response.append(line).append('\n');
            }
            br.close();
        }
        String output = response.toString();
        Assert.assertTrue(output.contains(HttpResponseStatus.BAD_REQUEST.toString()));
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    } finally {
        webMgr.stop();
    }
}
Also used : SlowServlet(org.apache.hyracks.http.servlet.SlowServlet) WebManager(org.apache.hyracks.http.server.WebManager) InputStreamReader(java.io.InputStreamReader) HttpServer(org.apache.hyracks.http.server.HttpServer) BufferedReader(java.io.BufferedReader) Socket(java.net.Socket) URISyntaxException(java.net.URISyntaxException) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

HttpServer (org.apache.hyracks.http.server.HttpServer)2 WebManager (org.apache.hyracks.http.server.WebManager)2 SlowServlet (org.apache.hyracks.http.servlet.SlowServlet)2 Test (org.junit.Test)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 Socket (java.net.Socket)1 URISyntaxException (java.net.URISyntaxException)1