Search in sources :

Example 1 with KnownKey

use of com.zimbra.common.localconfig.KnownKey in project zm-mailbox by Zimbra.

the class TestLdapConnection method setLocalConfig.

private Map<KnownKey, String> setLocalConfig(Map<KnownKey, String> keyValues) {
    Map<KnownKey, String> curValues = new HashMap<KnownKey, String>();
    for (Map.Entry<KnownKey, String> keyValue : keyValues.entrySet()) {
        KnownKey key = keyValue.getKey();
        String value = keyValue.getValue();
        // save the current value
        String curValue = key.value();
        curValues.put(key, curValue);
        // set to the new value
        LocalconfigTestUtil.modifyLocalConfigTransient(key, value);
        assertEquals(value, key.value());
    }
    return curValues;
}
Also used : KnownKey(com.zimbra.common.localconfig.KnownKey) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with KnownKey

use of com.zimbra.common.localconfig.KnownKey in project zm-mailbox by Zimbra.

the class TestLdapConnection method backgroundHealthCheck.

@Test
public void backgroundHealthCheck() throws Exception {
    SKIP_FOR_INMEM_LDAP_SERVER(SkipTestReason.CONNECTION_POOL_HEALTH_CHECK);
    // 5 secs
    final long BACKGROUND_HEALTH_CHECK_INTERVAL = 5000;
    Map<KnownKey, String> lcKeysToModify = new HashMap<KnownKey, String>();
    lcKeysToModify.put(LC.ldap_connect_pool_health_check_on_checkout_enabled, "false");
    // lcKeysToModify.put(LC.ldap_connect_pool_health_check_after_exception_enabled, "false");
    // lcKeysToModify.put(LC.ldap_connect_pool_health_check_background_enabled, "true");
    lcKeysToModify.put(LC.ldap_connect_pool_health_check_background_interval_millis, Long.valueOf(BACKGROUND_HEALTH_CHECK_INTERVAL).toString());
    Map<KnownKey, String> origLCKeyValues = setLocalConfig(lcKeysToModify);
    final int MAX_POOL_SIZE = LC.ldap_connect_pool_maxsize.intValue();
    final int NUM_CONNS = 10;
    ExternalLdapConfig ldapConfig = new ExternalLdapConfig(LDAP_URL_BACKGROUND, START_TLS_ENABLED, null, BIND_DN, BIND_PASSWORD, null, null);
    LDAPConnectionPool connPool = populateConnPool(ldapConfig, NUM_CONNS);
    // stop ldap server here
    System.out.println("Before health check, availConns = " + connPool.getCurrentAvailableConnections());
    stopLdap();
    // wait for the health check interval to trigger health check
    long waitFor = BACKGROUND_HEALTH_CHECK_INTERVAL + 1000;
    System.out.println("Waiting for " + waitFor + " msecs");
    Thread.sleep(waitFor);
    System.out.println("After health check, availConns = " + connPool.getCurrentAvailableConnections());
    assertEquals(0, connPool.getCurrentAvailableConnections());
    // put the config key back
    setLocalConfig(origLCKeyValues);
    startLdap();
    // get a connection now, should be successful
    UBIDLdapContext zlc = getContext(ldapConfig);
    closeContext(zlc);
}
Also used : LDAPConnectionPool(com.unboundid.ldap.sdk.LDAPConnectionPool) KnownKey(com.zimbra.common.localconfig.KnownKey) ExternalLdapConfig(com.zimbra.cs.ldap.LdapServerConfig.ExternalLdapConfig) HashMap(java.util.HashMap) UBIDLdapContext(com.zimbra.cs.ldap.unboundid.UBIDLdapContext) Test(org.junit.Test)

Example 3 with KnownKey

use of com.zimbra.common.localconfig.KnownKey in project zm-mailbox by Zimbra.

the class TestLdap method initPerJVM.

