use of com.thoughtworks.go.config.exceptions.GoConfigInvalidException in project gocd by gocd.
the class GoFileConfigDataSourceTest method shouldReloadConfigUsingFullSaveNormalFlowWithLastValidPartialsIfUpdatingWithLastKnownPartialsFails_onLoad.
@Test
public void shouldReloadConfigUsingFullSaveNormalFlowWithLastValidPartialsIfUpdatingWithLastKnownPartialsFails_onLoad() throws Exception {
systemEnvironment.setProperty(SystemEnvironment.OPTIMIZE_FULL_CONFIG_SAVE.propertyName(), "y");
GoConfigFileReader goConfigFileReader = mock(GoConfigFileReader.class);
MagicalGoConfigXmlLoader loader = mock(MagicalGoConfigXmlLoader.class);
CruiseConfig cruiseConfig = mock(CruiseConfig.class);
PartialConfigMother.withPipeline("P1");
List lastKnownPartials = Arrays.asList(PartialConfigMother.withPipeline("P1"));
List lastValidPartials = Arrays.asList(PartialConfigMother.withPipeline("P2"), PartialConfigMother.withPipeline("P3"));
CachedGoPartials cachedGoPartials = mock(CachedGoPartials.class);
GoConfigHolder goConfigHolder = new GoConfigHolder(new BasicCruiseConfig(), new BasicCruiseConfig());
ArgumentCaptor<FullConfigUpdateCommand> commandArgumentCaptor = ArgumentCaptor.forClass(FullConfigUpdateCommand.class);
ArgumentCaptor<List> listArgumentCaptor = ArgumentCaptor.forClass(List.class);
ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class);
when(goConfigFileReader.fileLocation()).thenReturn(new File(""));
when(goConfigFileReader.configXml()).thenReturn("config_xml");
when(loader.deserializeConfig("config_xml")).thenReturn(cruiseConfig);
when(cachedGoPartials.lastKnownPartials()).thenReturn(lastKnownPartials);
when(cachedGoPartials.lastValidPartials()).thenReturn(lastValidPartials);
when(fullConfigSaveNormalFlow.execute(commandArgumentCaptor.capture(), listArgumentCaptor.capture(), stringArgumentCaptor.capture())).thenThrow(new GoConfigInvalidException(null, null)).thenReturn(goConfigHolder);
GoFileConfigDataSource source = new GoFileConfigDataSource(null, null, systemEnvironment, null, null, loader, null, null, cachedGoPartials, fullConfigSaveMergeFlow, fullConfigSaveNormalFlow, goConfigFileReader, null);
GoConfigHolder configHolder = source.load();
assertThat(configHolder, is(goConfigHolder));
assertThat(commandArgumentCaptor.getValue().configForEdit(), is(cruiseConfig));
assertThat(listArgumentCaptor.getValue(), is(lastValidPartials));
assertThat(stringArgumentCaptor.getValue(), is("Filesystem"));
}
use of com.thoughtworks.go.config.exceptions.GoConfigInvalidException in project gocd by gocd.
the class GoFileConfigDataSourceTest method shouldNotRetryConfigUpdateIfLastKnownPartialsAreEmpty_OnWriteFullConfigWithLock.
@Test(expected = RuntimeException.class)
public void shouldNotRetryConfigUpdateIfLastKnownPartialsAreEmpty_OnWriteFullConfigWithLock() throws Exception {
List<PartialConfig> known = new ArrayList<>();
BasicCruiseConfig configForEdit = new BasicCruiseConfig();
MagicalGoConfigXmlLoader.setMd5(configForEdit, "md5");
FullConfigUpdateCommand updatingCommand = new FullConfigUpdateCommand(new BasicCruiseConfig(), "md5");
GoConfigHolder configHolder = new GoConfigHolder(new BasicCruiseConfig(), configForEdit);
CachedGoPartials cachedGoPartials = mock(CachedGoPartials.class);
GoFileConfigDataSource source = new GoFileConfigDataSource(null, null, systemEnvironment, null, null, null, null, null, cachedGoPartials, fullConfigSaveMergeFlow, fullConfigSaveNormalFlow);
stub(cachedGoPartials.lastKnownPartials()).toReturn(known);
when(fullConfigSaveNormalFlow.execute(updatingCommand, known, "loser_boozer")).thenThrow(new GoConfigInvalidException(configForEdit, "error"));
source.writeFullConfigWithLock(updatingCommand, configHolder);
}
Aggregations