ApdexThresholdConfig extends ConfigChangeWatcher implements ConfigurationDictionary { @Override public Number lookup(String name) { int t = dictionary.getOrDefault(name, -1); if (t < 0) { t = dictionary.getOrDefault("default", -1); } if (t < 0) { log.warn("Pick up system reserved threshold {}ms because of config missing", SYSTEM_RESERVED_THRESHOLD); return SYSTEM_RESERVED_THRESHOLD; } if (log.isDebugEnabled()) { log.debug("Apdex threshold of {} is {}ms", name, t); } return t; } ApdexThresholdConfig(final CoreModuleProvider provider); @Override Number lookup(String name); @Override void notify(ConfigChangeEvent value); @Override String value();  }
@Test public void testLookupOfBeforeInit() { ApdexThresholdConfig config = new ApdexThresholdConfig(provider); assertThat(config.lookup("foo"), is(500)); assertThat(config.lookup("default"), is(500)); assertThat(config.lookup("bar"), is(500)); }
@Test(timeout = 20000) public void testLookupOfDynamicUpdate() throws InterruptedException { ConfigWatcherRegister register = new MockConfigWatcherRegister(3); when(provider.name()).thenReturn("default"); ApdexThresholdConfig config = new ApdexThresholdConfig(provider); register.registerConfigChangeWatcher(config); register.start(); while (config.lookup("foo").intValue() == 500) { Thread.sleep(2000); } assertThat(config.lookup("foo"), is(200)); assertThat(config.lookup("default"), is(1000)); assertThat(config.lookup("bar"), is(1000)); }