Search in sources :

Example 16 with Allow

use of com.thoughtworks.go.config.rules.Allow 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)

Example 17 with Allow

use of com.thoughtworks.go.config.rules.Allow in project gocd by gocd.

the class PipelineConfigServiceIntegrationTest method createConfigRepoWithDefaultRules.

private ConfigRepoConfig createConfigRepoWithDefaultRules(GitMaterialConfig materialConfig, String plugin, String id) {
    ConfigRepoConfig config = ConfigRepoConfig.createConfigRepoConfig(materialConfig, plugin, id);
    config.getRules().add(new Allow("refer", "*", "*"));
    return config;
}
Also used : ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) Allow(com.thoughtworks.go.config.rules.Allow)

Aggregations

Allow (com.thoughtworks.go.config.rules.Allow)17 Test (org.junit.jupiter.api.Test)10 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)9 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)5 PipelineGroups (com.thoughtworks.go.domain.PipelineGroups)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Rules (com.thoughtworks.go.config.rules.Rules)3 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)2 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)2 ConfigTestRepo (com.thoughtworks.go.helper.ConfigTestRepo)2 HgTestRepo (com.thoughtworks.go.helper.HgTestRepo)2 GoDiskSpaceMonitor (com.thoughtworks.go.server.cronjob.GoDiskSpaceMonitor)2 File (java.io.File)2 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 Materials (com.thoughtworks.go.config.materials.Materials)1 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)1 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)1 ConfigReposConfig (com.thoughtworks.go.config.remote.ConfigReposConfig)1 Deny (com.thoughtworks.go.config.rules.Deny)1 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)1