Search in sources :

Example 16 with ChaiConfiguration

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;
}
Also used : ChaiConfiguration(com.novell.ldapchai.provider.ChaiConfiguration)

Example 17 with ChaiConfiguration

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);
}
Also used : ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ChaiUser(com.novell.ldapchai.ChaiUser) InetSocketAddress(java.net.InetSocketAddress) ChaiEntry(com.novell.ldapchai.ChaiEntry) TcpProxy(com.novell.ldapchai.tests.util.TcpProxy) ChaiConfiguration(com.novell.ldapchai.provider.ChaiConfiguration)

Example 18 with ChaiConfiguration

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;
}
Also used : ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ChaiException(com.novell.ldapchai.exception.ChaiException) ChaiConfiguration(com.novell.ldapchai.provider.ChaiConfiguration) ChaiException(com.novell.ldapchai.exception.ChaiException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException)

Example 19 with ChaiConfiguration

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);
}
Also used : ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ChaiEntry(com.novell.ldapchai.ChaiEntry) ChaiConfiguration(com.novell.ldapchai.provider.ChaiConfiguration)

Example 20 with ChaiConfiguration

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);
    }
}
Also used : ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ChaiEntry(com.novell.ldapchai.ChaiEntry) ChaiConfiguration(com.novell.ldapchai.provider.ChaiConfiguration) HashSet(java.util.HashSet)

Aggregations

ChaiConfiguration (com.novell.ldapchai.provider.ChaiConfiguration)20 ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)16 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)10 ChaiEntry (com.novell.ldapchai.ChaiEntry)9 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)7 ChaiUser (com.novell.ldapchai.ChaiUser)6 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)5 ChaiException (com.novell.ldapchai.exception.ChaiException)4 ArrayList (java.util.ArrayList)4 LdapProfile (password.pwm.config.profile.LdapProfile)4 PwmOperationalException (password.pwm.error.PwmOperationalException)4 List (java.util.List)3 Map (java.util.Map)3 TcpProxy (com.novell.ldapchai.tests.util.TcpProxy)2 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2 InetSocketAddress (java.net.InetSocketAddress)2 MalformedURLException (java.net.MalformedURLException)2 UnknownHostException (java.net.UnknownHostException)2 HashMap (java.util.HashMap)2