/** * 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. } }
public void testCopyToSlave() throws Exception { DumbSlave node = createSlave(); SlaveComputer c = node.getComputer(); c.connect(false).get(); // wait until it's connected if (c.isOffline()) fail("Slave failed to go online: " + c.getLog()); FreeStyleProject other = createArtifactProject(), p = createProject(other.getName(), "", "", false, false, false); assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get()); p.setAssignedLabel(node.getSelfLabel()); FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get(); assertBuildStatusSuccess(b); assertSame(node, b.getBuiltOn()); assertFile(true, "foo.txt", b); assertFile(true, "subdir/subfoo.txt", b); assertFile(true, "deepfoo/a/b/c.log", b); }