Skip to content
Permalink
Browse files

Merge branch 'JENKINS-14278' of git://github.com/cjo9900/parameterize…

…d-trigger-plugin into 2.17-RC

Resolved Conflicts:
	src/test/java/hudson/plugins/parameterizedtrigger/test/TriggerBuilderTest.java
  • Loading branch information...
cjo9900 committed Jan 29, 2013
2 parents 1f2d8f5 + 518fb04 commit 046294a3d96872d5eb99f559e60e8e3ba1b2eb27
@@ -214,7 +214,7 @@ private static ParametersAction getDefaultParameters(AbstractProject<?,?> projec
List<Action> actions = getBaseActions(
ImmutableList.<AbstractBuildParameters>builder().addAll(configs).addAll(addConfigs).build(),
build, listener);
for (AbstractProject project : getProjectList(build.getProject().getParent(),env)) {
for (AbstractProject project : getProjectList(build.getRootBuild().getProject().getParent(),env)) {
List<Action> list = getBuildActions(actions, project);

futures.add(schedule(build, project, list));
@@ -236,12 +236,12 @@ private static ParametersAction getDefaultParameters(AbstractProject<?,?> projec
try {
if (getCondition().isMet(build.getResult())) {
ListMultimap<AbstractProject, Future<AbstractBuild>> futures = ArrayListMultimap.create();

for (List<AbstractBuildParameters> addConfigs : getDynamicBuildParameters(build, listener)) {
List<Action> actions = getBaseActions(ImmutableList.<AbstractBuildParameters>builder().addAll(configs).addAll(addConfigs).build(), build, listener);
for (AbstractProject project : getProjectList(build.getProject().getParent(),env)) {
for (AbstractProject project : getProjectList(build.getRootBuild().getProject().getParent(),env)) {
List<Action> list = getBuildActions(actions, project);

futures.put(project, schedule(build, project, list));
}
}
@@ -252,7 +252,7 @@ private static ParametersAction getDefaultParameters(AbstractProject<?,?> projec
}
return ArrayListMultimap.create();
}

/**
* @return
* Inner list represents a set of build parameters used together for one invocation of a project,
@@ -94,7 +94,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
try {
for (BlockableBuildTriggerConfig config : configs) {
ListMultimap<AbstractProject, Future<AbstractBuild>> futures = config.perform2(build, launcher, listener);
List<AbstractProject> projectList = config.getProjectList(build.getProject().getParent(),env);
List<AbstractProject> projectList = config.getProjectList(build.getRootBuild().getProject().getParent(),env);

if(!projectList.isEmpty()){
//handle non-blocking configs
@@ -115,7 +115,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
AbstractBuild b = future.get();
listener.getLogger().println(HyperlinkNote.encodeTo('/'+ b.getUrl(), b.getFullDisplayName()) + " completed. Result was "+b.getResult());
build.getActions().add(new BuildInfoExporterAction(b.getProject().getFullName(), b.getNumber()));

if(buildStepResult && config.getBlock().mapBuildStepResult(b.getResult())) {
build.setResult(config.getBlock().mapBuildResult(b.getResult()));
} else {
@@ -152,8 +152,8 @@ public boolean shouldTriggerBuild(AbstractBuild build,
});

}


private String getProjectListAsString(List<AbstractProject> projectList){
StringBuffer projectListString = new StringBuffer();
for (Iterator iterator = projectList.iterator(); iterator.hasNext();) {
@@ -25,20 +25,33 @@

import hudson.model.Project;
import hudson.model.Result;
import hudson.model.FreeStyleProject;
import hudson.plugins.parameterizedtrigger.AbstractBuildParameterFactory;
import hudson.plugins.parameterizedtrigger.AbstractBuildParameters;
import hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig;
import hudson.plugins.parameterizedtrigger.BlockingBehaviour;
import hudson.plugins.parameterizedtrigger.CounterBuildParameterFactory;
import hudson.plugins.parameterizedtrigger.TriggerBuilder;
import org.jvnet.hudson.test.Bug;

import hudson.matrix.TextAxis;
import hudson.matrix.MatrixProject;
import hudson.matrix.MatrixRun;
import hudson.matrix.AxisList;


import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.io.IOException;

import org.jvnet.hudson.test.HudsonTestCase;
import com.google.common.collect.ImmutableList;
import hudson.model.Run;
import java.io.IOException;
import java.lang.System;

public class TriggerBuilderTest extends HudsonTestCase {

@@ -74,9 +87,41 @@ public void testOrderOfLogEntries() throws Exception {
"project4 #1 completed. Result was SUCCESS",
"project5 #1 completed. Result was SUCCESS",
"project6 #1 completed. Result was SUCCESS");

}


public void testSubParameterBuilds() throws Exception {
hudson.setNumExecutors(10); // makes sure there are enough executors so that there are no deadlocks
hudson.setNodes(hudson.getNodes()); // update nodes configuration

FreeStyleProject p1 = createFreeStyleProject("project1");
createFreeStyleProject("project2");
createFreeStyleProject("project3");

///triggered from project 1
createFreeStyleProject("projectZ4");
createFreeStyleProject("projectZ5");
createFreeStyleProject("projectZ6");

Project<?, ?> triggerProject = createFreeStyleProject("projectA");

TriggerBuilder triggerBuilder = new TriggerBuilder(createTriggerConfig("project1"));
triggerBuilder.getConfigs().add(createTriggerConfig("project2"));
triggerBuilder.getConfigs().add(createTriggerConfig("project3"));

TriggerBuilder triggerBuilder2 = new TriggerBuilder(createTriggerConfig("projectZ4"));
triggerBuilder2.getConfigs().add(createTriggerConfig("projectZ5"));
triggerBuilder2.getConfigs().add(createTriggerConfig("projectZ6"));

p1.getBuildersList().add(triggerBuilder2);
triggerProject.getBuildersList().add(triggerBuilder);

triggerProject.scheduleBuild2(0).get();
assertLines(triggerProject.getLastBuild(),
"project1 #1 completed. Result was SUCCESS",
"project2 #1 completed. Result was SUCCESS",
"project3 #1 completed. Result was SUCCESS");
}

public void testWaitingForCompletion() throws Exception {
createFreeStyleProject("project1");
createFreeStyleProject("project2");
@@ -95,7 +140,7 @@ public void testWaitingForCompletion() throws Exception {
"Waiting for the completion of project2",
"Waiting for the completion of project3");
}

public void testNonBlockingTrigger() throws Exception {
createFreeStyleProject("project1");
createFreeStyleProject("project2");
@@ -118,15 +163,15 @@ public void testConsoleOutputWithCounterParameters() throws Exception{
createFreeStyleProject("project1");
createFreeStyleProject("project2");
createFreeStyleProject("project3");

Project<?,?> triggerProject = createFreeStyleProject();

BlockingBehaviour blockingBehaviour = new BlockingBehaviour(Result.FAILURE, Result.UNSTABLE, Result.FAILURE);
ImmutableList<AbstractBuildParameterFactory> buildParameter = ImmutableList.<AbstractBuildParameterFactory>of(new CounterBuildParameterFactory("0","2","1", "TEST=COUNT$COUNT"));
List<AbstractBuildParameters> emptyList = Collections.<AbstractBuildParameters>emptyList();

BlockableBuildTriggerConfig bBTConfig = new BlockableBuildTriggerConfig("project1, project2, project3", blockingBehaviour, buildParameter, emptyList);

triggerProject.getBuildersList().add(new TriggerBuilder(bBTConfig));

triggerProject.scheduleBuild2(0).get();
@@ -143,7 +188,7 @@ public void testConsoleOutputWithCounterParameters() throws Exception{
"project3 #3 completed. Result was SUCCESS");
}


public void testBlockingTriggerWithDisabledProjects() throws Exception {
createFreeStyleProject("project1");
Project<?, ?> p2 = createFreeStyleProject("project2");
@@ -162,7 +207,78 @@ public void testBlockingTriggerWithDisabledProjects() throws Exception {
"Waiting for the completion of project1",
"Skipping project2. The project is either disabled or the configuration has not been saved yet.",
"Waiting for the completion of project3");

}


@Bug(14278)
public void testBlockingTriggerWithMatrixProject() throws Exception {

/* This test case will start a matrix project that is configured with 2 Axis
* each with two possible values giving 4 combinations.
* the build is configured with a TriggerBuilder which will block waiting for
* 6 other projects to complete.
*
* To allow this to run with no jobs being queued we need to have enogh exectors for all builds
* That is 1 + 4 + (4*6) = 29
* The minimun number of executors needed to allow test to run with queued builds would be
* 1 + 4 + 1 = 5 that is one exector for all of the builds that start others and
* and also a free executor to allow the queue to progress
*
* Set as 50 for first case.
*/

hudson.setNumExecutors(50);
hudson.setNodes(hudson.getNodes()); // update nodes configuration

createFreeStyleProject("project1");
createFreeStyleProject("project2");
createFreeStyleProject("project3");
createFreeStyleProject("project4");
createFreeStyleProject("project5");
createFreeStyleProject("project6");

MatrixProject matrixProject = createMatrixProject("matrixProject");

TriggerBuilder triggerBuilder = new TriggerBuilder(createTriggerConfig("project1"));
triggerBuilder.getConfigs().add(createTriggerConfig("project2"));
triggerBuilder.getConfigs().add(createTriggerConfig("project3"));
triggerBuilder.getConfigs().add(createTriggerConfig("project4"));
triggerBuilder.getConfigs().add(createTriggerConfig("project5"));
triggerBuilder.getConfigs().add(createTriggerConfig("project6"));

matrixProject.getBuildersList().add(triggerBuilder);

matrixProject.scheduleBuild2(0).get();

List<String> log2 = matrixProject.getLastBuild().getLog(20);
System.out.println(log2);

List<MatrixRun> runs = matrixProject.getLastBuild().getRuns();

assertEquals(4,runs.size());

for (MatrixRun run : runs) {
assertLinesRegex(run,
"project1 #[0-9] completed. Result was SUCCESS",
"project2 #[0-9] completed. Result was SUCCESS",
"project3 #[0-9] completed. Result was SUCCESS",
"project4 #[0-9] completed. Result was SUCCESS",
"project5 #[0-9] completed. Result was SUCCESS",
"project6 #[0-9] completed. Result was SUCCESS");
}
}


@Override
protected MatrixProject createMatrixProject(String name) throws IOException {
MatrixProject p = super.createMatrixProject(name);
// set up 2x2 matrix
AxisList axes = new AxisList();
axes.add(new TextAxis("db","mysql","oracle"));
axes.add(new TextAxis("direction","north","south"));
p.setAxes(axes);

return p;
}

private void assertLines(Run<?,?> build, String... lines) throws IOException {
@@ -175,4 +291,28 @@ private void assertLines(Run<?,?> build, String... lines) throws IOException {
}
}

private void assertLinesRegex (Run<?,?> build, String... regexs) throws IOException {
// Same function as above but allows regex instead of just strings
List<String> log = build.getLog(Integer.MAX_VALUE);
List<String> rest = log;
ListIterator li = log.listIterator();

Pattern p = Pattern.compile(""); // initial pattern will be replaced in loop
Matcher m = p.matcher((String)li.next());
for (String regex : regexs) {
int lastmatched = 0;
m.usePattern(Pattern.compile(regex));
while (li.hasNext()) {
m.reset((String)li.next());
if (m.matches()) {
lastmatched = li.nextIndex();
li = log.listIterator(li.nextIndex());
break;
}
}
// set up rest to contain the part of the log that has not been successfully checked
rest = log.subList(lastmatched + 1, log.size());
assertTrue("Could not find regex '" + regex + "' among remaining log lines " + rest, li.hasNext() );
}
}
}

0 comments on commit 046294a

Please sign in to comment.
You can’t perform that action at this time.