Search in sources :

Example 26 with ConfigReposConfig

use of com.thoughtworks.go.config.remote.ConfigReposConfig in project gocd by gocd.

the class PartialConfigServiceTest method setUp.

@BeforeEach
void setUp() {
    ConfigRepoService configRepoService = mock(ConfigRepoService.class);
    serverHealthService = mock(ServerHealthService.class);
    GoConfigPluginService configPluginService = mock(GoConfigPluginService.class);
    partialConfigHelper = mock(PartialConfigHelper.class);
    plugin = mock(PartialConfigProvider.class);
    when(configPluginService.partialConfigProviderFor(any(ConfigRepoConfig.class))).thenReturn(plugin);
    cruiseConfig = new BasicCruiseConfig();
    configRepoConfig = ConfigRepoConfig.createConfigRepoConfig(git("url"), "plugin", "id");
    cruiseConfig.setConfigRepos(new ConfigReposConfig(configRepoConfig));
    CachedGoConfig cachedGoConfig = mock(CachedGoConfig.class);
    when(cachedGoConfig.currentConfig()).thenReturn(cruiseConfig);
    configWatchList = new GoConfigWatchList(cachedGoConfig, mock(GoConfigService.class));
    goConfigService = mock(GoConfigService.class);
    repoConfigDataSource = new GoConfigRepoConfigDataSource(configWatchList, configPluginService, serverHealthService, configRepoService, goConfigService);
    cachedGoPartials = new CachedGoPartials(serverHealthService);
    serverHealthService = mock(ServerHealthService.class);
    updateCommand = null;
    service = new PartialConfigService(repoConfigDataSource, configWatchList, goConfigService, cachedGoPartials, serverHealthService, partialConfigHelper) {

        @Override
        protected PartialConfigUpdateCommand buildUpdateCommand(PartialConfig partial, String fingerprint) {
            if (null == updateCommand) {
                return super.buildUpdateCommand(partial, fingerprint);
            }
            return updateCommand;
        }
    };
    when(configRepoService.findByFingerprint(anyString())).thenReturn(configRepoConfig);
}
Also used : ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) ConfigReposConfig(com.thoughtworks.go.config.remote.ConfigReposConfig) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) ConfigRepoService(com.thoughtworks.go.server.service.ConfigRepoService) PartialConfigUpdateCommand(com.thoughtworks.go.config.update.PartialConfigUpdateCommand) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 27 with ConfigReposConfig

use of com.thoughtworks.go.config.remote.ConfigReposConfig in project gocd by gocd.

the class GoConfigWatchList method onConfigChange.

@Override
public void onConfigChange(CruiseConfig newCruiseConfig) {
    ConfigReposConfig partSources = newCruiseConfig.getConfigRepos();
    this.reposConfig = partSources;
    notifyListeners(partSources);
}
Also used : ConfigReposConfig(com.thoughtworks.go.config.remote.ConfigReposConfig)

Example 28 with ConfigReposConfig

use of com.thoughtworks.go.config.remote.ConfigReposConfig in project gocd by gocd.

the class GoConfigWatchListTest method shouldReturnFalseWhenDoesNotHaveConfigRepoWithFingerprint.

@Test
public void shouldReturnFalseWhenDoesNotHaveConfigRepoWithFingerprint() {
    GitMaterialConfig gitrepo = git("http://configrepo.git");
    when(cruiseConfig.getConfigRepos()).thenReturn(new ConfigReposConfig(ConfigRepoConfig.createConfigRepoConfig(gitrepo, "myplugin", "id")));
    watchList = new GoConfigWatchList(cachedGoConfig, mock(GoConfigService.class));
    GitMaterialConfig gitrepo2 = git("http://configrepo.git", "dev");
    assertFalse(watchList.hasConfigRepoWithFingerprint(gitrepo2.getFingerprint()));
}
Also used : ConfigReposConfig(com.thoughtworks.go.config.remote.ConfigReposConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) Test(org.junit.jupiter.api.Test)

Example 29 with ConfigReposConfig

use of com.thoughtworks.go.config.remote.ConfigReposConfig in project gocd by gocd.

the class GoConfigWatchListTest method shouldReturnTrueWhenHasConfigRepoWithFingerprint.

@Test
public void shouldReturnTrueWhenHasConfigRepoWithFingerprint() {
    GitMaterialConfig gitrepo = git("http://configrepo.git");
    when(cruiseConfig.getConfigRepos()).thenReturn(new ConfigReposConfig(ConfigRepoConfig.createConfigRepoConfig(gitrepo, "myplugin", "id")));
    watchList = new GoConfigWatchList(cachedGoConfig, goConfigService);
    assertTrue(watchList.hasConfigRepoWithFingerprint(gitrepo.getFingerprint()));
}
Also used : ConfigReposConfig(com.thoughtworks.go.config.remote.ConfigReposConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) Test(org.junit.jupiter.api.Test)

Example 30 with ConfigReposConfig

use of com.thoughtworks.go.config.remote.ConfigReposConfig in project gocd by gocd.

the class ConfigSaveDeadlockDetectionIntegrationTest method shouldNotDeadlockWhenAllPossibleWaysOfUpdatingTheConfigAreBeingUsedAtTheSameTime.

