package ru.nbakaev.hishop.good;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.context.web.WebAppConfiguration;
import org.testng.annotations.Test;
import ru.nbakaev.hishop.StartApplication;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by Nikita Bakaev, ya@nbakaev.ru on 2/21/2016.
 * All Rights Reserved
 */
@SpringApplicationConfiguration(classes = StartApplication.class)
@WebAppConfiguration
@ActiveProfiles("development")
public class GoodRepositoryImplMillionGoodsTest extends AbstractTestNGSpringContextTests {

    @Autowired
    private MongoOperations mongoOperations;

    @Autowired
    private GoodRepository goodRepository;

    private final Logger logger = LoggerFactory.getLogger(getClass());

    private ExecutorService executorService = Executors.newFixedThreadPool(80);

    @Test
    public void createMillionGoodsTest() {

//        List<Good> createdGoods = new ArrayList<>();

        for (int i=0; i < 5_000_000; i++){

            if (i % 100_000 == 0){
                logger.info("Creating good with number: " + i);
            }

            int finalI = i;
            executorService.submit( () -> {
                Good good = new Good();
                good.setName("Good-"+ finalI);

                good = goodRepository.createGood(good);
            });


//            createdGoods.add(good);

        }

    }

}

@@ -643,16 +643,54 @@
 ecutors;
+%0Aimport java.util.concurrent.TimeUnit;
 %0A%0A/**%0A *
@@ -1308,26 +1308,24 @@
 st() %7B%0A%0A
-//
         
 List%3CGoo
@@ -1320,50 +1320,54 @@
     
-List%3CGood%3E createdGoods = new ArrayList%3C%3E(
+logger.info(%22Start creating million good test%22
 );%0A%0A
@@ -1384,17 +1384,19 @@
 r (int i
-=
+ = 
 0; i %3C 5
@@ -1409,16 +1409,17 @@
 00; i++)
+ 
 %7B%0A%0A     
@@ -1446,16 +1446,17 @@
 00 == 0)
+ 
 %7B%0A      
@@ -1591,17 +1591,16 @@
 .submit(
- 
 () -%3E %7B%0A
@@ -1675,16 +1675,17 @@
 (%22Good-%22
+ 
 + finalI
@@ -1765,44 +1765,295 @@
 );%0A%0A
-%0A//            createdGoods.add(good
+            executorService.shutdownNow();%0A            try %7B%0A                executorService.awaitTermination(1, TimeUnit.MINUTES);%0A            %7D catch (InterruptedException e) %7B%0A                e.printStackTrace();%0A            %7D%0A%0A            logger.info(%22End creating million good test%22
 );%0A%0A

add logger coments