@Test public void testGetValue_cache() { when(configSource.repository.getConfigValue(anyString())).thenReturn("123"); configSource.getValue("test"); configSource.getValue("test"); verify(configSource.repository, times(1)).getConfigValue(anyString()); }
@Override public String getValue(String propertyName) { if (CONFIG_ORDINAL.equals(propertyName)) { return null; } initRepository(); initValidity(); TimedEntry entry = cache.get(propertyName); if (entry == null){ return readFromDB(propertyName); }else if(entry.isExpired()) { ChangeEventNotifier changeEventNotifier = ChangeEventNotifier.getInstance(); String oldValue = entry.getValue(); String newValue = readFromDB(propertyName); if(notifyOnChanges){ if(newValue==null){ changeEventNotifier.fire(new ChangeEvent(Type.REMOVE,propertyName,changeEventNotifier.getOptionalOldValue(oldValue),null,NAME)); }else if(!oldValue.equals(newValue)){ changeEventNotifier.fire(new ChangeEvent(Type.UPDATE,propertyName,changeEventNotifier.getOptionalOldValue(oldValue),newValue,NAME)); } } return newValue; }else{ return entry.getValue(); } }
DatasourceConfigSource extends EnabledConfigSource { @Override public String getValue(String propertyName) { if (CONFIG_ORDINAL.equals(propertyName)) { return null; } initRepository(); initValidity(); TimedEntry entry = cache.get(propertyName); if (entry == null){ return readFromDB(propertyName); }else if(entry.isExpired()) { ChangeEventNotifier changeEventNotifier = ChangeEventNotifier.getInstance(); String oldValue = entry.getValue(); String newValue = readFromDB(propertyName); if(notifyOnChanges){ if(newValue==null){ changeEventNotifier.fire(new ChangeEvent(Type.REMOVE,propertyName,changeEventNotifier.getOptionalOldValue(oldValue),null,NAME)); }else if(!oldValue.equals(newValue)){ changeEventNotifier.fire(new ChangeEvent(Type.UPDATE,propertyName,changeEventNotifier.getOptionalOldValue(oldValue),newValue,NAME)); } } return newValue; }else{ return entry.getValue(); } } }
DatasourceConfigSource extends EnabledConfigSource { @Override public String getValue(String propertyName) { if (CONFIG_ORDINAL.equals(propertyName)) { return null; } initRepository(); initValidity(); TimedEntry entry = cache.get(propertyName); if (entry == null){ return readFromDB(propertyName); }else if(entry.isExpired()) { ChangeEventNotifier changeEventNotifier = ChangeEventNotifier.getInstance(); String oldValue = entry.getValue(); String newValue = readFromDB(propertyName); if(notifyOnChanges){ if(newValue==null){ changeEventNotifier.fire(new ChangeEvent(Type.REMOVE,propertyName,changeEventNotifier.getOptionalOldValue(oldValue),null,NAME)); }else if(!oldValue.equals(newValue)){ changeEventNotifier.fire(new ChangeEvent(Type.UPDATE,propertyName,changeEventNotifier.getOptionalOldValue(oldValue),newValue,NAME)); } } return newValue; }else{ return entry.getValue(); } } DatasourceConfigSource(); }
DatasourceConfigSource extends EnabledConfigSource { @Override public String getValue(String propertyName) { if (CONFIG_ORDINAL.equals(propertyName)) { return null; } initRepository(); initValidity(); TimedEntry entry = cache.get(propertyName); if (entry == null){ return readFromDB(propertyName); }else if(entry.isExpired()) { ChangeEventNotifier changeEventNotifier = ChangeEventNotifier.getInstance(); String oldValue = entry.getValue(); String newValue = readFromDB(propertyName); if(notifyOnChanges){ if(newValue==null){ changeEventNotifier.fire(new ChangeEvent(Type.REMOVE,propertyName,changeEventNotifier.getOptionalOldValue(oldValue),null,NAME)); }else if(!oldValue.equals(newValue)){ changeEventNotifier.fire(new ChangeEvent(Type.UPDATE,propertyName,changeEventNotifier.getOptionalOldValue(oldValue),newValue,NAME)); } } return newValue; }else{ return entry.getValue(); } } DatasourceConfigSource(); @Override Map<String, String> getPropertiesIfEnabled(); @Override String getValue(String propertyName); @Override String getName(); }
DatasourceConfigSource extends EnabledConfigSource { @Override public String getValue(String propertyName) { if (CONFIG_ORDINAL.equals(propertyName)) { return null; } initRepository(); initValidity(); TimedEntry entry = cache.get(propertyName); if (entry == null){ return readFromDB(propertyName); }else if(entry.isExpired()) { ChangeEventNotifier changeEventNotifier = ChangeEventNotifier.getInstance(); String oldValue = entry.getValue(); String newValue = readFromDB(propertyName); if(notifyOnChanges){ if(newValue==null){ changeEventNotifier.fire(new ChangeEvent(Type.REMOVE,propertyName,changeEventNotifier.getOptionalOldValue(oldValue),null,NAME)); }else if(!oldValue.equals(newValue)){ changeEventNotifier.fire(new ChangeEvent(Type.UPDATE,propertyName,changeEventNotifier.getOptionalOldValue(oldValue),newValue,NAME)); } } return newValue; }else{ return entry.getValue(); } } DatasourceConfigSource(); @Override Map<String, String> getPropertiesIfEnabled(); @Override String getValue(String propertyName); @Override String getName();  }