// ======================================================================== // Copyright 2004-2008 Mort Bay Consulting Pty. Ltd. // ------------------------------------------------------------------------ // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ======================================================================== package org.mortbay.servlet; import java.io.IOException; import java.net.URL; import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import junit.framework.TestCase; import org.mortbay.jetty.Handler; import org.mortbay.jetty.LocalConnector; import org.mortbay.jetty.servlet.FilterHolder; import org.mortbay.jetty.testing.HttpTester; import org.mortbay.jetty.testing.ServletTester; import org.mortbay.log.Log; public class QoSFilterTest extends TestCase { private ServletTester _tester; private FakeCountDownLatch _doneRequests; private final int NUM_CONNECTIONS = 20; private final int NUM_LOOPS = 10; private final int MAX_QOS = 5; protected void setUp() throws Exception { _tester = new ServletTester(); _tester.setContextPath("/context"); _tester.addServlet(TestServlet.class, "/test"); TestServlet.__maxSleepers=0; TestServlet.__sleepers=0; _doneRequests = new FakeCountDownLatch(NUM_CONNECTIONS*NUM_LOOPS); _tester.start(); } protected void tearDown() throws Exception { _tester.stop(); } public void testNoFilter() throws Exception { for(int i = 0; i < NUM_CONNECTIONS; ++i ) { new Thread(new Worker(i)).start(); } _doneRequests.await(10); if (TestServlet.__maxSleepers<=MAX_QOS) Log.warn("TEST WAS NOT PARALLEL ENOUGH!"); assertTrue(TestServlet.__maxSleepers<=NUM_CONNECTIONS); } public void testBlockingQosFilter() throws Exception { FilterHolder holder = new FilterHolder(QoSFilter2.class); holder.setInitParameter(QoSFilter.MAX_REQUESTS_INIT_PARAM, ""+MAX_QOS); _tester.getContext().getServletHandler().addFilterWithMapping(holder,"/*",Handler.REQUEST); for(int i = 0; i < NUM_CONNECTIONS; ++i ) { new Thread(new Worker(i)).start(); } _doneRequests.await(10); if (TestServlet.__maxSleepers0 && System.currentTimeMillis()