Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,6 @@ THE SOFTWARE.
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
</dependency>
<dependency>
<groupId>com.tngtech.jgiven</groupId>
<artifactId>jgiven-junit</artifactId>
<version>2.0.2</version>
<scope>test</scope>
<exclusions>
<!-- Provided by Jenkins core -->
<exclusion>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Dependencies for test -->
<dependency>
Expand Down
32 changes: 15 additions & 17 deletions src/test/java/hudson/plugins/throttleconcurrents/TestUtil.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package hudson.plugins.throttleconcurrents;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import hudson.EnvVars;
import hudson.model.Computer;
Expand All @@ -11,14 +11,14 @@
import hudson.model.queue.CauseOfBlockage;
import hudson.slaves.DumbSlave;
import hudson.slaves.RetentionStrategy;
import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import jenkins.model.queue.CompositeCauseOfBlockage;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.support.steps.ExecutorStepExecution;
import org.junit.rules.TemporaryFolder;
import org.jvnet.hudson.test.JenkinsRule;

public class TestUtil {
Expand All @@ -34,13 +34,15 @@ public class TestUtil {
static final ThrottleJobProperty.ThrottleCategory OTHER_ONE_PER_NODE =
new ThrottleJobProperty.ThrottleCategory("other_one_per_node", 1, 0, null);

private TestUtil() {
// Instantiation is prohibited
}

private static DumbSlave createAgent(
JenkinsRule j, TemporaryFolder temporaryFolder, EnvVars env, int numExecutors, String label)
throws Exception {
JenkinsRule j, File temporaryFolder, EnvVars env, int numExecutors, String label) throws Exception {
synchronized (j.jenkins) {
int sz = j.jenkins.getNodes().size();
DumbSlave agent =
new DumbSlave("agent" + sz, temporaryFolder.getRoot().getPath(), j.createComputerLauncher(env));
DumbSlave agent = new DumbSlave("agent" + sz, temporaryFolder.getPath(), j.createComputerLauncher(env));
agent.setNumExecutors(numExecutors);
agent.setMode(Node.Mode.NORMAL);
agent.setLabelString(label == null ? "" : label);
Expand All @@ -54,12 +56,7 @@ private static DumbSlave createAgent(
}

static Node setupAgent(
JenkinsRule j,
TemporaryFolder temporaryFolder,
List<Node> agents,
EnvVars env,
int numExecutors,
String label)
JenkinsRule j, File temporaryFolder, List<Node> agents, EnvVars env, int numExecutors, String label)
throws Exception {
DumbSlave agent = TestUtil.createAgent(j, temporaryFolder, env, numExecutors, label);

Expand Down Expand Up @@ -88,8 +85,7 @@ static void setupCategories(ThrottleJobProperty.ThrottleCategory... categories)
}

static Set<String> getBlockageReasons(CauseOfBlockage cob) {
if (cob instanceof CompositeCauseOfBlockage) {
CompositeCauseOfBlockage ccob = (CompositeCauseOfBlockage) cob;
if (cob instanceof CompositeCauseOfBlockage ccob) {
return ccob.uniqueReasons.keySet();
} else {
return Collections.singleton(cob.getShortDescription());
Expand All @@ -99,7 +95,9 @@ static Set<String> getBlockageReasons(CauseOfBlockage cob) {
static void hasPlaceholderTaskForRun(Node n, WorkflowRun r) throws Exception {
for (Executor exec : n.toComputer().getExecutors()) {
if (exec.getCurrentExecutable() != null) {
assertTrue(exec.getCurrentExecutable().getParent() instanceof ExecutorStepExecution.PlaceholderTask);
assertInstanceOf(
ExecutorStepExecution.PlaceholderTask.class,
exec.getCurrentExecutable().getParent());
ExecutorStepExecution.PlaceholderTask task = (ExecutorStepExecution.PlaceholderTask)
exec.getCurrentExecutable().getParent();
while (task.run() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,30 @@
*/
package hudson.plugins.throttleconcurrents;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* This class initiates the testing of {@link hudson.plugins.throttleconcurrents.ThrottleJobProperty.ThrottleCategory}.<br>
* -Hence this class also testing {@link hudson.plugins.throttleconcurrents.ThrottleJobProperty.NodeLabeledPair}.<br>
* -Test methods for {@link hudson.plugins.throttleconcurrents.ThrottleJobProperty.ThrottleCategory#getNodeLabeledPairs()}.
* @author [email protected]
*/
public class ThrottleCategoryTest {
class ThrottleCategoryTest {
private static final String testCategoryName = "aCategory";

@Test
public void shouldGetEmptyNodeLabeledPairsListUponInitialNull() {
void shouldGetEmptyNodeLabeledPairsListUponInitialNull() {
ThrottleJobProperty.ThrottleCategory category =
new ThrottleJobProperty.ThrottleCategory(testCategoryName, 0, 0, null);
assertTrue(
"nodeLabeledPairs shall be empty",
category.getNodeLabeledPairs().isEmpty());
assertTrue(category.getNodeLabeledPairs().isEmpty(), "nodeLabeledPairs shall be empty");
}

@Test
public void shouldGetNonEmptyNodeLabeledPairsListThatWasSet() {
void shouldGetNonEmptyNodeLabeledPairsListThatWasSet() {
String expectedLabel = "aLabel";
Integer expectedMax = 1;

Expand All @@ -54,12 +52,12 @@ public void shouldGetNonEmptyNodeLabeledPairsListThatWasSet() {
Integer actualMax = category.getNodeLabeledPairs().get(0).getMaxConcurrentPerNodeLabeled();

assertEquals(
"throttledNodeLabel " + actualLabel + " does not match expected " + expectedLabel,
expectedLabel,
actualLabel);
actualLabel,
"throttledNodeLabel " + actualLabel + " does not match expected " + expectedLabel);
assertEquals(
"maxConcurrentPerNodeLabeled " + actualMax + " does not match expected " + expectedMax,
expectedMax,
actualMax);
actualMax,
"maxConcurrentPerNodeLabeled " + actualMax + " does not match expected " + expectedMax);
}
}
Loading
Loading