ElasticsearchConfig extends MapConfig { public Optional<Integer> getBulkFlushIntervalMS() { if (containsKey(CONFIG_KEY_FLUSH_INTERVALS_MS)) { int intervalMs = getInt(CONFIG_KEY_FLUSH_INTERVALS_MS); if (intervalMs <= 0) { throw new ConfigException(String.format("%s must be > 0", CONFIG_KEY_FLUSH_INTERVALS_MS)); } return Optional.of(intervalMs); } else { return Optional.empty(); } } ElasticsearchConfig(String name, Config config); String getHTTPURL(); AuthType getAuthType(); String getBasicAuthUser(); String getBasicAuthPassword(); int getConnectTimeoutMs(); int getReadTimeoutMs(); int getBulkFlushMaxActions(); Optional<Integer> getBulkFlushIntervalMS(); static final String CONFIG_KEY_FLUSH_MAX_ACTIONS; static final String CONFIG_KEY_FLUSH_INTERVALS_MS; static final String CONFIG_KEY_HTTP_URL; static final String CONFIG_KEY_HTTP_AUTH_TYPE; static final String CONFIG_KEY_HTTP_AUTH_BASIC_USER; static final String CONFIG_KEY_HTTP_AUTH_BASIC_PASSWORD; static final String CONFIG_KEY_HTTP_CONNECT_TIMEOUT_MS; static final String CONFIG_KEY_HTTP_READ_TIMEOUT_MS; }
@Test public void testFlushMaxIntervalMs() throws Exception { assertFalse(EMPTY_CONFIG.getBulkFlushIntervalMS().isPresent()); ElasticsearchConfig config = configForProperty("systems.es.flush.interval.ms", "500"); assertEquals(500, config.getBulkFlushIntervalMS().get().intValue()); assertThatThrownBy(configForProperty("systems.es.flush.interval.ms", "junk")::getBulkFlushIntervalMS).isInstanceOf(NumberFormatException.class); assertThatThrownBy(configForProperty("systems.es.flush.interval.ms", "-1")::getBulkFlushIntervalMS).isInstanceOf(ConfigException.class) .hasMessageContaining("must be > 0"); }