package com.blade.task;

import java.util.concurrent.CountDownLatch;
import java.util.stream.IntStream;

/**
 * @author PSH
 * @date 2019/03/16
 */
public class TaskManagerTest {
    public static void main(String[] args) {
        CountDownLatch downLatch = new CountDownLatch(500);
        IntStream.range(0,500).forEach(i -> {
            Task task = new Task("task-" + i, null, Integer.MAX_VALUE);
            new Thread(()->{
                TaskManager.addTask(task);
                downLatch.countDown();
            }).start();
        });
        try {
            downLatch.await();
            System.out.println("TaskManager.getTasks().size() = " + TaskManager.getTasks().size());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

@@ -96,16 +96,64 @@
 tStream;
+%0Aimport org.junit.Assert;%0Aimport org.junit.Test;
 %0A%0A/**%0A *
@@ -224,52 +224,117 @@
 t %7B%0A
-    public static void main(String%5B%5D args) %7B
+%0A    @Test%0A    public void testAddTaskMultiThreading() throws Exception %7B%0A%0A        final int tackCount = 500;
 %0A   
@@ -384,19 +384,25 @@
 wnLatch(
-500
+tackCount
 );%0A     
@@ -422,19 +422,26 @@
 range(0,
-500
+ tackCount
 ).forEac
@@ -546,18 +546,20 @@
 hread(()
+ 
 -%3E
+ 
 %7B%0A      
@@ -674,26 +674,9 @@
 %7D);%0A
-        try %7B%0A    
+%0A
     
@@ -710,185 +710,70 @@
     
-    
-System.out.println(%22TaskManager.getTasks().size() = %22 + TaskManager.getTasks().size());%0A        %7D catch (InterruptedException e) %7B%0A            e.printStackTrace();%0A        %7D
+Assert.assertEquals(tackCount, TaskManager.getTasks().size());
 %0A   

update TackManager