Search in sources :

Example 1 with ConfigMergeException

use of com.thoughtworks.go.config.exceptions.ConfigMergeException in project gocd by gocd.

the class GoFileConfigDataSourceTest method shouldThrowConfigMergeExceptionWhenConfigMergeFeatureIsTurnedOff.

@Test
public void shouldThrowConfigMergeExceptionWhenConfigMergeFeatureIsTurnedOff() throws Exception {
    String firstMd5 = dataSource.forceLoad(dataSource.fileLocation()).configForEdit.getMd5();
    goConfigDao.updateConfig(configHelper.addPipelineCommand(firstMd5, "p0", "s0", "b0"));
    String originalMd5 = dataSource.forceLoad(dataSource.fileLocation()).configForEdit.getMd5();
    goConfigDao.updateConfig(configHelper.addPipelineCommand(originalMd5, "p1", "s1", "j1"));
    GoConfigHolder goConfigHolder = dataSource.forceLoad(dataSource.fileLocation());
    systemEnvironment.set(SystemEnvironment.ENABLE_CONFIG_MERGE_FEATURE, Boolean.FALSE);
    try {
        dataSource.writeWithLock(configHelper.changeJobNameCommand(originalMd5, "p0", "s0", "b0", "j0"), goConfigHolder);
        fail("Should throw ConfigMergeException");
    } catch (RuntimeException e) {
        ConfigMergeException cme = (ConfigMergeException) e.getCause();
        assertThat(cme.getMessage(), is(ConfigFileHasChangedException.CONFIG_CHANGED_PLEASE_REFRESH));
    }
}
Also used : StringContains.containsString(org.hamcrest.core.StringContains.containsString) ConfigMergeException(com.thoughtworks.go.config.exceptions.ConfigMergeException) Test(org.junit.Test)

Example 2 with ConfigMergeException

use of com.thoughtworks.go.config.exceptions.ConfigMergeException in project gocd by gocd.

the class GoFileConfigDataSourceTest method shouldPropagateConfigHasChangedException.

@Test
public void shouldPropagateConfigHasChangedException() throws Exception {
    String originalMd5 = dataSource.forceLoad(dataSource.fileLocation()).configForEdit.getMd5();
    goConfigDao.updateConfig(configHelper.addPipelineCommand(originalMd5, "p1", "s1", "b1"));
    GoConfigHolder goConfigHolder = dataSource.forceLoad(dataSource.fileLocation());
    try {
        dataSource.writeWithLock(configHelper.addPipelineCommand(originalMd5, "p2", "s", "b"), goConfigHolder);
        fail("Should throw ConfigFileHasChanged exception");
    } catch (Exception e) {
        assertThat(e.getCause().getClass().getName(), e.getCause() instanceof ConfigMergeException, is(true));
    }
}
Also used : StringContains.containsString(org.hamcrest.core.StringContains.containsString) ConfigFileHasChangedException(com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) ExpectedException(org.junit.rules.ExpectedException) ConfigMergeException(com.thoughtworks.go.config.exceptions.ConfigMergeException) IOException(java.io.IOException) ConfigMergeException(com.thoughtworks.go.config.exceptions.ConfigMergeException) Test(org.junit.Test)

Example 3 with ConfigMergeException

use of com.thoughtworks.go.config.exceptions.ConfigMergeException in project gocd by gocd.

the class ConfigRepository method getConfigMergedWithLatestRevision.

public String getConfigMergedWithLatestRevision(GoConfigRevision configRevision, String oldMD5) throws Exception {
    try {
        LOGGER.debug("[Config Save] Starting git merge of config");
        createBranch(BRANCH_AT_REVISION, getRevCommitForMd5(oldMD5));
        createBranch(BRANCH_AT_HEAD, getCurrentRevCommit());
        RevCommit newCommit = checkinToBranch(BRANCH_AT_REVISION, configRevision);
        return getMergedConfig(BRANCH_AT_HEAD, newCommit);
    } catch (Exception e) {
        LOGGER.info("[CONFIG_MERGE] Could not merge");
        throw new ConfigMergeException(e.getMessage(), e);
    } finally {
        cleanAndResetToMaster();
        LOGGER.debug("[Config Save] Ending git merge of config");
    }
}
Also used : ConfigFileHasChangedException(com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) NullArgumentException(org.apache.commons.lang.NullArgumentException) ConfigMergeException(com.thoughtworks.go.config.exceptions.ConfigMergeException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) ConfigMergeException(com.thoughtworks.go.config.exceptions.ConfigMergeException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 4 with ConfigMergeException

use of com.thoughtworks.go.config.exceptions.ConfigMergeException in project gocd by gocd.

the class FullConfigSaveMergeFlowTest method shouldErrorOutIfConfigMergeFails.

@Test(expected = ConfigMergeException.class)
public void shouldErrorOutIfConfigMergeFails() throws Exception {
    when(writer.documentFrom(configForEdit)).thenReturn(document);
    when(writer.toString(document)).thenReturn("cruise_config");
    when(configRepository.getConfigMergedWithLatestRevision(any(GoConfigRevision.class), anyString())).thenThrow(new ConfigMergeException("merge fails"));
    flow.execute(updateConfigCommand, partials, null);
}
Also used : GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) ConfigMergeException(com.thoughtworks.go.config.exceptions.ConfigMergeException) Test(org.junit.Test)

Example 5 with ConfigMergeException

use of com.thoughtworks.go.config.exceptions.ConfigMergeException in project gocd by gocd.

the class ConfigRepositoryTest method shouldThrowExceptionWhenThereIsMergeConflict.

@Test
public void shouldThrowExceptionWhenThereIsMergeConflict() throws Exception {
    String original = "first\nsecond\n";
    String nextUpdate = "1st\nsecond\n";
    String latestUpdate = "2nd\nsecond\n";
    configRepo.checkin(goConfigRevision(original, "md5-1"));
    configRepo.checkin(goConfigRevision(nextUpdate, "md5-2"));
    RevCommit currentRevCommitOnMaster = configRepo.getCurrentRevCommit();
    try {
        configRepo.getConfigMergedWithLatestRevision(goConfigRevision(latestUpdate, "md5-3"), "md5-1");
        fail("should have bombed for merge conflict");
    } catch (ConfigMergeException e) {
        assertThat(e.getMessage(), is(ConfigFileHasChangedException.CONFIG_CHANGED_PLEASE_REFRESH));
    }
    List<Ref> branches = getAllBranches();
    assertThat(branches.size(), is(1));
    assertThat(branches.get(0).getName().endsWith("master"), is(true));
    assertThat(configRepo.getCurrentRevCommit(), is(currentRevCommitOnMaster));
}
Also used : Ref(org.eclipse.jgit.lib.Ref) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ConfigMergeException(com.thoughtworks.go.config.exceptions.ConfigMergeException) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

ConfigMergeException (com.thoughtworks.go.config.exceptions.ConfigMergeException)5 Test (org.junit.Test)4 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)2 IOException (java.io.IOException)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 StringContains.containsString (org.hamcrest.core.StringContains.containsString)2 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)1 GoConfigRevision (com.thoughtworks.go.domain.GoConfigRevision)1 NullArgumentException (org.apache.commons.lang.NullArgumentException)1 IncorrectObjectTypeException (org.eclipse.jgit.errors.IncorrectObjectTypeException)1 MissingObjectException (org.eclipse.jgit.errors.MissingObjectException)1 Ref (org.eclipse.jgit.lib.Ref)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 ExpectedException (org.junit.rules.ExpectedException)1