示例#1
0
    @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);
    }
  /**
   * Tests if a {@link MatrixBuild} gets loaded and converted correctly from a version 1.2.0 save.
   *
   * @throws InterruptedException if it is not allowed to sleep in the beginning.
   */
  @LocalData
  public void testMatrix120() throws InterruptedException {
    MatrixProject project = (MatrixProject) jenkins.getItem("mymatrix");
    MatrixBuild build = project.getBuildByNumber(1);
    OldDataConverter.getInstance().waitForInitialCompletion();
    FailureCauseMatrixBuildAction matrixBuildAction =
        build.getAction(FailureCauseMatrixBuildAction.class);
    assertNotNull(matrixBuildAction);
    List<MatrixRun> runs = Whitebox.getInternalState(matrixBuildAction, "runs");
    assertNotNull(runs);
    List<String> runIds = null;

    runIds = Whitebox.getInternalState(matrixBuildAction, "runIds");

    assertEquals(runs.size(), runIds.size());
    assertNotNull(runs.get(3).getProject());
    assertEquals(runs.get(3).getProject().getCombination().toString(), runIds.get(3));
    assertNotNull(Whitebox.getInternalState(matrixBuildAction, "build"));

    MatrixBuild build2 = project.getBuildByNumber(2);
    List<MatrixRun> aggregatedRuns2 = FailureCauseMatrixAggregator.getRuns(build2);
    FailureCauseMatrixBuildAction matrixBuildAction2 =
        build2.getAction(FailureCauseMatrixBuildAction.class);
    assertNotNull(matrixBuildAction2);
    List<MatrixRun> runs2 = Whitebox.getInternalState(matrixBuildAction2, "runs");
    assertSame(aggregatedRuns2.get(5), runs2.get(5));
  }
 private MatrixProject createMatrixArtifactProject() throws IOException {
   MatrixProject p = createMatrixProject();
   p.setAxes(new AxisList(new Axis("FOO", "one", "two")));
   p.getBuildersList().add(new ArtifactBuilder());
   p.getPublishersList().add(new ArtifactArchiver("**", "", false));
   return p;
 }
