Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from emsa23/master
[JENKINS-27966] Priority Sorter must not require matrix-project
- Loading branch information
Showing
22 changed files
with
389 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/jenkins/advancedqueue/PriorityConfigurationMatrixHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package jenkins.advancedqueue; | ||
|
||
import jenkins.advancedqueue.sorter.ItemInfo; | ||
import jenkins.advancedqueue.sorter.QueueItemCache; | ||
import hudson.matrix.MatrixConfiguration; | ||
import hudson.matrix.MatrixProject; | ||
import hudson.model.Job; | ||
|
||
class PriorityConfigurationMatrixHelper { | ||
|
||
boolean isMatrixConfiguration(Job<?, ?> job) { | ||
return job instanceof MatrixConfiguration; | ||
} | ||
|
||
PriorityConfigurationCallback getPriority(MatrixConfiguration matrixConfiguration, | ||
PriorityConfigurationCallback priorityCallback) { | ||
// [JENKINS-8597] | ||
// For MatrixConfiguration use the latest assigned Priority from the | ||
// MatrixProject | ||
MatrixProject matrixProject = matrixConfiguration.getParent(); | ||
priorityCallback.addDecisionLog(0, "Job is MatrixConfiguration [" + matrixProject.getName() + "] ..."); | ||
ItemInfo itemInfo = QueueItemCache.get().getItem(matrixProject.getName()); | ||
// Can be null (for example) at startup when the MatrixBuild got | ||
// lost (was running at restart) | ||
if (itemInfo != null) { | ||
priorityCallback.addDecisionLog(0, "MatrixProject found in cache, using priority from queue-item [" | ||
+ itemInfo.getItemId() + "]"); | ||
return priorityCallback.setPrioritySelection(itemInfo.getPriority(), itemInfo.getJobGroupId(), | ||
itemInfo.getPriorityStrategy()); | ||
} | ||
priorityCallback.addDecisionLog(0, "MatrixProject not found in cache, assigning global default priority"); | ||
return priorityCallback.setPrioritySelection(PrioritySorterConfiguration.get().getStrategy() | ||
.getDefaultPriority()); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package jenkins.advancedqueue.test; | ||
|
||
import hudson.cli.BuildCommand.CLICause; | ||
import hudson.model.Cause.UserIdCause; | ||
import jenkins.advancedqueue.testutil.ExpectedItem; | ||
import jenkins.advancedqueue.testutil.JobHelper; | ||
import jenkins.advancedqueue.testutil.TestRunListener; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.recipes.LocalData; | ||
|
||
public class MatrixTest { | ||
|
||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
private JobHelper jobHelper = new JobHelper(j); | ||
|
||
@Test | ||
@LocalData | ||
public void simple_matrix_with_no_configuration() throws Exception { | ||
TestRunListener.init( | ||
new ExpectedItem("Matrix 0", 1), | ||
new ExpectedItem("0A1=0A.", 1), new ExpectedItem("0A1=0A.", 1) | ||
); | ||
jobHelper.scheduleMatrixProjects(new UserIdCause()).go(); | ||
j.waitUntilNoActivity(); | ||
TestRunListener.assertStartedItems(); | ||
} | ||
|
||
@Test | ||
@LocalData | ||
public void simple_two_matrix_with_no_configuration() throws Exception { | ||
TestRunListener.init( | ||
new ExpectedItem("Matrix 0", 1), new ExpectedItem("Matrix 1", 1), | ||
new ExpectedItem("0A1=0A.", 1), new ExpectedItem("0A1=0A.", 1), | ||
new ExpectedItem("1A1=1A.", 1), new ExpectedItem("1A1=1A.", 1) | ||
); | ||
jobHelper.scheduleMatrixProjects(new UserIdCause(), new UserIdCause()).go(); | ||
j.waitUntilNoActivity(); | ||
TestRunListener.assertStartedItems(); | ||
} | ||
|
||
@Test | ||
@LocalData | ||
public void matrix_and_jobs_with_no_configuration() throws Exception { | ||
TestRunListener.init( | ||
new ExpectedItem("Matrix 0", 1), new ExpectedItem("Matrix 1", 5), | ||
new ExpectedItem("0A1=0A.", 1), new ExpectedItem("0A1=0A.", 1), | ||
new ExpectedItem("Job 0", 5), | ||
new ExpectedItem("1A1=1A.", 5), new ExpectedItem("1A1=1A.", 5) | ||
); | ||
jobHelper.scheduleProjects(new CLICause()).scheduleMatrixProjects(new UserIdCause(), new CLICause()).go(); | ||
j.waitUntilNoActivity(); | ||
TestRunListener.assertStartedItems(); | ||
} | ||
|
||
@Test | ||
@LocalData | ||
public void matrix_and_jobs_with_no_configuration_reverse() throws Exception { | ||
TestRunListener.init( | ||
new ExpectedItem("Matrix 0", 1), new ExpectedItem("Matrix 1", 5), | ||
new ExpectedItem("0A1=0A.", 1), new ExpectedItem("0A1=0A.", 1), | ||
new ExpectedItem("1A1=1A.", 5), new ExpectedItem("1A1=1A.", 5), | ||
new ExpectedItem("Job 0", 5) | ||
); | ||
jobHelper.scheduleMatrixProjects(new UserIdCause(), new CLICause()).scheduleProjects(new CLICause()).go(); | ||
j.waitUntilNoActivity(); | ||
TestRunListener.assertStartedItems(); | ||
} | ||
} |
Oops, something went wrong.