Example usage for org.apache.commons.pool.impl GenericKeyedObjectPool setMinIdle

List of usage examples for org.apache.commons.pool.impl GenericKeyedObjectPool setMinIdle

Introduction

In this page you can find the example usage for org.apache.commons.pool.impl GenericKeyedObjectPool setMinIdle.

Prototype

public synchronized void setMinIdle(int poolSize) 

Source Link

Document

Sets the minimum number of idle objects to maintain in each of the keyed pools.

Usage

From source file:com.tasktop.c2c.server.common.service.tests.ajp.AjpProtocolTest.java

@Ignore
// This sometimes fails on the CI server
@Test//  w w w.  ja v  a2 s.c  o m
public void testMultipleSuccessiveGets() throws IOException {
    GenericKeyedObjectPool uniSocketPool = new GenericKeyedObjectPool(new AjpPoolableConnectionFactory());
    uniSocketPool.setLifo(true);
    uniSocketPool.setMaxIdle(1);
    uniSocketPool.setMaxTotal(1);
    uniSocketPool.setMinIdle(1);
    protocol.setSocketPool(uniSocketPool);
    final int numRequests = 50;
    for (int x = 0; x < numRequests; ++x) {
        System.out.println("request: " + x);
        Payload payload = new Payload();
        MockHttpServletRequest request = new MockHttpServletRequest() {
            @Override
            public int getContentLength() {
                return -1;
            }
        };

        payload.setResponseCode(HttpServletResponse.SC_OK);
        payload.setBinaryContent(createData((x + 3) * 512));
        payload.setCharacterContent("some content " + x);
        payload.getResponseHeaders().put("foo", "bar");
        TestServlet.setResponsePayload(payload);

        request.setMethod("GET");
        request.setRequestURI("/testGet" + x);
        request.addHeader("Content-Type", "text/plain");

        MockHttpServletResponse response = new MockHttpServletResponse();
        protocol.forward(request, response);

        assertRequestIsExpected(request, TestServlet.getLastRequest());
        assertResponseIsExpected(payload, response);
    }
}

From source file:com.tasktop.c2c.server.common.service.tests.ajp.AjpProtocolTest.java

@Test
public void testMultipleSuccessiveRequestsOnOneConnection() throws IOException {
    GenericKeyedObjectPool uniSocketPool = new GenericKeyedObjectPool(new AjpPoolableConnectionFactory());
    uniSocketPool.setLifo(true);// www .  j  a  v  a  2 s . c  o  m
    uniSocketPool.setMaxIdle(1);
    uniSocketPool.setMaxTotal(1);
    uniSocketPool.setMinIdle(1);
    protocol.setSocketPool(uniSocketPool);
    final int numRequests = 50;
    for (int x = 0; x < numRequests; ++x) {
        System.out.println("request: " + x);
        Payload payload = new Payload();
        MockHttpServletRequest request = new MockHttpServletRequest();
        if (x % 3 == 0) {
            payload.setResponseCode(HttpServletResponse.SC_CREATED);
            payload.setCharacterContent("some content " + x);
            payload.getResponseHeaders().put("foo", "bar");
            TestServlet.setResponsePayload(payload);

            String formContent = "a=b&c=def";
            byte[] requestContent = formContent.getBytes();

            request.setMethod("PUT");
            request.setRequestURI("/testPostData" + x);
            request.addHeader("Content-Type", "application/x-www-form-urlencoded");
            request.addHeader("Content-Length", requestContent.length);
            request.setContent(requestContent);
        } else {
            payload.setResponseCode(HttpServletResponse.SC_OK);
            payload.setBinaryContent(createData((x * 1024) + 3));
            payload.getResponseHeaders().put("Content-Length",
                    Integer.toString(payload.getBinaryContent().length));
            payload.getResponseHeaders().put("Content-Type", "unknown");
            payload.getResponseHeaders().put("TestPayloadNumber",
                    Integer.toHexString(x) + '/' + Integer.toHexString(numRequests));
            TestServlet.setResponsePayload(payload);

            request.setMethod("GET");
            request.setRequestURI("/test" + x);
        }

        MockHttpServletResponse response = new MockHttpServletResponse();
        protocol.forward(request, response);

        assertRequestIsExpected(request, TestServlet.getLastRequest());
        assertResponseIsExpected(payload, response);
    }
}

From source file:com.tasktop.c2c.server.common.service.tests.ajp.AjpProtocolTest.java

@Test
// Trying to recreate task 718
public void testGetThenPost() throws Exception {
    final byte[] POST_REQUEST_PAYLOAD = createData(431);

    GenericKeyedObjectPool uniSocketPool = new GenericKeyedObjectPool(new AjpPoolableConnectionFactory());
    uniSocketPool.setLifo(true);/*from  w w w.  jav  a 2  s.  co  m*/
    uniSocketPool.setMaxIdle(1);
    uniSocketPool.setMaxTotal(1);
    uniSocketPool.setMinIdle(1);
    protocol.setSocketPool(uniSocketPool);

    for (int i = 0; i < 10; i++) {
        MockHttpServletRequest getRequest = new MockHttpServletRequest();

        getRequest.setMethod("GET");
        getRequest.setRequestURI("/alm/s/code2cloud/scm/test4.git/info/refs");
        getRequest.setQueryString("service=git-receive-pack");
        getRequest.addParameter("service", "git-receive-pack");
        getRequest.addHeader("Authorization", AUTH_HEADER);
        getRequest.addHeader("Host", "localhost:8888");
        getRequest.addHeader("User-Agent", "git/1.7.3.1");
        getRequest.addHeader("Accept", "*/*");
        getRequest.addHeader("Pragma", "no-cache");
        Payload getPayload = new Payload();
        getPayload.setResponseCode(HttpServletResponse.SC_OK);
        getPayload.setCharacterContent(GET_RESPONSE_PAYLOAD);

        MockHttpServletResponse response = new MockHttpServletResponse();
        TestServlet.setResponsePayload(getPayload);
        protocol.forward(getRequest, response);
        assertRequestIsExpected(getRequest, TestServlet.getLastRequest());
        assertResponseIsExpected(getPayload, response);

        MockHttpServletRequest postRequest = new MockHttpServletRequest();
        postRequest.setMethod("POST");
        postRequest.setRequestURI("/alm/s/code2cloud/scm/test4.git/git-receive-pack");
        postRequest.addHeader("Authorization", AUTH_HEADER);
        postRequest.addHeader("Host", "localhost:8888");
        postRequest.addHeader("Content-Length", "" + POST_REQUEST_PAYLOAD.length);
        postRequest.addHeader("Accept-Encoding", "deflate, gzip");
        postRequest.addHeader("User-Agent", "git/1.7.3.1");
        postRequest.addHeader("Accept", "application/x-git-receive-pack-result");
        postRequest.addHeader("Content-Type", "application/x-git-receive-pack-request");

        postRequest.setContent(POST_REQUEST_PAYLOAD);

        Payload postPayload = new Payload();
        postPayload.setResponseCode(HttpServletResponse.SC_OK);
        postPayload.setCharacterContent(POST_RESPONSE_PAYLOAD);

        response = new MockHttpServletResponse();
        TestServlet.setResponsePayload(postPayload);
        protocol.forward(postRequest, response);
        assertRequestIsExpected(postRequest, TestServlet.getLastRequest());
        assertResponseIsExpected(postPayload, response);
    }

}