@Before public void setup() throws Exception { diskSpaceSimulator = new DiskSpaceSimulator(); new HgTestRepo("testHgRepo"); svnRepository = new SvnTestRepo("testSvnRepo"); dbHelper.onSetUp(); configHelper.onSetUp(); configHelper.usingCruiseConfigDao(goConfigDao).initializeConfigFile(); repository = new SvnCommand(null, svnRepository.projectRepositoryUrl()); goParentPipelineConfig = configHelper.addPipeline( GO_PIPELINE_UPSTREAM, STAGE_NAME, new MaterialConfigs(new GitMaterialConfig("foo-bar")), "unit"); goPipelineConfig = configHelper.addPipeline(GO_PIPELINE_NAME, STAGE_NAME, repository, "unit"); svnMaterialRevs = new MaterialRevisions(); SvnMaterial svnMaterial = SvnMaterial.createSvnMaterialWithMock(repository); svnMaterialRevs.addRevision( svnMaterial, svnMaterial.latestModification( null, new ServerSubprocessExecutionContext(goConfigService, new SystemEnvironment()))); final MaterialRevisions materialRevisions = new MaterialRevisions(); SvnMaterial anotherSvnMaterial = SvnMaterial.createSvnMaterialWithMock(repository); materialRevisions.addRevision( anotherSvnMaterial, anotherSvnMaterial.latestModification(null, subprocessExecutionContext)); transactionTemplate.execute( new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { materialRepository.save(svnMaterialRevs); } }); BuildCause buildCause = BuildCause.createWithModifications(svnMaterialRevs, ""); mingleConfig = configHelper.addPipeline( MINGLE_PIPELINE_NAME, STAGE_NAME, repository, new Filter(new IgnoredFiles("**/*.doc")), "unit", "functional"); latestPipeline = PipelineMother.schedule(this.mingleConfig, buildCause); latestPipeline = pipelineDao.saveWithStages(latestPipeline); dbHelper.passStage(latestPipeline.getStages().first()); pipelineScheduleQueue.clear(); }
private void prepareAPipelineWithHistory() throws SQLException { MaterialRevisions materialRevisions = new MaterialRevisions(); List<Modification> modifications = this.hgMaterial.latestModification(workingFolder, subprocessExecutionContext); materialRevisions.addRevision(this.hgMaterial, modifications); BuildCause buildCause = BuildCause.createWithModifications(materialRevisions, ""); latestPipeline = PipelineMother.schedule(mingleConfig, buildCause); latestPipeline = dbHelper.savePipelineWithStagesAndMaterials(latestPipeline); dbHelper.passStage(latestPipeline.getStages().first()); }
private Pipeline passFirstStage(PipelineConfig pipelineConfig) { Stage completedMingleStage = stageDao.mostRecentWithBuilds( CaseInsensitiveString.str(pipelineConfig.name()), pipelineConfig.findBy(new CaseInsensitiveString("dev"))); dbHelper.passStage(completedMingleStage); dbHelper.passStage(completedMingleStage); assertThat(completedMingleStage.getJobInstances().first().getState(), is(JobState.Completed)); Pipeline pipeline = pipelineDao.mostRecentPipeline(CaseInsensitiveString.str(pipelineConfig.name())); return dbHelper.passPipeline(pipeline); }
@After public void teardown() throws Exception { dbHelper.onTearDown(); preCondition.onTearDown(); pipelineScheduleQueue.clear(); configHelper.onTearDown(); }
@Before public void setup() throws Exception { configHelper = new GoConfigFileHelper(); configHelper.usingCruiseConfigDao(goConfigDao); configHelper.onSetUp(); testRepo = new SvnTestRepo("testSvnRepo"); dbHelper.onSetUp(); repository = new SvnCommand(null, testRepo.projectRepositoryUrl()); mingleConfig = configHelper.addPipeline("mingle", STAGE_NAME, repository, "unit", "functional"); goConfig = configHelper.addPipeline("go", STAGE_NAME, repository, "unit"); StageConfig ftStageConfig = StageConfigMother.custom("ft", "twist"); ftStageConfig .jobConfigByConfigName(new CaseInsensitiveString("twist")) .addVariable("JOB_LVL", "job value"); ftStageConfig.setVariables(env("STAGE_LVL", "stage value")); configHelper.addStageToPipeline("go", ftStageConfig); configHelper.addEnvironmentVariableToPipeline("go", env("PIPELINE_LVL", "pipeline value")); configHelper.addEnvironments("uat"); EnvironmentConfig uatEnv = configHelper.currentConfig().getEnvironments().named(new CaseInsensitiveString("uat")); uatEnv.addPipeline(new CaseInsensitiveString("go")); uatEnv.addEnvironmentVariable("ENV_LVL", "env value"); evolveConfig = configHelper.addPipeline("evolve", STAGE_NAME, repository, "unit"); goCache.clear(); }
@Test public void shouldLockPipelineWhenSchedulingIt() throws Exception { scheduleAndCompleteInitialPipelines(); configHelper.lockPipeline("mingle"); Material stubMaterial = new TestingMaterial(); mingleConfig.setMaterialConfigs(new MaterialConfigs(stubMaterial.config())); assertThat(pipelineLockService.isLocked("mingle"), is(false)); MaterialRevisions revisions = new MaterialRevisions(); revisions.addRevision( stubMaterial, ((TestingMaterial) stubMaterial) .modificationsSince(null, null, subprocessExecutionContext)); BuildCause buildCause = BuildCause.createWithModifications(revisions, ""); dbHelper.saveMaterials(buildCause.getMaterialRevisions()); Pipeline pipeline = instanceFactory.createPipelineInstance( mingleConfig, buildCause, new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider()); pipelineService.save(pipeline); assertThat(pipelineLockService.isLocked("mingle"), is(true)); }
@Test public void shouldForceStagePlanWithModificationsSinceLast() throws Exception { Pipeline completedMingle = scheduleAndCompleteInitialPipelines(); pipelineDao.loadPipeline(completedMingle.getId()); TestingMaterial testingMaterial = new TestingMaterial(); mingleConfig.setMaterialConfigs(new MaterialConfigs(testingMaterial.config())); MaterialRevisions revisions = new MaterialRevisions(); revisions.addRevision( testingMaterial, testingMaterial.modificationsSince(null, null, subprocessExecutionContext)); BuildCause buildCause = BuildCause.createManualForced(revisions, Username.ANONYMOUS); dbHelper.saveMaterials(buildCause.getMaterialRevisions()); Pipeline forcedPipeline = instanceFactory.createPipelineInstance( mingleConfig, buildCause, new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider()); pipelineService.save(forcedPipeline); verifyMingleScheduledWithModifications(); }
@Test public void shouldNotScheduleActivePipeline() throws Exception { Pipeline pipeline = PipelineMother.building(mingleConfig); pipeline = dbHelper.savePipelineWithStagesAndMaterials(pipeline); Pipeline newPipeline = manualSchedule(CaseInsensitiveString.str(mingleConfig.name())); assertThat(newPipeline.getId(), is(pipeline.getId())); }
@After public void tearDown() throws Exception { configHelper.onTearDown(); dbHelper.onTearDown(); TestRepo.internalTearDown(); cleanupTempFolders(); }
@Before public void setUp() throws Exception { dbHelper.onSetUp(); configHelper = new GoConfigFileHelper(goConfigDao); configHelper.onSetUp(); configHelper.addPipeline( "bar", "stage", MaterialConfigsMother.defaultMaterialConfigs(), "build"); pipelineConfig = configHelper.addPipeline( "foo", "stage", MaterialConfigsMother.defaultMaterialConfigs(), "build"); configHelper.addMingleConfigToPipeline( "foo", new MingleConfig("https://some-tracking-tool:8443", "project-super-secret", "hello=world")); CruiseConfig cruiseConfig = configHelper.load(); PipelineConfigs group = cruiseConfig.findGroup("defaultGroup"); group.setAuthorization( new Authorization( new ViewConfig(new AdminUser(new CaseInsensitiveString("authorized_user"))))); configHelper.writeConfigFile(cruiseConfig); SecurityConfig securityConfig = new SecurityConfig( new LdapConfig(new GoCipher()), new PasswordFileConfig("/tmp/foo.passwd"), true); securityConfig.adminsConfig().add(new AdminUser(new CaseInsensitiveString("admin"))); configHelper.addSecurity(securityConfig); }
@After public void teardown() throws Exception { dbHelper.onTearDown(); fixture.onTearDown(); configHelper.onTearDown(); resetSecurityContext(); }
private Pipeline tryToScheduleAPipeline() { BuildCause buildCause = BuildCause.createWithModifications(modifyOneFile(preCondition.pipelineConfig()), ""); dbHelper.saveMaterials(buildCause.getMaterialRevisions()); pipelineScheduleQueue.schedule(preCondition.pipelineName, buildCause); scheduleService.autoSchedulePipelinesFromRequestBuffer(); return pipelineService.mostRecentFullPipelineByName(preCondition.pipelineName); }
@After public void teardown() throws Exception { diskSpaceSimulator.onTearDown(); TestRepo.internalTearDown(); dbHelper.onTearDown(); pipelineScheduleQueue.clear(); configHelper.onTearDown(); }
@After public void teardown() throws Exception { dbHelper.onTearDown(); FileUtil.deleteFolder(goConfigService.artifactsDir()); pipelineScheduleQueue.clear(); agentAssignment.clear(); CONFIG_HELPER.onTearDown(); }
@Before public void setup() throws Exception { configHelper = new GoConfigFileHelper(goConfigDao); dbHelper.onSetUp(); goCache.clear(); configHelper.onSetUp(); svnRepo = new SvnTestRepoWithExternal(); cleanupTempFolders(); }
@After public void teardown() throws Exception { TestRepo.internalTearDown(); dbHelper.onTearDown(); FileUtil.deleteFolder(goConfigService.artifactsDir()); FileUtil.deleteFolder(workingFolder); TestRepo.internalTearDown(); pipelineScheduleQueue.clear(); }
@Before public void setUp() throws Exception { preCondition = new PipelineWithTwoStages(materialRepository, transactionTemplate); configHelper.usingCruiseConfigDao(goConfigFileDao); configHelper.onSetUp(); dbHelper.onSetUp(); preCondition.usingConfigHelper(configHelper).usingDbHelper(dbHelper).onSetUp(); }
@After public void teardown() throws Exception { goCache.clear(); agentService.clearAll(); fixture.onTearDown(); dbHelper.onTearDown(); configHelper.onTearDown(); FileUtil.deleteFolder(goConfigService.artifactsDir()); agentAssignment.clear(); agentRemoteHandler.connectedAgents().clear(); }
@After public void teardown() throws Exception { if (pipelineWithTwoStages != null) { pipelineWithTwoStages.onTearDown(); } dbHelper.onTearDown(); pipelineScheduleQueue.clear(); testRepo.tearDown(); FileUtil.deleteFolder(new File("pipelines")); configHelper.onTearDown(); }
@Before public void setUp() throws Exception { fixture = new PipelineWithMultipleStages(3, materialRepository, transactionTemplate); configHelper.usingCruiseConfigDao(goConfigFileDao); configHelper.onSetUp(); dbHelper.onSetUp(); fixture.usingConfigHelper(configHelper).usingDbHelper(dbHelper).onSetUp(); goConfigService.forceNotifyListeners(); request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); }
@Test public void shouldScheduleJobForAllAgentsWhenToBeRunOnAllAgents() throws Exception { configHelper.addAgent("localhost", "uuid1"); configHelper.addAgent("localhost", "uuid2"); configHelper.addAgent("localhost", "uuid3"); configHelper.addAgentToEnvironment("dev", "uuid1"); configHelper.setRunOnAllAgents( CaseInsensitiveString.str(evolveConfig.name()), STAGE_NAME, "unit", true); Material stubMaterial = new TestingMaterial(); evolveConfig.setMaterialConfigs(new MaterialConfigs(stubMaterial.config())); MaterialRevisions revisions = new MaterialRevisions(); revisions.addRevision( stubMaterial, ((TestingMaterial) stubMaterial) .modificationsSince(null, null, subprocessExecutionContext)); BuildCause buildCause = BuildCause.createWithModifications(revisions, ""); dbHelper.saveMaterials(buildCause.getMaterialRevisions()); Pipeline pipeline = instanceFactory.createPipelineInstance( evolveConfig, buildCause, new DefaultSchedulingContext( DEFAULT_APPROVED_BY, environmentConfigService.agentsForPipeline(evolveConfig.name())), md5, new TimeProvider()); pipelineService.save(pipeline); Stage instance = scheduleService.scheduleStage( pipeline, STAGE_NAME, "anyone", new ScheduleService.NewStageInstanceCreator(goConfigService), new ScheduleService.ExceptioningErrorHandler()); JobInstances scheduledJobs = instance.getJobInstances(); assertThat( scheduledJobs.toArray(), hasItemInArray( hasProperty( "name", is(RunOnAllAgents.CounterBasedJobNameGenerator.appendMarker("unit", 1))))); assertThat(scheduledJobs.toArray(), hasItemInArray(hasProperty("agentUuid", is("uuid2")))); assertThat( scheduledJobs.toArray(), hasItemInArray( hasProperty( "name", is(RunOnAllAgents.CounterBasedJobNameGenerator.appendMarker("unit", 2))))); assertThat(scheduledJobs.toArray(), hasItemInArray(hasProperty("agentUuid", is("uuid3")))); assertThat(scheduledJobs.size(), is(2)); }
@Before public void setup() throws Exception { dbHelper.onSetUp(); configHelper.onSetUp(); configHelper.usingCruiseConfigDao(goConfigDao).initializeConfigFile(); hgTestRepo = new HgTestRepo("hgTestRepo1"); hgMaterial = MaterialsMother.hgMaterial(hgTestRepo.projectRepositoryUrl()); hgMaterial.setFilter(new Filter(new IgnoredFiles("helper/**/*.*"))); workingFolder = TestFileUtil.createTempFolder("workingFolder"); outputStreamConsumer = inMemoryConsumer(); mingleConfig = configHelper.addPipeline( "cruise", STAGE_NAME, this.hgMaterial.config(), "unit", "functional"); }
@Before public void setup() throws Exception { configHelper = new GoConfigFileHelper(); dbHelper.onSetUp(); configHelper.usingCruiseConfigDao(goConfigDao).initializeConfigFile(); configHelper.onSetUp(); goConfigService.forceNotifyListeners(); File dumpDir = tempFolder.newFolder("perf-pipelineapi-test"); FileUtil.deleteDirectoryNoisily(dumpDir); dumpDir.mkdirs(); result = new HttpLocalizedOperationResult(); user = new Username(new CaseInsensitiveString("admin")); consoleAppenderForPerformanceTest = "ConsoleAppenderForPerformanceTest"; rollingFileAppenderForPerformanceTest = "RollingFileAppenderForPerformanceTest"; }
private Pipeline createAndLoadModifyOneFilePipeline(PipelineConfig pipelineConfig) { MaterialConfigs expandedConfigs = materialExpansionService.expandMaterialConfigsForScheduling( pipelineConfig.materialConfigs()); MaterialRevisions materialRevisions = ModificationsMother.modifyOneFile( MaterialsMother.createMaterialsFromMaterialConfigs(expandedConfigs)); Pipeline building = PipelineMother.buildingWithRevisions(pipelineConfig, materialRevisions); Pipeline pipeline = dbHelper.savePipelineWithMaterials(building); final long jobId = pipeline.getStages().get(0).getJobInstances().get(0).getId(); return (Pipeline) transactionTemplate.execute( new TransactionCallback() { public Object doInTransaction(TransactionStatus status) { return loader.pipelineWithPasswordAwareBuildCauseByBuildId(jobId); } }); }
@Test public void should_NOT_schedulePipeline_whenOneOfTheMaterialsHasNoModificationsPresent() throws Exception { Pipeline latestGoInstance = PipelineMother.schedule( goPipelineConfig, BuildCause.createManualForced( svnMaterialRevs, new Username(new CaseInsensitiveString("loser")))); latestGoInstance = pipelineDao.saveWithStages(latestGoInstance); dbHelper.passStage(latestGoInstance.getStages().first()); configHelper.addMaterialToPipeline( GO_PIPELINE_NAME, new DependencyMaterialConfig( new CaseInsensitiveString(GO_PIPELINE_UPSTREAM), new CaseInsensitiveString(STAGE_NAME))); svnRepository.checkInOneFile("a.java"); scheduleHelper.autoSchedulePipelinesWithRealMaterials(GO_PIPELINE_NAME); assertThat(pipelineScheduleQueue.toBeScheduled().keySet(), not(hasItem(GO_PIPELINE_NAME))); }
@Before public void setUp() throws Exception { configHelper = new GoConfigFileHelper().usingCruiseConfigDao(goConfigDao); configHelper.onSetUp(); dbHelper.onSetUp(); fixture = new PipelineWithTwoStages(materialRepository, transactionTemplate); fixture.usingConfigHelper(configHelper).usingDbHelper(dbHelper).onSetUp(); repository = new SvnCommand(null, testRepo.projectRepositoryUrl()); evolveConfig = configHelper.addPipeline("evolve", STAGE_NAME, repository, "unit"); configHelper.addPipeline("anotherPipeline", STAGE_NAME, repository, "anotherTest"); configHelper.addPipeline("thirdPipeline", STAGE_NAME, repository, "yetAnotherTest"); goConfigService.forceNotifyListeners(); goCache.clear(); u = new ScheduleTestUtil(transactionTemplate, materialRepository, dbHelper, configHelper); agent = new AgentStub(); }
@Test public void shouldNotScheduleBuildIfNoModification() throws Exception { autoSchedulePipelines("mingle", "evolve"); // Get the scheduled evolve stage and complete it. Stage evolveInstance = stageDao.mostRecentWithBuilds( CaseInsensitiveString.str(evolveConfig.name()), evolveConfig.findBy(new CaseInsensitiveString("dev"))); dbHelper.passStage(evolveInstance); stageDao.stageStatusChanged(evolveInstance); autoSchedulePipelines(); Stage mostRecent = stageDao.mostRecentWithBuilds( CaseInsensitiveString.str(evolveConfig.name()), evolveConfig.findBy(new CaseInsensitiveString("dev"))); assertThat(mostRecent.getId(), is(evolveInstance.getId())); assertThat(mostRecent.getJobInstances().first().getState(), is(JobState.Completed)); }
@Test public void shouldNotAssignCancelledJob() throws Exception { AgentIdentifier instance = agent(AgentMother.localAgent()); Pipeline pipeline = instanceFactory.createPipelineInstance( evolveConfig, modifyNoFiles(evolveConfig), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider()); dbHelper.savePipelineWithStagesAndMaterials(pipeline); buildAssignmentService.onConfigChange(goConfigService.getCurrentConfig()); JobInstance job = buildOf(pipeline); job.cancel(); jobInstanceDao.updateStateAndResult(job); assertThat( buildAssignmentService.assignWorkToAgent(instance), is((Work) BuildAssignmentService.NO_WORK)); }
@Test public void shouldNotAssignWorkWhenPipelineScheduledWithStaleMaterials() { AgentIdentifier instance = agent(AgentMother.localAgent()); Pipeline pipeline = instanceFactory.createPipelineInstance( evolveConfig, modifyNoFiles(evolveConfig), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider()); dbHelper.savePipelineWithStagesAndMaterials(pipeline); evolveConfig.setMaterialConfigs(new MaterialConfigs(new HgMaterialConfig("foo", null))); configHelper.removePipeline(CaseInsensitiveString.str(evolveConfig.name())); configHelper.addPipeline(evolveConfig); buildAssignmentService.onConfigChange(goConfigService.getCurrentConfig()); JobInstance job = buildOf(pipeline); jobInstanceDao.updateStateAndResult(job); assertThat( buildAssignmentService.assignWorkToAgent(instance), is((Work) BuildAssignmentService.NO_WORK)); }
@Test public void shouldCreateWorkWithFetchMaterialsFlagFromStageConfig() throws Exception { evolveConfig.getFirstStageConfig().setFetchMaterials(true); Pipeline pipeline1 = instanceFactory.createPipelineInstance( evolveConfig, modifySomeFiles(evolveConfig), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider()); dbHelper.savePipelineWithStagesAndMaterials(pipeline1); buildAssignmentService.onTimer(); BuildWork work = (BuildWork) buildAssignmentService.assignWorkToAgent(agent(AgentMother.localAgent())); assertThat( "should have set fetchMaterials on assignment", work.getAssignment().getPlan().shouldFetchMaterials(), is(true)); }