@Test public void testConfigurationsValidation() throws Exception { String[] keys = { "config.test.wait.poll_interval", "config.test.wait.min_poll_interval", "config.test.wait.max_poll_interval" }; String[] illegalValues = { "", "foobar", "-1s", "99999999999999999s", (SECONDS.toHours(Integer.MAX_VALUE) * 2) + "h" }; for (String key : keys) { for (String value : illegalValues) { assertConfigurationFailsValidation(ImmutableMap.of(key, value)); } } assertConfigurationFailsValidation(ImmutableMap.of("config.test.wait.poll_interval", "5s")); assertConfigurationFailsValidation(ImmutableMap.of("config.test.wait.poll_interval", "29s")); assertConfigurationPassesValidation(ImmutableMap.of("config.test.wait.poll_interval", "30s")); assertConfigurationPassesValidation(ImmutableMap.of("config.test.wait.poll_interval", "31s")); { AbstractWaitOperatorFactory f = assertConfigurationPassesValidation(ImmutableMap.of( "config.test.wait.min_poll_interval", "45s", "config.test.wait.max_poll_interval", "60s" )); assertThat(f.getPollInterval(CONFIG_FACTORY.create()), is(45)); } assertConfigurationFailsValidation(ImmutableMap.of( "config.test.wait.min_poll_interval", "10s", "config.test.wait.poll_interval", "5s" )); assertConfigurationFailsValidation(ImmutableMap.of( "config.test.wait.min_poll_interval", "30s", "config.test.wait.max_poll_interval", "40s", "config.test.wait.poll_interval", "50s" )); assertConfigurationFailsValidation(ImmutableMap.of( "config.test.wait.min_poll_interval", "10s", "config.test.wait.max_poll_interval", "5s" )); { AbstractWaitOperatorFactory f = assertConfigurationPassesValidation(ImmutableMap.of( "config.test.wait.min_poll_interval", "5s", "config.test.wait.poll_interval", "5s", "config.test.wait.max_poll_interval", "5s" )); assertThat(f.getPollInterval(CONFIG_FACTORY.create()), is(5)); assertThrows(() -> f.getPollInterval(CONFIG_FACTORY.create(cfg(ImmutableMap.of("interval", "3s")))), ConfigException.class); assertThrows(() -> f.getPollInterval(CONFIG_FACTORY.create(cfg(ImmutableMap.of("interval", "7s")))), ConfigException.class); } { AbstractWaitOperatorFactory f = assertConfigurationPassesValidation(ImmutableMap.of( "config.test.wait.min_poll_interval", "5s", "config.test.wait.poll_interval", "10s", "config.test.wait.max_poll_interval", "15s" )); assertThat(f.getPollInterval(CONFIG_FACTORY.create()), is(10)); assertThrows(() -> f.getPollInterval(CONFIG_FACTORY.create(cfg(ImmutableMap.of("interval", "3s")))), ConfigException.class); assertThrows(() -> f.getPollInterval(CONFIG_FACTORY.create(cfg(ImmutableMap.of("interval", "30s")))), ConfigException.class); } { AbstractWaitOperatorFactory f = assertConfigurationPassesValidation(ImmutableMap.of( "config.test.wait.min_poll_interval", "10s", "config.test.wait.poll_interval", "5m", "config.test.wait.max_poll_interval", "2h" )); assertThat(f.getPollInterval(CONFIG_FACTORY.create()), is(5 * 60)); assertThrows(() -> f.getPollInterval(CONFIG_FACTORY.create(cfg(ImmutableMap.of("interval", "5s")))), ConfigException.class); assertThrows(() -> f.getPollInterval(CONFIG_FACTORY.create(cfg(ImmutableMap.of("interval", "3h")))), ConfigException.class); } }
public int getPollInterval(Config params) { long interval = validatePollInterval(params.get("interval", DurationParam.class, DurationParam.of(pollInterval)).getDuration().getSeconds()); assert interval >= 0 && interval <= Integer.MAX_VALUE; return (int) interval; }
AbstractWaitOperatorFactory { public int getPollInterval(Config params) { long interval = validatePollInterval(params.get("interval", DurationParam.class, DurationParam.of(pollInterval)).getDuration().getSeconds()); assert interval >= 0 && interval <= Integer.MAX_VALUE; return (int) interval; } }
AbstractWaitOperatorFactory { public int getPollInterval(Config params) { long interval = validatePollInterval(params.get("interval", DurationParam.class, DurationParam.of(pollInterval)).getDuration().getSeconds()); assert interval >= 0 && interval <= Integer.MAX_VALUE; return (int) interval; } protected  AbstractWaitOperatorFactory(final String operatorType, Config systemConfig); }
AbstractWaitOperatorFactory { public int getPollInterval(Config params) { long interval = validatePollInterval(params.get("interval", DurationParam.class, DurationParam.of(pollInterval)).getDuration().getSeconds()); assert interval >= 0 && interval <= Integer.MAX_VALUE; return (int) interval; } protected  AbstractWaitOperatorFactory(final String operatorType, Config systemConfig); int getPollInterval(Config params); }
AbstractWaitOperatorFactory { public int getPollInterval(Config params) { long interval = validatePollInterval(params.get("interval", DurationParam.class, DurationParam.of(pollInterval)).getDuration().getSeconds()); assert interval >= 0 && interval <= Integer.MAX_VALUE; return (int) interval; } protected  AbstractWaitOperatorFactory(final String operatorType, Config systemConfig); int getPollInterval(Config params);  }