@Test
public void testAutoMode() {

	ExecutionContext context = newExecutionContext();
	ReportNode rootReportNode = context.getReport();
	context.getVariablesManager().putVariable(rootReportNode, "execution_threads_auto", 2);
	
	ThreadPool threadPool = new ThreadPool(context);
	
	List<String> itemList = new ArrayList<>();
	for(int i=0; i<100; i++) {
		itemList.add("Item"+i);
	}
	
	List<String> itemList2 = new ArrayList<>();
	for(int i=0; i<100; i++) {
		itemList2.add(Integer.toString(i));
	}
	
	List<String> processedItems = new CopyOnWriteArrayList<>();
	
	CountDownLatch countDownLatch = new CountDownLatch(2);
	
	ConcurrentHashMap<String,String> threadIdLevel1 = new ConcurrentHashMap<>();
	ConcurrentHashMap<String,String> threadIdLevel2 = new ConcurrentHashMap<>();
	threadPool.consumeWork(itemList.iterator(), new WorkerItemConsumerFactory<String>() {
		@Override
		public Consumer<String> createWorkItemConsumer(WorkerController<String> control) {
			return item1 -> {
				context.setCurrentReportNode(rootReportNode);
				threadIdLevel1.put(Thread.currentThread().getName(),"");
				waitForOtherWorkersToStart(countDownLatch);
				threadPool.consumeWork(itemList2.iterator(), new WorkerItemConsumerFactory<String>() {
					@Override
					public Consumer<String> createWorkItemConsumer(WorkerController<String> control) {
						return item2 -> {
							threadIdLevel2.put(Thread.currentThread().getName(),"");
							processedItems.add(item1+item2);
						};
					}
				}, 4);
			};
		}
	}, 4);
	
	Assert.assertEquals(2, threadIdLevel1.size());
	Assert.assertEquals(2, threadIdLevel2.size());
	for (String item : itemList) {
		for (String item2 : itemList2) {
			String concatenatedItem = item+item2;
			if(!processedItems.contains(concatenatedItem)) {
				fail("The item "+concatenatedItem+" hasn't been processed");
			}
			
		}
	}
}