Skip to content

Commit

Permalink
#130 Fix maxThreads=1 bug (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
CaioK authored and eolivelli committed Jun 1, 2018
1 parent 1bff2bb commit 8605012
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions majordodo-core/src/main/java/majordodo/task/TasksChooser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package majordodo.task;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
Expand All @@ -29,7 +28,6 @@
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import majordodo.utils.DiscardingBoundedPriorityQueue;
Expand Down Expand Up @@ -287,6 +285,9 @@ void accept(int position, TasksHeap.TaskEntry entry) {
IntCounter counterForUser = availableSpacePerUser.get(new IntTaskTypeUser(tasktype, entry.userid));
if (counterForUser == null) {
int limitForUserWithoutAnyTaskRunning = (availableSpaceForTaskType * maxThreadPerUserPerTaskTypePercent) / 100;
if (limitForUserWithoutAnyTaskRunning <= 0) {
limitForUserWithoutAnyTaskRunning = 1;
}
counterForUser = new IntCounter(limitForUserWithoutAnyTaskRunning);
availableSpacePerUser.put(new IntTaskTypeUser(tasktype, entry.userid), counterForUser);
}
Expand Down
25 changes: 25 additions & 0 deletions majordodo-core/src/test/java/majordodo/task/BrokerStatusTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,31 @@ public void testCollectMaxAvailableSpacePerUserOnWorker() throws Exception {

}
}

@Test
public void testCollectMaxAvailableSpacePerUserOnWorkerMaxThreads1() throws Exception {
try (Broker broker = new Broker(new BrokerConfiguration(), new MemoryCommitLog(), new TasksHeap(1000, createTaskPropertiesMapperFunction()));) {
broker.startAsWritable();

int maxThreadPerTaskType1 = 1;
Map<String, Integer> maxThreadsPerTaskType2 = Collections.singletonMap(TASKTYPE_MYTYPE, maxThreadPerTaskType1);

// add other 10 tasks for the same user
for (int i = 0; i < 10; i++) {
SubmitTaskResult res = broker.getClient().submitTask(new AddTaskRequest(0, TASKTYPE_MYTYPE, userId, "", 1, 0, 0, null, 0, null, null));
assertTrue(res.getTaskId() > 0);
}

int maxThreadPerUserPerTaskTypePercent = 80;
// at least one should be assigned
{
List<AssignedTask> assignTasksToWorker = broker.assignTasksToWorker(100, maxThreadsPerTaskType2, Collections.singletonList(group),
Collections.emptySet(), "myworker", new HashMap<>(), new ResourceUsageCounters(), maxThreadPerUserPerTaskTypePercent);
assertEquals(1, assignTasksToWorker.size());
}

}
}

@Test
public void testCollectMaxAvailableSpacePerUserOnWorkerUsingTaskTypeAny() throws Exception {
Expand Down

0 comments on commit 8605012

Please sign in to comment.