// Path: bulkimport/src/main/java/com/microsoft/azure/documentdb/bulkimport/ExceptionUtils.java
// public static boolean isGone(DocumentClientException e) {
//     return e.getStatusCode() == HttpConstants.StatusCodes.GONE;
// }
// 
// Path: bulkimport/src/main/java/com/microsoft/azure/documentdb/bulkimport/ExceptionUtils.java
// public static boolean isSplit(DocumentClientException e) {
//     return e.getStatusCode() == HttpConstants.StatusCodes.GONE
//             && HttpConstants.SubStatusCodes.SPLITTING == e.getSubStatusCode();
// }
// 
// Path: bulkimport/src/main/java/com/microsoft/azure/documentdb/bulkimport/ExceptionUtils.java
// public static boolean isThrottled(DocumentClientException e) {
//     return e.getStatusCode() == HttpConstants.StatusCodes.TOO_MANY_REQUESTS;
// }
// 
// Path: bulkimport/src/main/java/com/microsoft/azure/documentdb/bulkimport/ExceptionUtils.java
// public static boolean isTimedOut(DocumentClientException e) {
//     return e.getStatusCode() == HttpConstants.StatusCodes.TIMEOUT;
// }


import static com.microsoft.azure.documentdb.bulkimport.ExceptionUtils.isGone;
import static com.microsoft.azure.documentdb.bulkimport.ExceptionUtils.isSplit;
import static com.microsoft.azure.documentdb.bulkimport.ExceptionUtils.isThrottled;
import static com.microsoft.azure.documentdb.bulkimport.ExceptionUtils.isTimedOut;
import java.io.IOException;
import java.time.Duration;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Stopwatch;
import com.google.common.util.concurrent.AtomicDouble;
import com.microsoft.azure.documentdb.DocumentClient;
import com.microsoft.azure.documentdb.DocumentClientException;
import com.microsoft.azure.documentdb.RequestOptions;
import com.microsoft.azure.documentdb.StoredProcedureResponse;
        return numberOfDocumentsImported.get();
    }

    public double getTotalRequestUnitsConsumed() {
        return totalRequestUnitsConsumed.get();
    }

    public Iterator<Callable<InsertMetrics>> miniBatchInsertExecutionCallableIterator() {

        Stream<Callable<InsertMetrics>> stream = batchesToInsert.stream().map(miniBatch -> {
            return new Callable<InsertMetrics>() {

                @Override
                public InsertMetrics call() throws Exception {

                    try {
                        logger.debug("pki {} importing mini batch started", partitionKeyRangeId);
                        Stopwatch stopwatch = Stopwatch.createStarted();
                        double requestUnitsCounsumed = 0;
                        int numberOfThrottles = 0;
                        StoredProcedureResponse response;
                        boolean timedOut = false;

                        int currentDocumentIndex = 0;

                        while (currentDocumentIndex < miniBatch.size() && !cancel) {
                            logger.debug("pki {} inside for loop, currentDocumentIndex", partitionKeyRangeId, currentDocumentIndex);

                            String[] docBatch = miniBatch.subList(currentDocumentIndex, miniBatch.size()).toArray(new String[0]);

// Path: bulkimport/src/main/java/com/microsoft/azure/documentdb/bulkimport/ExceptionUtils.java
// public static boolean isGone(DocumentClientException e) {
//     return e.getStatusCode() == HttpConstants.StatusCodes.GONE;
// }
// 
// Path: bulkimport/src/main/java/com/microsoft/azure/documentdb/bulkimport/ExceptionUtils.java
// public static boolean isSplit(DocumentClientException e) {
//     return e.getStatusCode() == HttpConstants.StatusCodes.GONE
//             && HttpConstants.SubStatusCodes.SPLITTING == e.getSubStatusCode();
// }
// 
// Path: bulkimport/src/main/java/com/microsoft/azure/documentdb/bulkimport/ExceptionUtils.java
// public static boolean isThrottled(DocumentClientException e) {
//     return e.getStatusCode() == HttpConstants.StatusCodes.TOO_MANY_REQUESTS;
// }
// 
// Path: bulkimport/src/main/java/com/microsoft/azure/documentdb/bulkimport/ExceptionUtils.java
// public static boolean isTimedOut(DocumentClientException e) {
//     return e.getStatusCode() == HttpConstants.StatusCodes.TIMEOUT;
// }


// Path: bulkimport/src/main/java/com/microsoft/azure/documentdb/bulkimport/BatchInserter.java
import static com.microsoft.azure.documentdb.bulkimport.ExceptionUtils.isGone;
import static com.microsoft.azure.documentdb.bulkimport.ExceptionUtils.isSplit;
import static com.microsoft.azure.documentdb.bulkimport.ExceptionUtils.isThrottled;
import static com.microsoft.azure.documentdb.bulkimport.ExceptionUtils.isTimedOut;
import java.io.IOException;
import java.time.Duration;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Stopwatch;
import com.google.common.util.concurrent.AtomicDouble;
import com.microsoft.azure.documentdb.DocumentClient;
import com.microsoft.azure.documentdb.DocumentClientException;
import com.microsoft.azure.documentdb.RequestOptions;
import com.microsoft.azure.documentdb.StoredProcedureResponse;

        return numberOfDocumentsImported.get();
    }

    public double getTotalRequestUnitsConsumed() {
        return totalRequestUnitsConsumed.get();
    }

    public Iterator<Callable<InsertMetrics>> miniBatchInsertExecutionCallableIterator() {

        Stream<Callable<InsertMetrics>> stream = batchesToInsert.stream().map(miniBatch -> {
            return new Callable<InsertMetrics>() {

                @Override
                public InsertMetrics call() throws Exception {

                    try {
                        logger.debug("pki {} importing mini batch started", partitionKeyRangeId);
                        Stopwatch stopwatch = Stopwatch.createStarted();
                        double requestUnitsCounsumed = 0;
                        int numberOfThrottles = 0;
                        StoredProcedureResponse response;
                        boolean timedOut = false;

                        int currentDocumentIndex = 0;

                        while (currentDocumentIndex < miniBatch.size() && !cancel) {
                            logger.debug("pki {} inside for loop, currentDocumentIndex", partitionKeyRangeId, currentDocumentIndex);

                            String[] docBatch = miniBatch.subList(currentDocumentIndex, miniBatch.size()).toArray(new String[0]);

                            boolean isThrottled = false;