示例#4
0
 @Test
 public void testGetItem() throws Exception{
     ListView view = listView("foo");
     FreeStyleProject job1 = j.createFreeStyleProject("free");
     MatrixProject job2 = j.createMatrixProject("matrix");
     FreeStyleProject job3 = j.createFreeStyleProject("not-included");
     view.jobNames.add(job2.getDisplayName());
     view.jobNames.add(job1.getDisplayName());
     assertEquals("View should return job " + job1.getDisplayName(),job1,  view.getItem("free"));
     assertNotNull("View should return null.", view.getItem("not-included"));
 }
 /** Test copying artifacts from a particular configuration of a matrix job */
 public void testMatrixJob() throws Exception {
   MatrixProject other = createMatrixArtifactProject();
   FreeStyleProject p = createProject(other.getName() + "/FOO=two", "", "", true, false, false);
   assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get());
   FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get();
   assertBuildStatusSuccess(b);
   assertFile(true, "foo.txt", b);
   assertFile(true, "two.txt", b);
   assertFile(true, "subdir/subfoo.txt", b);
   assertFile(true, "deepfoo/a/b/c.log", b);
 }
 public void testNoInterpreter() throws Exception {
   ToxBuilder builder = new ToxBuilder("tox.ini", false, null);
   MatrixProject project = createMatrixProject();
   AxisList axes = new AxisList(new ToxAxis(new String[] {"py27"}));
   project.setAxes(axes);
   project.getBuildersList().add(builder);
   MatrixBuild build = project.scheduleBuild2(0).get();
   List<MatrixRun> runs = build.getRuns();
   assertEquals(1, runs.size());
   MatrixRun run = runs.get(0);
   String log = FileUtils.readFileToString(run.getLogFile());
   assertTrue(
       "should not have found an interpreter:\n" + log,
       log.contains(Messages.BuilderUtil_NoInterpreterFound()));
 }
 public void testNoAxis() throws Exception {
   ToxBuilder builder = new ToxBuilder("tox.ini", false, null);
   MatrixProject project = createMatrixProject();
   AxisList axes = new AxisList(new TextAxis("TOTO", "TUTU"));
   project.setAxes(axes);
   project.getBuildersList().add(builder);
   MatrixBuild build = project.scheduleBuild2(0).get();
   List<MatrixRun> runs = build.getRuns();
   assertEquals(1, runs.size());
   MatrixRun run = runs.get(0);
   String log = FileUtils.readFileToString(run.getLogFile());
   assertTrue(
       "should not have found a tox axis:\n" + log,
       log.contains(Messages.ToxBuilder_ToxAxis_Required()));
 }
 public void testToxAxisSuccessful() throws Exception {
   configureCPython2();
   ToxBuilder builder = new ToxBuilder("tox.ini", false, null);
   MatrixProject project = createMatrixProject();
   AxisList axes = new AxisList(new ToxAxis(new String[] {"py27"}));
   project.setScm(new ToxSCM("tox.ini", "[testenv]\ncommand = echo"));
   project.setAxes(axes);
   project.getBuildersList().add(builder);
   MatrixBuild build = project.scheduleBuild2(0).get();
   List<MatrixRun> runs = build.getRuns();
   assertEquals(1, runs.size());
   MatrixRun run = runs.get(0);
   String log = FileUtils.readFileToString(run.getLogFile());
   assertTrue("tox should have been successful:\n" + log, log.contains("congratulations :)"));
   assertTrue("build should have been successful:\n" + log, log.contains("SUCCESS"));
 }
  @Test
  public void shortenMatrix() throws Exception {
    Node slave = j.createOnlineSlave();
    setMaxPathLength(slave, 1); // Not enough for anything

    MatrixProject mp = j.createMatrixProject();
    mp.setAssignedNode(slave);
    mp.setAxes(new AxisList(new LabelExpAxis("axis", slave.getNodeName())));

    MatrixBuild build = j.buildAndAssertSuccess(mp);
    assertThat(build.getBuiltOn(), equalTo(slave));
    MatrixRun run = build.getExactRuns().get(0);
    assertThat(run.getBuiltOn(), equalTo(slave));

    System.out.println(build.getWorkspace());
    System.out.println(run.getWorkspace());
  }
 public void testToxenvPatternBlank() throws Exception {
   configureCPython2();
   ToxBuilder builder = new ToxBuilder("tox.ini", false, "$FOOBAR");
   MatrixProject project = createMatrixProject();
   AxisList axes = new AxisList(new TextAxis("FOOBAR2", "badluck"));
   project.setScm(new ToxSCM("tox.ini", "[testenv]\ncommand = echo"));
   project.setAxes(axes);
   project.getBuildersList().add(builder);
   MatrixBuild build = project.scheduleBuild2(0).get();
   List<MatrixRun> runs = build.getRuns();
   assertEquals(1, runs.size());
   MatrixRun run = runs.get(0);
   String log = FileUtils.readFileToString(run.getLogFile());
   System.out.println(log);
   assertTrue(
       "should not be able to run with a blank TOXENV pattern:\n" + log,
       log.contains(Messages.ToxBuilder_ToxenvPattern_Invalid("$FOOBAR")));
 }
示例#11
0
    @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);
    }
