HAConfiguration { public static boolean isHAEnabled(Configuration configuration) { boolean ret = false; if (configuration.containsKey(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)) { ret = configuration.getBoolean(ATLAS_SERVER_HA_ENABLED_KEY); } else { String[] ids = configuration.getStringArray(HAConfiguration.ATLAS_SERVER_IDS); ret = ids != null && ids.length > 1; } return ret; } private  HAConfiguration(); static boolean isHAEnabled(Configuration configuration); static String getBoundAddressForId(Configuration configuration, String serverId); static List<String> getServerInstances(Configuration configuration); static ZookeeperProperties getZookeeperProperties(Configuration configuration); static final String ATLAS_SERVER_ZK_ROOT_DEFAULT; static final String ATLAS_SERVER_HA_PREFIX; static final String ZOOKEEPER_PREFIX; static final String ATLAS_SERVER_HA_ZK_ROOT_KEY; static final String ATLAS_SERVER_HA_ENABLED_KEY; static final String ATLAS_SERVER_ADDRESS_PREFIX; static final String ATLAS_SERVER_IDS; static final String HA_ZOOKEEPER_CONNECT; static final int DEFAULT_ZOOKEEPER_CONNECT_SLEEPTIME_MILLIS; static final String HA_ZOOKEEPER_RETRY_SLEEPTIME_MILLIS; static final String HA_ZOOKEEPER_NUM_RETRIES; static final int DEFAULT_ZOOKEEPER_CONNECT_NUM_RETRIES; static final String HA_ZOOKEEPER_SESSION_TIMEOUT_MS; static final int DEFAULT_ZOOKEEPER_SESSION_TIMEOUT_MILLIS; static final String HA_ZOOKEEPER_ACL; static final String HA_ZOOKEEPER_AUTH; }
@Test public void testIsHAEnabledByLegacyConfiguration() { when(configuration.containsKey(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(true); when(configuration.getBoolean(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(Boolean.TRUE); boolean isHAEnabled = HAConfiguration.isHAEnabled(configuration); assertTrue(isHAEnabled); when(configuration.containsKey(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(false); isHAEnabled = HAConfiguration.isHAEnabled(configuration); assertFalse(isHAEnabled); }
@Test public void testIsHAEnabledByIds() { when(configuration.containsKey(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(false); when(configuration.getStringArray(HAConfiguration.ATLAS_SERVER_IDS)).thenReturn(TEST_ATLAS_SERVER_IDS_HA); boolean isHAEnabled = HAConfiguration.isHAEnabled(configuration); assertTrue(isHAEnabled); when(configuration.getStringArray(HAConfiguration.ATLAS_SERVER_IDS)).thenReturn(new String[] { "id1"}); isHAEnabled = HAConfiguration.isHAEnabled(configuration); assertFalse(isHAEnabled); }