package org.gcube.application.cms.usecases;

import lombok.extern.slf4j.Slf4j;
import org.gcube.application.cms.tests.TokenSetter;

import java.io.FileNotFoundException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicLong;

@Slf4j
public class StressTest {


    private static ExecutorService service = Executors.newFixedThreadPool(5);

    public static void main(String[] args) throws FileNotFoundException {
        TokenSetter.set("/pred4s/preprod/preVRE");
        AtomicLong executed=new AtomicLong(0);

     //   AddSectionToConcessioneRequest request= ConcessionPublisherThread.prepareRequest(
       //         new StorageUtils(), Concessione.Paths.RELAZIONE,new File(TestConcessioniModel.getBaseFolder(),"relazione.pdf"));

//        int numRequests=100000;
//        for(int i=0;i<numRequests;i++){
//            service.submit(new Runnable() {
//                @Override
//                public void run() {
//                    try{
//                        MongoConcessioni client=mongoConcessioni().build();
//                        Concessione c =TestConcessioniModel.prepareConcessione(1,1);
//                        c.setNome("Stress test");
//                        c.setDefaults();
//                        c=client.createNew(c);
////                        client.registerFileSet(c.getMongo_id(),request);
//                    }catch(Throwable t){
//                        System.err.println(t);
//                        try {Thread.sleep(1000);} catch (InterruptedException i) {}
//                    }finally {
//                        log.info("Executed "+executed.incrementAndGet());
//                        try {Thread.sleep(1000);} catch (InterruptedException i) {}
//                    }
//                }
//            });
//        }

//        try{
//        while(!service.awaitTermination(1, TimeUnit.MINUTES)){
//            log.info("Waiting termination, executed {} out of {}",executed.get(),numRequests);
//        }
//        }catch (InterruptedException e){

//        }
        System.out.println("DONE");
    }
}
