// 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;
                                                    String.format("Stored proc returned failure %s", bulkImportResponse.errorCode));
                                        }
                                    }

                                    double requestCharge = response.getRequestCharge();
                                    currentDocumentIndex += bulkImportResponse.count;
                                    numberOfDocumentsImported.addAndGet(bulkImportResponse.count);
                                    requestUnitsCounsumed += requestCharge;
                                    totalRequestUnitsConsumed.addAndGet(requestCharge);
                                }
                                else {
                                    logger.warn("pki {} Failed to receive response", partitionKeyRangeId);
                                }

                            } catch (DocumentClientException e) {

                                logger.debug("pki {} Importing minibatch failed", partitionKeyRangeId, e);

                                if (isThrottled(e)) {
                                    logger.debug("pki {} Throttled on partition range id", partitionKeyRangeId);
                                    numberOfThrottles++;
                                    isThrottled = true;
                                    retryAfter = Duration.ofMillis(e.getRetryAfterInMilliseconds());
                                    // will retry again

                                } else if (isTimedOut(e)) {
                                    logger.debug("pki {} Request timed out", partitionKeyRangeId);
                                    timedOut = true;
                                    // will retry again

// 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;

                                                    String.format("Stored proc returned failure %s", bulkImportResponse.errorCode));
                                        }
                                    }

                                    double requestCharge = response.getRequestCharge();
                                    currentDocumentIndex += bulkImportResponse.count;
                                    numberOfDocumentsImported.addAndGet(bulkImportResponse.count);
                                    requestUnitsCounsumed += requestCharge;
                                    totalRequestUnitsConsumed.addAndGet(requestCharge);
                                }
                                else {
                                    logger.warn("pki {} Failed to receive response", partitionKeyRangeId);
                                }

                            } catch (DocumentClientException e) {

                                logger.debug("pki {} Importing minibatch failed", partitionKeyRangeId, e);

                                if (isThrottled(e)) {
                                    logger.debug("pki {} Throttled on partition range id", partitionKeyRangeId);
                                    numberOfThrottles++;
                                    isThrottled = true;
                                    retryAfter = Duration.ofMillis(e.getRetryAfterInMilliseconds());
                                    // will retry again

                                } else if (isTimedOut(e)) {
                                    logger.debug("pki {} Request timed out", partitionKeyRangeId);
                                    timedOut = true;
                                    // will retry again

                                } else if (isGone(e)) {