/** Scenario: loads on one label shouldn't translate to load on another label. */ public void testLabels() throws Exception { BulkChange bc = new BulkChange(hudson); try { DummyCloudImpl cloud = initHudson(0); Label blue = hudson.getLabel("blue"); Label red = hudson.getLabel("red"); cloud.label = red; // red jobs List<FreeStyleProject> redJobs = create5SlowJobs(new Latch(5)); for (FreeStyleProject p : redJobs) p.setAssignedLabel(red); // blue jobs List<FreeStyleProject> blueJobs = create5SlowJobs(new Latch(5)); for (FreeStyleProject p : blueJobs) p.setAssignedLabel(blue); // build all List<Future<FreeStyleBuild>> blueBuilds = buildAll(blueJobs); verifySuccessfulCompletion(buildAll(redJobs)); // cloud should only give us 5 nodes for 5 red jobs assertEquals(5, cloud.numProvisioned); // and all blue jobs should be still stuck in the queue for (Future<FreeStyleBuild> bb : blueBuilds) assertFalse(bb.isDone()); } finally { bc.abort(); } }
@Test public void testGetQueueItems() throws IOException, Exception{ ListView view1 = listView("view1"); view1.filterQueue = true; ListView view2 = listView("view2"); view2.filterQueue = true; FreeStyleProject inView1 = j.createFreeStyleProject("in-view1"); inView1.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave")); view1.add(inView1); MatrixProject inView2 = j.createMatrixProject("in-view2"); inView2.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave")); view2.add(inView2); FreeStyleProject notInView = j.createFreeStyleProject("not-in-view"); notInView.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave")); FreeStyleProject inBothViews = j.createFreeStyleProject("in-both-views"); inBothViews.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave")); view1.add(inBothViews); view2.add(inBothViews); Queue.getInstance().schedule(notInView, 0); Queue.getInstance().schedule(inView1, 0); Queue.getInstance().schedule(inView2, 0); Queue.getInstance().schedule(inBothViews, 0); Thread.sleep(1000); assertContainsItems(view1, inView1, inBothViews); assertNotContainsItems(view1, notInView, inView2); assertContainsItems(view2, inView2, inBothViews); assertNotContainsItems(view2, notInView, inView1); }
private FreeStyleProject createJob(Builder builder) throws IOException { FreeStyleProject p = createFreeStyleProject(); p.setAssignedLabel( null); // let it roam free, or else it ties itself to the master since we have no slaves p.getBuildersList().add(builder); return p; }
@Test public void testGetComputers() throws IOException, Exception{ ListView view1 = listView("view1"); ListView view2 = listView("view2"); ListView view3 = listView("view3"); view1.filterExecutors=true; view2.filterExecutors=true; view3.filterExecutors=true; Slave slave0 = j.createOnlineSlave(j.jenkins.getLabel("label0")); Slave slave1 = j.createOnlineSlave(j.jenkins.getLabel("label1")); Slave slave2 = j.createOnlineSlave(j.jenkins.getLabel("label2")); Slave slave3 = j.createOnlineSlave(j.jenkins.getLabel("label0")); Slave slave4 = j.createOnlineSlave(j.jenkins.getLabel("label4")); FreeStyleProject freestyleJob = j.createFreeStyleProject("free"); view1.add(freestyleJob); freestyleJob.setAssignedLabel(j.jenkins.getLabel("label0||label2")); MatrixProject matrixJob = j.createMatrixProject("matrix"); view1.add(matrixJob); matrixJob.setAxes(new AxisList( new LabelAxis("label", Arrays.asList("label1")) )); FreeStyleProject noLabelJob = j.createFreeStyleProject("not-assigned-label"); view3.add(noLabelJob); noLabelJob.setAssignedLabel(null); FreeStyleProject foreignJob = j.createFreeStyleProject("in-other-view"); view2.add(foreignJob); foreignJob.setAssignedLabel(j.jenkins.getLabel("label0||label1")); // contains all slaves having labels associated with freestyleJob or matrixJob assertContainsNodes(view1, slave0, slave1, slave2, slave3); assertNotContainsNodes(view1, slave4); // contains all slaves having labels associated with foreignJob assertContainsNodes(view2, slave0, slave1, slave3); assertNotContainsNodes(view2, slave2, slave4); // contains all slaves as it contains noLabelJob that can run everywhere assertContainsNodes(view3, slave0, slave1, slave2, slave3, slave4); }
public void setUp() throws Exception { super.setUp(); EnvVars env = new EnvVars(); // we don't want Maven, Ant, etc. to be discovered in the path for this test to work, // but on Unix these tools rely on other basic Unix tools (like env) for its operation, // so empty path breaks the test. env.put("PATH", "/bin:/usr/bin"); env.put("M2_HOME", "empty"); slave = createSlave(new LabelAtom("slave"), env); project = createFreeStyleProject(); project.setAssignedLabel(slave.getSelfLabel()); }
/** * Returns the future object for a newly created project. * * @param blockingJobName the name for the project * @param shell the shell command task to add * @param label the label to bind to master or slave * @return the future object for a newly created project * @throws IOException */ private Future<FreeStyleBuild> createBlockingProject( String blockingJobName, Shell shell, Label label) throws IOException { FreeStyleProject blockingProject = this.createFreeStyleProject(blockingJobName); blockingProject.setAssignedLabel(label); blockingProject.getBuildersList().add(shell); Future<FreeStyleBuild> future = blockingProject.scheduleBuild2(0); while (!blockingProject.isBuilding()) { // wait until job is started } return future; }
/** * One test for all for faster execution. * * @throws Exception */ public void testCanRun() throws Exception { // init slave LabelAtom slaveLabel = new LabelAtom("slave"); LabelAtom masterLabel = new LabelAtom("master"); DumbSlave slave = this.createSlave(slaveLabel); SlaveComputer c = slave.getComputer(); c.connect(false).get(); // wait until it's connected if (c.isOffline()) { fail("Slave failed to go online: " + c.getLog()); } BuildBlockerQueueTaskDispatcher dispatcher = new BuildBlockerQueueTaskDispatcher(); String blockingJobName = "blockingJob"; Shell shell = new Shell("sleep 1"); Future<FreeStyleBuild> future1 = createBlockingProject("xxx", shell, masterLabel); Future<FreeStyleBuild> future2 = createBlockingProject(blockingJobName, shell, masterLabel); Future<FreeStyleBuild> future3 = createBlockingProject("yyy", shell, slaveLabel); // add project to slave FreeStyleProject project = this.createFreeStyleProject(); project.setAssignedLabel(slaveLabel); Queue.BuildableItem item = new Queue.BuildableItem( new Queue.WaitingItem(Calendar.getInstance(), project, new ArrayList<Action>())); CauseOfBlockage causeOfBlockage = dispatcher.canRun(item); assertNull(causeOfBlockage); BuildBlockerProperty property = new BuildBlockerProperty(); property.setBlockingJobs(".*ocki.*"); project.addProperty(property); causeOfBlockage = dispatcher.canRun(item); assertNotNull(causeOfBlockage); assertEquals( "Blocking job " + blockingJobName + " is running.", causeOfBlockage.getShortDescription()); while (!(future1.isDone() && future2.isDone() && future3.isDone())) { // wait until jobs are done. } }