-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 #347 from psh686868/dev
:BugFix: fixed TaskManager
- Loading branch information
Showing
2 changed files
with
65 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.blade.task; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.stream.IntStream; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author PSH | ||
* @date 2019/03/16 | ||
*/ | ||
public class TaskManagerTest { | ||
|
||
@Test | ||
public void testAddTaskMultiThreading() throws Exception { | ||
|
||
final int tackCount = 500; | ||
CountDownLatch downLatch = new CountDownLatch(tackCount); | ||
IntStream.range(0, tackCount).forEach(i -> { | ||
Task task = new Task("task-" + i, null, Integer.MAX_VALUE); | ||
new Thread(() -> { | ||
TaskManager.addTask(task); | ||
downLatch.countDown(); | ||
}).start(); | ||
}); | ||
|
||
downLatch.await(); | ||
Assert.assertEquals(tackCount, TaskManager.getTasks().size()); | ||
} | ||
} |