Search in sources :

Example 16 with GoConfigInvalidException

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"));
}
Also used : StringContains.containsString(org.hamcrest.core.StringContains.containsString) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) Arrays.asList(java.util.Arrays.asList) File(java.io.File) Test(org.junit.Test)

Example 17 with GoConfigInvalidException

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);
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) Test(org.junit.Test)

Aggregations

GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)17 Test (org.junit.Test)13 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)4 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)4 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)4 Packages (com.thoughtworks.go.domain.packagerepository.Packages)4 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)3 FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)3 ConfigErrors (com.thoughtworks.go.domain.ConfigErrors)3 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)2 SCM (com.thoughtworks.go.domain.scm.SCM)2 SCMs (com.thoughtworks.go.domain.scm.SCMs)2 IOException (java.io.IOException)2 StringContains.containsString (org.hamcrest.core.StringContains.containsString)2 AgentConfig (com.thoughtworks.go.config.AgentConfig)1 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)1 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)1 ConfigMergeException (com.thoughtworks.go.config.exceptions.ConfigMergeException)1 GoConfigInvalidMergeException (com.thoughtworks.go.config.exceptions.GoConfigInvalidMergeException)1 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)1