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