use of com.novell.ldapchai.provider.ChaiConfiguration in project ldapchai by ldapchai.
the class FailOverTester method makeChaiConfig.
private static ChaiConfiguration makeChaiConfig(final String url) {
final ChaiConfiguration config = new ChaiConfiguration();
config.setSetting(ChaiSetting.BIND_URLS, url);
config.setSetting(ChaiSetting.BIND_DN, TestHelper.bindDN);
config.setSetting(ChaiSetting.BIND_PASSWORD, TestHelper.bindPW);
config.setSetting(ChaiSetting.FAILOVER_ENABLE, "true");
config.setSetting(ChaiSetting.STATISTICS_ENABLE, "false");
config.setSetting(ChaiSetting.WATCHDOG_ENABLE, "false");
config.setSetting(ChaiSetting.PROMISCUOUS_SSL, "true");
return config;
}
use of com.novell.ldapchai.provider.ChaiConfiguration in project ldapchai by ldapchai.
the class FailOverTester method testMultiServerFailover.
public void testMultiServerFailover() throws Exception {
TestHelper.configureLogging();
final InetSocketAddress destinationAddress = figureDestSocketAddress();
final TcpProxy proxy1 = new TcpProxy(basePort + 1, destinationAddress);
final TcpProxy proxy2 = new TcpProxy(basePort + 2, destinationAddress);
final TcpProxy proxy3 = new TcpProxy(basePort + 3, destinationAddress);
proxy2.start();
final ChaiConfiguration testConfig = makeChaiConfig(figureUrlForProxy(proxy1, proxy2, proxy3));
final ChaiProvider testProvider = ChaiProviderFactory.createProvider(testConfig);
final ChaiEntry testContainer = TestHelper.createTestContainer(testProvider);
final ChaiUser testUser = TestHelper.createNewTestUser(testContainer);
TestHelper.doBasicNonDestructiveUserTest(testUser);
proxy2.stop();
TestHelper.pause(1000);
{
// test to make sure we get unavailable error
boolean gotError = false;
try {
TestHelper.doBasicNonDestructiveUserTest(testUser);
} catch (ChaiUnavailableException e) {
System.out.println("got expected unavailable error: " + e.getMessage());
gotError = true;
}
Assert.assertTrue(gotError);
}
proxy1.start();
TestHelper.pause(1000);
TestHelper.doBasicNonDestructiveUserTest(testUser);
proxy1.stop();
proxy3.start();
TestHelper.pause(1000);
TestHelper.doBasicNonDestructiveUserTest(testUser);
}
use of com.novell.ldapchai.provider.ChaiConfiguration in project ldapchai by ldapchai.
the class TestHelper method getProvider.
public static ChaiProvider getProvider() throws Exception {
if (cachedProvider == null) {
final ChaiProvider newProvider;
try {
final ChaiConfiguration chaiConfig = new ChaiConfiguration(TestHelper.bindURL, TestHelper.bindDN, TestHelper.bindPW);
chaiConfig.setSetting(ChaiSetting.PROVIDER_IMPLEMENTATION, testProviderImpl);
chaiConfig.setSetting(ChaiSetting.PROMISCUOUS_SSL, "true");
// chaiConfig.setSetting(ChaiSetting.WATCHDOG_ENABLE, "false");
// chaiConfig.setSetting(ChaiSetting.FAILOVER_ENABLE, "false");
newProvider = ChaiProviderFactory.createProvider(chaiConfig);
} catch (ChaiException e) {
throw new Exception("Cannot connect to test ldap directory", e);
}
// test for test container
try {
newProvider.readStringAttribute(TestHelper.testContainer, "objectClass");
} catch (Exception e) {
throw new Exception("Cannot connect to test ldap directory, missing test container", e);
}
cachedProvider = newProvider;
}
return cachedProvider;
}
use of com.novell.ldapchai.provider.ChaiConfiguration in project ldapchai by ldapchai.
the class WatchdogTester method testWatchdogBasic.
public void testWatchdogBasic() throws Exception {
final ChaiEntry testContainer = TestHelper.createTestContainer();
final long idleTime = 5 * 1000;
final ChaiConfiguration chaiConfig = new ChaiConfiguration(TestHelper.bindURL, TestHelper.bindDN, TestHelper.bindPW);
chaiConfig.setSetting(ChaiSetting.WATCHDOG_ENABLE, "true");
chaiConfig.setSetting(ChaiSetting.PROMISCUOUS_SSL, "true");
chaiConfig.setSetting(ChaiSetting.WATCHDOG_IDLE_TIMEOUT, String.valueOf(idleTime));
final ChaiProvider provider = ChaiProviderFactory.createProvider(chaiConfig);
// do initial read
String cnValue = provider.readStringAttribute(testContainer.getEntryDN(), "ou");
System.out.println("cnValue = " + cnValue);
TestHelper.pause((long) (idleTime * 1.5));
cnValue = provider.readStringAttribute(testContainer.getEntryDN(), "ou");
System.out.println("cnValue = " + cnValue);
}
use of com.novell.ldapchai.provider.ChaiConfiguration 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