Search in sources :

Example 31 with ChaiEntry

use of com.novell.ldapchai.ChaiEntry 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

ChaiEntry (com.novell.ldapchai.ChaiEntry)31 ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)12 ChaiConfiguration (com.novell.ldapchai.provider.ChaiConfiguration)8 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)7 ChaiUser (com.novell.ldapchai.ChaiUser)6 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)5 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)4 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)3 ChaiException (com.novell.ldapchai.exception.ChaiException)2 ChaiValidationException (com.novell.ldapchai.exception.ChaiValidationException)2 NmasResponseSet (com.novell.ldapchai.impl.edir.NmasResponseSet)2 TcpProxy (com.novell.ldapchai.tests.util.TcpProxy)2 InetSocketAddress (java.net.InetSocketAddress)2 MalformedURLException (java.net.MalformedURLException)2 UnknownHostException (java.net.UnknownHostException)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2