Search in sources :

Example 51 with ChaiProvider

use of com.novell.ldapchai.provider.ChaiProvider in project ldapchai by ldapchai.

the class WatchdogTester method testProviderLeak.

public void testProviderLeak() throws Exception {
    final ChaiEntry testContainer = TestHelper.createTestContainer();
    final int testIterations = TestHelper.testBulkIterations > 150 ? TestHelper.testBulkIterations : 150;
    final int startThreads = Thread.activeCount();
    final Set<ChaiProvider> providerCollection = new HashSet<ChaiProvider>();
    System.out.println("startThreads = " + startThreads);
    final ChaiConfiguration chaiConfig = new ChaiConfiguration(TestHelper.bindURL, TestHelper.bindDN, TestHelper.bindPW);
    chaiConfig.setSetting(ChaiSetting.WATCHDOG_ENABLE, "true");
    chaiConfig.setSetting(ChaiSetting.PROMISCUOUS_SSL, "true");
    for (int i = 0; i < testIterations; i++) {
        final ChaiProvider provider = ChaiProviderFactory.createProvider(chaiConfig);
        provider.readStringAttribute(testContainer.getEntryDN(), "cn");
        providerCollection.add(provider);
        final int currentThreads = Thread.activeCount();
        System.out.println("currentThreads= " + currentThreads + ", iteration: " + i);
    }
    final long idleTime = 5000 + Integer.parseInt(chaiConfig.getSetting(ChaiSetting.WATCHDOG_IDLE_TIMEOUT));
    System.out.printf("sleeping for " + idleTime);
    TestHelper.pause(idleTime);
    int stopThreads = Thread.activeCount();
    System.out.println("startThreads = " + startThreads);
    System.out.println("stopThreads = " + stopThreads);
    System.out.println("re-using connections");
    int i = 0;
    for (final ChaiProvider provider : providerCollection) {
        provider.getChaiConfiguration();
        provider.readStringAttribute(testContainer.getEntryDN(), "cn");
        final int currentThreads = Thread.activeCount();
        System.out.println("currentThreads= " + currentThreads + ", iteration: " + i++);
    }
    System.out.printf("sleeping for " + idleTime);
    TestHelper.pause(idleTime);
    stopThreads = Thread.activeCount();
    System.out.println("startThreads = " + startThreads);
    System.out.println("stopThreads = " + stopThreads);
    System.out.println("re-using connections");
    if (stopThreads > startThreads) {
        System.out.println("\nthread dump:");
        final Thread[] tarray = new Thread[Thread.activeCount()];
        Thread.enumerate(tarray);
        for (final Thread t : tarray) {
            System.out.println(t.toString() + t.getStackTrace()[0]);
        }
        throw new Exception("possible thread leak startThreads=" + startThreads + " stopThreads=" + stopThreads);
    }
}
Also used : ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ChaiEntry(com.novell.ldapchai.ChaiEntry) ChaiConfiguration(com.novell.ldapchai.provider.ChaiConfiguration) HashSet(java.util.HashSet)

Aggregations

ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)51 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)19 ChaiUser (com.novell.ldapchai.ChaiUser)18 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)18 ChaiConfiguration (com.novell.ldapchai.provider.ChaiConfiguration)16 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)15 ErrorInformation (password.pwm.error.ErrorInformation)15 ChaiEntry (com.novell.ldapchai.ChaiEntry)13 ChaiException (com.novell.ldapchai.exception.ChaiException)10 ArrayList (java.util.ArrayList)10 PwmOperationalException (password.pwm.error.PwmOperationalException)10 UserIdentity (password.pwm.bean.UserIdentity)9 LdapProfile (password.pwm.config.profile.LdapProfile)8 PasswordData (password.pwm.util.PasswordData)8 HashSet (java.util.HashSet)7 List (java.util.List)6 ChaiProviderFactory (com.novell.ldapchai.provider.ChaiProviderFactory)5 Instant (java.time.Instant)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5