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);
}
Aggregations