示例#12
0
  /** {@inheritDoc} */
  @Override
  public void buildDependencyGraph(AbstractProject owner, DependencyGraph graph) {
    for (AbstractProject downstream : getChildProjects()) {
      graph.addDependency(new DownstreamDependency(owner, downstream, this));
    }

    // workaround for problems with Matrixprojects
    // see http://issues.hudson-ci.org/browse/HUDSON-5508
    if (!triggerOnlyOnceWhenMatrixEnds) {
      if (owner instanceof MatrixProject) {
        MatrixProject proj = (MatrixProject) owner;
        Collection<MatrixConfiguration> activeConfigurations = proj.getActiveConfigurations();
        for (MatrixConfiguration conf : activeConfigurations) {
          for (AbstractProject downstream : getChildProjects()) {
            graph.addDependency(new DownstreamDependency(conf, downstream, this));
          }
        }
      }
    }
  }
  @LocalData
  public void testMatrixBuildSummary() throws Exception {
    Hudson hudson = Hudson.getInstance();
    List<MatrixProject> projects = hudson.getAllItems(MatrixProject.class);
    MatrixProject testProject = null;
    for (MatrixProject project : projects) {
      System.out.println(project.getName());
      if (project.getName().equals("matrix-robot")) testProject = project;
    }
    if (testProject == null) fail("Couldn't find example project");
    Future<MatrixBuild> run = testProject.scheduleBuild2(0);

    while (!run.isDone()) {
      Thread.sleep(5);
    }
    Run lastBuild = testProject.getLastBuild();
    assertTrue("Build wasn't a success", lastBuild.getResult() == Result.SUCCESS);

    WebClient wc = getWebClient();
    HtmlPage page = wc.goTo("job/matrix-robot");
    WebAssert.assertElementPresentByXPath(
        page, "//div[@id='navigation']//a[@href='/job/matrix-robot/robot']");
    WebAssert.assertElementPresentByXPath(page, "//td[@id='main-panel']//img[@src='robot/graph']");

    page = wc.goTo("job/matrix-robot/3");
    WebAssert.assertElementPresentByXPath(
        page, "//div[@id='navigation']//a[@href='/job/matrix-robot/3/robot']");
    WebAssert.assertElementPresentByXPath(
        page, "//td[@id='main-panel']//h4[contains(.,'Robot Test Summary:')]");
    WebAssert.assertElementPresentByXPath(
        page,
        "//td[@id='main-panel']//a[@href='/job/matrix-robot/3/robot' and contains(text(),'Browse results')]");
  }
 public void testToxAxisAndToxenvPattern() throws Exception {
   configureCPython2();
   ToxBuilder builder = new ToxBuilder("tox.ini", false, "$INTERPRETER$VERSION");
   MatrixProject project = createMatrixProject();
   AxisList axes =
       new AxisList(
           new ToxAxis(new String[] {"py27"}),
           new TextAxis("INTERPRETER", "py"),
           new TextAxis("VERSION", "27"));
   project.setScm(new ToxSCM("tox.ini", "[testenv]\ncommand = echo"));
   project.setAxes(axes);
   project.getBuildersList().add(builder);
   MatrixBuild build = project.scheduleBuild2(0).get();
   List<MatrixRun> runs = build.getRuns();
   assertEquals(1, runs.size());
   MatrixRun run = runs.get(0);
   String log = FileUtils.readFileToString(run.getLogFile());
   System.out.println(log);
   assertTrue(
       "should not be able to run with both Tox axis and TOXENV pattern:\n" + log,
       log.contains(Messages.ToxBuilder_ToxAxis_And_ToxenvPattern()));
 }
  /** projectName in CopyArtifact build steps should be updated if a job is renamed */
  public void testJobRename() throws Exception {
    FreeStyleProject other = createFreeStyleProject(),
        p = createProject(other.getName(), "", "", true, false, false);
    assertEquals(
        "before", other.getName(), ((CopyArtifact) p.getBuilders().get(0)).getProjectName());
    String newName = other.getName() + "-new";
    other.renameTo(newName);
    assertEquals("after", newName, ((CopyArtifact) p.getBuilders().get(0)).getProjectName());

    // Test reference to a matrix configuration
    MatrixProject otherm = createMatrixProject(), mp = createMatrixProject();
    mp.getBuildersList()
        .add(
            new CopyArtifact(
                otherm.getName() + "/FOO=$FOO", new SavedBuildSelector(), "", "", false, false));
    assertEquals(
        "before",
        otherm.getName() + "/FOO=$FOO",
        ((CopyArtifact) mp.getBuilders().get(0)).getProjectName());
    otherm.renameTo(newName = otherm.getName() + "-new");
    assertEquals(
        "after", newName + "/FOO=$FOO", ((CopyArtifact) mp.getBuilders().get(0)).getProjectName());
  }
 /** Test copying artifacts from all configurations of a matrix job */
 public void testMatrixAll() throws Exception {
   MatrixProject mp = createMatrixProject();
   mp.setAxes(new AxisList(new Axis("ARCH", "sparc", "x86")));
   mp.getBuildersList().add(new ArchMatrixBuilder());
   mp.getPublishersList().add(new ArtifactArchiver("target/*", "", false));
   assertBuildStatusSuccess(mp.scheduleBuild2(0, new UserCause()).get());
   FreeStyleProject p = createProject(mp.getName(), "", "", true, false, false);
   FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get();
   assertBuildStatusSuccess(b);
   assertFile(true, "ARCH=sparc/target/readme.txt", b);
   assertFile(true, "ARCH=sparc/target/sparc.out", b);
   assertFile(true, "ARCH=x86/target/readme.txt", b);
   assertFile(true, "ARCH=x86/target/x86.out", b);
 }
 /** Test artifact copy between matrix jobs, for artifact from matching axis */
 public void testMatrixToMatrix() throws Exception {
   MatrixProject other = createMatrixArtifactProject(), p = createMatrixProject();
   p.setAxes(new AxisList(new Axis("FOO", "one", "two"))); // should match other job
   p.getBuildersList()
       .add(
           new CopyArtifact(
               other.getName() + "/FOO=$FOO",
               new StatusBuildSelector(true),
               "",
               "",
               false,
               false));
   assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get());
   MatrixBuild b = p.scheduleBuild2(0, new UserCause()).get();
   assertBuildStatusSuccess(b);
   MatrixRun r = b.getRun(new Combination(Collections.singletonMap("FOO", "one")));
   assertFile(true, "one.txt", r);
   assertFile(false, "two.txt", r);
   r = b.getRun(new Combination(Collections.singletonMap("FOO", "two")));
   assertFile(false, "one.txt", r);
   assertFile(true, "two.txt", r);
 }