Search in sources :

Example 6 with FeatureToggles

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");
}
Also used : FeatureToggles(com.thoughtworks.go.server.domain.support.toggle.FeatureToggles) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream)

Example 7 with FeatureToggles

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);
}
Also used : FeatureToggles(com.thoughtworks.go.server.domain.support.toggle.FeatureToggles)

Example 8 with FeatureToggles

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;
    }
}
Also used : FeatureToggles(com.thoughtworks.go.server.domain.support.toggle.FeatureToggles)

Example 9 with FeatureToggles

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();
}
Also used : FeatureToggles(com.thoughtworks.go.server.domain.support.toggle.FeatureToggles) FeatureToggle(com.thoughtworks.go.server.domain.support.toggle.FeatureToggle) StubGoCache(com.thoughtworks.go.server.service.StubGoCache) TestTransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager) Test(org.junit.Test)

Example 10 with FeatureToggles

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));
}
Also used : FeatureToggles(com.thoughtworks.go.server.domain.support.toggle.FeatureToggles) FeatureToggle(com.thoughtworks.go.server.domain.support.toggle.FeatureToggle) Test(org.junit.Test)

Aggregations

FeatureToggles (com.thoughtworks.go.server.domain.support.toggle.FeatureToggles)19 Test (org.junit.Test)15 FeatureToggle (com.thoughtworks.go.server.domain.support.toggle.FeatureToggle)13 File (java.io.File)4 StubGoCache (com.thoughtworks.go.server.service.StubGoCache)2 TestTransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1