use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggles in project gocd by gocd.
the class FeatureToggleRepository method availableToggles.
public FeatureToggles availableToggles() {
String availableTogglesResourcePath = environment.get(AVAILABLE_FEATURE_TOGGLES_FILE_PATH);
InputStream streamForAvailableToggles = getClass().getResourceAsStream(availableTogglesResourcePath);
if (streamForAvailableToggles == null) {
LOGGER.error("Failed to read toggles from " + availableTogglesResourcePath + ". Saying there are no toggles.");
return new FeatureToggles();
}
return readTogglesFromStream(streamForAvailableToggles, "available");
}
use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggles in project gocd by gocd.
the class FeatureToggleRepository method changeValueOfToggle.
public void changeValueOfToggle(String key, boolean newValue) {
FeatureToggles currentToggles = userToggles().changeToggleValue(key, newValue);
writeTogglesToFile(userTogglesFile(), currentToggles);
}
use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggles in project gocd by gocd.
the class FeatureToggleService method allToggles.
public FeatureToggles allToggles() {
synchronized (USER_TOGGLES_CACHE_KEY) {
FeatureToggles allToggles = (FeatureToggles) goCache.get(USER_TOGGLES_CACHE_KEY);
if (allToggles != null) {
return allToggles;
}
FeatureToggles availableToggles = repository.availableToggles();
FeatureToggles userToggles = repository.userToggles();
allToggles = availableToggles.overrideWithTogglesIn(userToggles);
goCache.put(USER_TOGGLES_CACHE_KEY, allToggles);
return allToggles;
}
}
use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggles in project gocd by gocd.
the class FeatureToggleServiceTest method shouldInvalidateCacheWhenAFeatureTogglesValueIsChanged.
@Test
public void shouldInvalidateCacheWhenAFeatureTogglesValueIsChanged() throws Exception {
when(repository.availableToggles()).thenReturn(new FeatureToggles(new FeatureToggle("key1", "desc1", true)));
when(repository.userToggles()).thenReturn(new FeatureToggles());
FeatureToggleService service = new FeatureToggleService(repository, new StubGoCache(new TestTransactionSynchronizationManager()));
service.allToggles();
verify(repository, times(1)).availableToggles();
service.changeValueOfToggle("key1", false);
verify(repository, times(1)).availableToggles();
service.allToggles();
verify(repository, times(2)).availableToggles();
}
use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggles in project gocd by gocd.
the class FeatureToggleServiceTest method shouldListAllFeatureToggles.
@Test
public void shouldListAllFeatureToggles() throws Exception {
FeatureToggles existingToggles = new FeatureToggles(new FeatureToggle("key1", "description1", true), new FeatureToggle("key2", "description2", false));
when(repository.availableToggles()).thenReturn(existingToggles);
when(repository.userToggles()).thenReturn(new FeatureToggles());
FeatureToggleService service = new FeatureToggleService(repository, goCache);
assertThat(service.allToggles(), is(existingToggles));
}
Aggregations