Search in sources :

Example 6 with UBIDLdapContext

use of com.zimbra.cs.ldap.unboundid.UBIDLdapContext in project zm-mailbox by Zimbra.

the class TestLdapConnection method testConnPoolNumAvailConns.

@Test
public // @Ignore  // TODO: must be the first test to run
void testConnPoolNumAvailConns() throws Exception {
    int INIT_POOL_SIZE = LC.ldap_connect_pool_initsize.intValue();
    int MAX_POOL_SIZE = LC.ldap_connect_pool_maxsize.intValue();
    LDAPConnectionPool connPool = LdapConnectionPool.getConnPoolByName(LdapConnectionPool.CP_ZIMBRA_REPLICA);
    assertEquals(INIT_POOL_SIZE, connPool.getCurrentAvailableConnections());
    assertEquals(MAX_POOL_SIZE, connPool.getMaximumAvailableConnections());
    UBIDLdapContext zlc = getContext();
    String poolName = connPool.getConnectionPoolName();
    closeContext(zlc);
    assertEquals(LdapConnectionPool.CP_ZIMBRA_REPLICA, poolName);
    // should not change.
    for (int i = 0; i < 10; i++) {
        UBIDLdapContext conn = getContext();
        closeContext(conn);
        assertEquals(INIT_POOL_SIZE, connPool.getCurrentAvailableConnections());
    }
    int numOpen = 20;
    // make sure numOpen is a good number to test
    assertTrue(numOpen > INIT_POOL_SIZE);
    assertTrue(numOpen < MAX_POOL_SIZE);
    // get connections, not closing them, num available connections in the pool 
    // should keep decreasing until there is no more.
    UBIDLdapContext[] conns = new UBIDLdapContext[numOpen];
    for (int i = 0; i < numOpen; i++) {
        conns[i] = getContext();
        int expected = Math.max(0, INIT_POOL_SIZE - (i + 1));
        assertEquals(expected, connPool.getCurrentAvailableConnections());
    }
    // should keep increasing.
    for (int i = 0; i < numOpen; i++) {
        closeContext(conns[i]);
        int expected = i + 1;
        assertEquals(expected, connPool.getCurrentAvailableConnections());
    }
// dumpConnPool(connPool);
}
Also used : LDAPConnectionPool(com.unboundid.ldap.sdk.LDAPConnectionPool) UBIDLdapContext(com.zimbra.cs.ldap.unboundid.UBIDLdapContext) Test(org.junit.Test)

Aggregations

UBIDLdapContext (com.zimbra.cs.ldap.unboundid.UBIDLdapContext)6 LDAPConnectionPool (com.unboundid.ldap.sdk.LDAPConnectionPool)5 Test (org.junit.Test)4 KnownKey (com.zimbra.common.localconfig.KnownKey)3 ExternalLdapConfig (com.zimbra.cs.ldap.LdapServerConfig.ExternalLdapConfig)3 HashMap (java.util.HashMap)3 ServiceException (com.zimbra.common.service.ServiceException)2 ZAttributes (com.zimbra.cs.ldap.ZAttributes)1 Ignore (org.junit.Ignore)1