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));
}
}
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));
}
}
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");
}
}
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);
}
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));
}
Aggregations