// Path: src/test/java/org/jboss/elasticsearch/river/jira/testtools/MockThread.java
// public class MockThread extends Thread {
// 
//   public boolean wasStarted = false;
// 
//   public boolean interruptWasCalled = false;
// 
//   @Override
//   public synchronized void start() {
//     wasStarted = true;
//   }
// 
//   @Override
//   public void interrupt() {
//     interruptWasCalled = true;
//   }
// 
// }


import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.jboss.elasticsearch.river.jira.testtools.MockThread;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
		{
			tested.startIndexers();
			Assert.assertTrue(tested.projectIndexerThreads.isEmpty());
			Assert.assertTrue(tested.projectIndexers.isEmpty());
			verify(esIntegrationMock, times(0)).acquireIndexingThread(Mockito.any(String.class), Mockito.any(Runnable.class));
		}

		// case - all indexer slots full, do not start new ones
		{
			reset(esIntegrationMock);
			tested.projectKeysToIndexQueue.addAll(Utils.parseCsvString("ORG,AAA,BBB,CCC,DDD"));
			tested.projectIndexerThreads.put("JJ", new Thread());
			tested.projectIndexerThreads.put("II", new Thread());
			tested.startIndexers();
			Assert.assertEquals(2, tested.projectIndexerThreads.size());
			Assert.assertEquals(5, tested.projectKeysToIndexQueue.size());
			verify(esIntegrationMock, times(0)).acquireIndexingThread(Mockito.any(String.class), Mockito.any(Runnable.class));
			Mockito.verifyNoMoreInteractions(esIntegrationMock);
		}

		// case - one indexer slot empty, start new one
		{
			reset(esIntegrationMock);
			tested.projectIndexerThreads.clear();
			tested.projectIndexerThreads.put("II", new Thread());
			tested.projectIndexers.clear();
			tested.projectIndexers.put("II", new JIRAProjectIndexer("II", true, null, esIntegrationMock, null));
			tested.projectKeysToIndexQueue.clear();
			tested.projectKeysToIndexQueue.addAll(Utils.parseCsvString("ORG,AAA,BBB,CCC,DDD"));
			when(esIntegrationMock.acquireIndexingThread(Mockito.eq("jira_river_indexer_ORG"), Mockito.any(Runnable.class)))
// Path: src/test/java/org/jboss/elasticsearch/river/jira/testtools/MockThread.java
// public class MockThread extends Thread {
// 
//   public boolean wasStarted = false;
// 
//   public boolean interruptWasCalled = false;
// 
//   @Override
//   public synchronized void start() {
//     wasStarted = true;
//   }
// 
//   @Override
//   public void interrupt() {
//     interruptWasCalled = true;
//   }
// 
// }


// Path: src/test/java/org/jboss/elasticsearch/river/jira/JIRAProjectIndexerCoordinatorTest.java
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.jboss.elasticsearch.river.jira.testtools.MockThread;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

		{
			tested.startIndexers();
			Assert.assertTrue(tested.projectIndexerThreads.isEmpty());
			Assert.assertTrue(tested.projectIndexers.isEmpty());
			verify(esIntegrationMock, times(0)).acquireIndexingThread(Mockito.any(String.class), Mockito.any(Runnable.class));
		}

		// case - all indexer slots full, do not start new ones
		{
			reset(esIntegrationMock);
			tested.projectKeysToIndexQueue.addAll(Utils.parseCsvString("ORG,AAA,BBB,CCC,DDD"));
			tested.projectIndexerThreads.put("JJ", new Thread());
			tested.projectIndexerThreads.put("II", new Thread());
			tested.startIndexers();
			Assert.assertEquals(2, tested.projectIndexerThreads.size());
			Assert.assertEquals(5, tested.projectKeysToIndexQueue.size());
			verify(esIntegrationMock, times(0)).acquireIndexingThread(Mockito.any(String.class), Mockito.any(Runnable.class));
			Mockito.verifyNoMoreInteractions(esIntegrationMock);
		}

		// case - one indexer slot empty, start new one
		{
			reset(esIntegrationMock);
			tested.projectIndexerThreads.clear();
			tested.projectIndexerThreads.put("II", new Thread());
			tested.projectIndexers.clear();
			tested.projectIndexers.put("II", new JIRAProjectIndexer("II", true, null, esIntegrationMock, null));
			tested.projectKeysToIndexQueue.clear();
			tested.projectKeysToIndexQueue.addAll(Utils.parseCsvString("ORG,AAA,BBB,CCC,DDD"));
			when(esIntegrationMock.acquireIndexingThread(Mockito.eq("jira_river_indexer_ORG"), Mockito.any(Runnable.class)))
					.thenReturn(new MockThread());