Skip to content

Commit b2d71dd

Browse files
Travis yml
1 parent 2dd429f commit b2d71dd

File tree

4 files changed

+101
-1
lines changed

4 files changed

+101
-1
lines changed

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
before_install:
2+
- echo "MAVEN_OPTS='-Xmx512m -XX:MaxPermSize=128m'" > ~/.mavenrc
3+
- mvn clean
4+
- wget https://github.com/codacy/codacy-coverage-reporter/releases/download/4.0.5/codacy-coverage-reporter-4.0.5-assembly.jar
5+
6+
language: Java
7+
jdk:
8+
- oraclejdk8
9+
10+
## Travis installs the project with the following maven command:- "mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V"
11+
script:
12+
- mvn package
13+
14+
## Send Coverage to Codacy
15+
after_success:
16+
- java -jar codacy-coverage-reporter-4.0.5-assembly.jar report -l Java -r taskmaster-core/target/site/jacoco/jacoco.xml

taskmaster-core/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
<scope>provided</scope>
5050
</dependency>
5151

52+
<!-- Junit -->
53+
<dependency>
54+
<groupId>org.junit.vintage</groupId>
55+
<artifactId>junit-vintage-engine</artifactId>
56+
</dependency>
57+
5258
</dependencies>
5359

5460
</project>

taskmaster-core/src/main/java/com/github/bordertech/taskmaster/logical/LogicalThreadPool.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.io.Serializable;
55
import java.util.concurrent.Semaphore;
66
import java.util.concurrent.TimeUnit;
7+
import org.apache.commons.lang.StringUtils;
78
import org.apache.commons.logging.Log;
89
import org.apache.commons.logging.LogFactory;
910

@@ -24,12 +25,19 @@ public class LogicalThreadPool implements Serializable {
2425
private final Semaphore semaphore;
2526
private boolean shutdown;
2627

28+
/**
29+
* Default constructor with default name and no limit to threads.
30+
*/
31+
public LogicalThreadPool() {
32+
this(null, 0);
33+
}
34+
2735
/**
2836
* @param name thread pool name
2937
* @param max the maximum threads. Zero means no limit.
3038
*/
3139
public LogicalThreadPool(final String name, final int max) {
32-
this.name = name == null ? "default" : name;
40+
this.name = StringUtils.isEmpty(name) ? "default" : name;
3341
this.max = max > 0 ? max : 0;
3442
this.semaphore = new Semaphore(this.max, true);
3543
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.github.bordertech.taskmaster.logical;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
/**
7+
* Unit tests for {@link LogicalThreadPool}.
8+
*/
9+
public class LogicalThreadPoolTest {
10+
11+
@Test
12+
public void testConstructor1() {
13+
LogicalThreadPool pool = new LogicalThreadPool();
14+
Assert.assertEquals("Incorrect pool name for default constructor", "default", pool.getName());
15+
Assert.assertEquals("Incorrect max threads for default constructor", 0, pool.getMax());
16+
}
17+
18+
@Test
19+
public void testConstructor2() {
20+
LogicalThreadPool pool = new LogicalThreadPool("foo", 5);
21+
Assert.assertEquals("Incorrect name for constructor", "foo", pool.getName());
22+
Assert.assertEquals("Incorrect default max threads for constructor", 5, pool.getMax());
23+
}
24+
25+
@Test
26+
public void testDefaultShutdown() {
27+
Assert.assertFalse("Pool should not be shutdown.", new LogicalThreadPool().isShutdown());
28+
}
29+
30+
@Test
31+
public void testNameDefault() {
32+
Assert.assertEquals("Pool name should be default for default constructor", "default", new LogicalThreadPool().getName());
33+
}
34+
35+
@Test
36+
public void testNameNull() {
37+
Assert.assertEquals("Pool name should be default for null in constructor", "default", new LogicalThreadPool(null, 0).getName());
38+
}
39+
40+
@Test
41+
public void testNameEmpty() {
42+
Assert.assertEquals("Pool name should be default for empty in constructor", "default", new LogicalThreadPool("", 0).getName());
43+
}
44+
45+
@Test
46+
public void testNameValue() {
47+
Assert.assertEquals("Pool name should be default for value in constructor", "foo", new LogicalThreadPool("foo", 0).getName());
48+
}
49+
50+
@Test
51+
public void testMaxDefault() {
52+
Assert.assertEquals("Pool max should default to zero (no limit).", 0, new LogicalThreadPool().getMax());
53+
}
54+
55+
@Test
56+
public void testMaxNegative() {
57+
Assert.assertEquals("Pool max should be zero for negative constructor value.", 0, new LogicalThreadPool(null, -1).getMax());
58+
}
59+
60+
@Test
61+
public void testMaxZero() {
62+
Assert.assertEquals("Pool max should be zero for zero constructor value.", 0, new LogicalThreadPool(null, 0).getMax());
63+
}
64+
65+
@Test
66+
public void testMaxPositive() {
67+
Assert.assertEquals("Pool max should be positive value.", 10, new LogicalThreadPool(null, 10).getMax());
68+
}
69+
70+
}

0 commit comments

Comments
 (0)