@Test
@Timeout(value = 3, unit = TimeUnit.MINUTES)
public void shouldNotDeadlockWhenAllPossibleWaysOfUpdatingTheConfigAreBeingUsedAtTheSameTime() throws Exception {
    int EXISTING_ENV_COUNT = goConfigService.cruiseConfig().getEnvironments().size();
    final ArrayList<Thread> group1 = new ArrayList<>();
    final ArrayList<Thread> group2 = new ArrayList<>();
    final ArrayList<Thread> group3 = new ArrayList<>();
    final ArrayList<Thread> group4 = new ArrayList<>();
    final ArrayList<Thread> group5 = new ArrayList<>();
    int count = 100;
    final int pipelineCreatedThroughApiCount = count;
    final int pipelineCreatedThroughUICount = count;
    final int configRepoAdditionThreadCount = count;
    final int configRepoDeletionThreadCount = count;
    final int fullConfigSaveThreadCount = count;
    for (int i = 0; i < pipelineCreatedThroughUICount; i++) {
        Thread thread = configSaveThread(i);
        group1.add(thread);
    }
    for (int i = 0; i < pipelineCreatedThroughApiCount; i++) {
        Thread thread = pipelineSaveThread(i);
        group2.add(thread);
    }
    ConfigReposConfig configRepos = new ConfigReposConfig();
    for (int i = 0; i < configRepoAdditionThreadCount; i++) {
        ConfigRepoConfig configRepoConfig = ConfigRepoConfig.createConfigRepoConfig(git("url" + i), "plugin", "id-" + i);
        configRepoConfig.getRules().add(new Allow("refer", "*", "*"));
        configRepos.add(configRepoConfig);
        Thread thread = configRepoSaveThread(configRepoConfig, i);
        group3.add(thread);
    }
    for (int i = 0; i < configRepoDeletionThreadCount; i++) {
        ConfigRepoConfig configRepoConfig = ConfigRepoConfig.createConfigRepoConfig(git("to-be-deleted-url" + i), "plugin", "to-be-deleted-" + i);
        cachedGoPartials.cacheAsLastKnown(configRepoConfig.getRepo().getFingerprint(), PartialConfigMother.withPipeline("to-be-deleted" + i, new RepoConfigOrigin(configRepoConfig, "plugin")));
        configRepos.add(configRepoConfig);
        Thread thread = configRepoDeleteThread(configRepoConfig, i);
        group4.add(thread);
    }
    for (int i = 0; i < fullConfigSaveThreadCount; i++) {
        Thread thread = fullConfigSaveThread(i);
        group5.add(thread);
    }
    configHelper.setConfigRepos(configRepos);
    for (int i = 0; i < count; i++) {
        Thread timerThread = null;
        try {
            timerThread = createThread(new Runnable() {

                @Override
                public void run() {
                    try {
                        writeConfigToFile(new File(goConfigDao.fileLocation()));
                    } catch (Exception e) {
                        e.printStackTrace();
                        fail("Failed with error: " + e.getMessage());
                    }
                    cachedGoConfig.forceReload();
                }
            }, "timer-thread");
        } catch (InterruptedException e) {
            fail(e.getMessage());
        }
        try {
            group1.get(i).start();
            group2.get(i).start();
            group3.get(i).start();
            group4.get(i).start();
            group5.get(i).start();
            timerThread.start();
            group1.get(i).join();
            group2.get(i).join();
            group3.get(i).join();
            group4.get(i).join();
            group5.get(i).join();
            timerThread.join();
        } catch (InterruptedException e) {
            fail(e.getMessage());
        }
    }
    assertThat(goConfigService.getAllPipelineConfigs().size(), is(pipelineCreatedThroughApiCount + pipelineCreatedThroughUICount + configRepoAdditionThreadCount));
    assertThat(goConfigService.getConfigForEditing().getAllPipelineConfigs().size(), is(pipelineCreatedThroughApiCount + pipelineCreatedThroughUICount));
    assertThat(goConfigService.getConfigForEditing().getEnvironments().size(), is(fullConfigSaveThreadCount + EXISTING_ENV_COUNT));
}
Also used : ConfigReposConfig(com.thoughtworks.go.config.remote.ConfigReposConfig) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) ArrayList(java.util.ArrayList) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) File(java.io.File) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) Allow(com.thoughtworks.go.config.rules.Allow) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Aggregations

ConfigReposConfig (com.thoughtworks.go.config.remote.ConfigReposConfig)30 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)18 Test (org.junit.jupiter.api.Test)17 ScmMaterialConfig (com.thoughtworks.go.config.materials.ScmMaterialConfig)14 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)7 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)6 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)5 File (java.io.File)4 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)3 ConfigRepoService (com.thoughtworks.go.server.service.ConfigRepoService)2 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ApiController (com.thoughtworks.go.api.ApiController)1 ApiVersion (com.thoughtworks.go.api.ApiVersion)1 CrudController (com.thoughtworks.go.api.CrudController)1 OutputWriter (com.thoughtworks.go.api.base.OutputWriter)1 JsonReader (com.thoughtworks.go.api.representers.JsonReader)1 ApiAuthenticationHelper (com.thoughtworks.go.api.spring.ApiAuthenticationHelper)1 GsonTransformer (com.thoughtworks.go.api.util.GsonTransformer)1 HaltApiResponses.haltBecauseEntityAlreadyExists (com.thoughtworks.go.api.util.HaltApiResponses.haltBecauseEntityAlreadyExists)1