// invoked once per JVM
private static void initPerJVM(TestConfig testConfig) throws Exception {
    if (perJVMInited) {
        return;
    }
    perJVMInited = true;
    CliUtil.toolSetup(Log.Level.error.name());
    ZimbraLog.test.setLevel(Log.Level.info);
    ZimbraLog.autoprov.setLevel(Log.Level.debug);
    /*
        if (useInMemoryLdapServerProperty == null) {
            useInMemoryLdapServerProperty = 
                System.getProperty("use_in_memory_ldap_server", "false");
        }
        
        boolean useInMemoryLdapServer = 
            Boolean.parseBoolean(useInMemoryLdapServerProperty);
        
        KnownKey key = new KnownKey("debug_use_in_memory_ldap_server", 
                useInMemoryLdapServerProperty);
        assert(DebugConfig.useInMemoryLdapServer == useInMemoryLdapServer);
        useInMemoryLdapServer = InMemoryLdapServer.isOn();
        
        ZimbraLog.test.info("useInMemoryLdapServer = " + useInMemoryLdapServer);
        
        if (useInMemoryLdapServer) {
            try {
                InMemoryLdapServer.start(InMemoryLdapServer.ZIMBRA_LDAP_SERVER, 
                        new InMemoryLdapServer.ServerConfig(
                        Lists.newArrayList(LdapConstants.ATTR_DC + "=" + TEST_LDAP_BASE_DOMAIN)));
            } catch (Exception e) {
                e.printStackTrace();
                throw e;
            }
        }
        */
    if (useInMemoryLdapServerOverride != null) {
        boolean useInMemoryLdapServer = Boolean.parseBoolean(useInMemoryLdapServerOverride);
        KnownKey key = new KnownKey("debug_use_in_memory_ldap_server", useInMemoryLdapServerOverride);
        if (DebugConfig.useInMemoryLdapServer != useInMemoryLdapServer) {
            System.out.println("useInMemoryLdapServerOverride is " + useInMemoryLdapServerOverride + " but LC key debug_use_in_memory_ldap_server is " + key.value() + ".  Remove the value from LC key.");
            fail();
        }
    }
    ZimbraLog.test.info("useInMemoryLdapServer = " + InMemoryLdapServer.isOn());
    RightManager.getInstance(true);
    TestConfig.useConfig(testConfig);
    cleanupAll();
}
Also used : KnownKey(com.zimbra.common.localconfig.KnownKey)

Example 4 with KnownKey

use of com.zimbra.common.localconfig.KnownKey in project zm-mailbox by Zimbra.

the class LdapTest method initPerJVM.

// invoked once per JVM
private static synchronized void initPerJVM() throws Exception {
    if (perJVMInited) {
        return;
    }
    perJVMInited = true;
    CliUtil.toolSetup(Log.Level.error.name());
    ZimbraLog.test.setLevel(Log.Level.info);
    if (useInMemoryLdapServerOverride != null) {
        boolean useInMemoryLdapServer = Boolean.parseBoolean(useInMemoryLdapServerOverride);
        KnownKey key = new KnownKey("debug_use_in_memory_ldap_server", useInMemoryLdapServerOverride);
        if (DebugConfig.useInMemoryLdapServer != useInMemoryLdapServer) {
            System.out.println("useInMemoryLdapServerOverride is " + useInMemoryLdapServerOverride + " but LC key debug_use_in_memory_ldap_server is " + key.value() + ".  Remove the value from LC key.");
            fail();
        }
    }
    ZimbraLog.test.info("useInMemoryLdapServer = " + InMemoryLdapServer.isOn());
    RightManager.getInstance(true);
    Cleanup.deleteAll();
}
Also used : KnownKey(com.zimbra.common.localconfig.KnownKey)

Example 5 with KnownKey

use of com.zimbra.common.localconfig.KnownKey in project zm-mailbox by Zimbra.

the class LocalConfigCLI method loadExtensionLC.

private void loadExtensionLC(String className) {
    try {
        Class<?> lcClass = Class.forName(className);
        Field[] fields = lcClass.getFields();
        for (Field field : fields) {
            try {
                if (field.getType() == KnownKey.class) {
                    KnownKey key = (KnownKey) field.get(null);
                    // Automatically set the key name with the variable name.
                    key.setKey(field.getName());
                    // process annotations
                    if (field.isAnnotationPresent(Supported.class))
                        key.setSupported(true);
                    if (field.isAnnotationPresent(Reloadable.class))
                        key.setReloadable(true);
                }
            } catch (Throwable never) {
            // ignore
            }
        }
    } catch (ClassNotFoundException e) {
    // ignore
    }
}
Also used : Field(java.lang.reflect.Field) KnownKey(com.zimbra.common.localconfig.KnownKey)

Aggregations

KnownKey (com.zimbra.common.localconfig.KnownKey)7 HashMap (java.util.HashMap)4 LDAPConnectionPool (com.unboundid.ldap.sdk.LDAPConnectionPool)3 ExternalLdapConfig (com.zimbra.cs.ldap.LdapServerConfig.ExternalLdapConfig)3 UBIDLdapContext (com.zimbra.cs.ldap.unboundid.UBIDLdapContext)3 Test (org.junit.Test)3 ServiceException (com.zimbra.common.service.ServiceException)2 Field (java.lang.reflect.Field)1 Map (java.util.Map)1 Ignore (org.junit.Ignore)1