// Path: bulkimport/src/main/java/com/microsoft/azure/documentdb/bulkimport/DocumentBulkImporter.java
// public static class Builder {
// 
//     private DocumentClient client;
//     private String collectionLink;
//     private int maxMiniBatchSize = (int) Math.floor(MAX_BULK_IMPORT_SCRIPT_INPUT_SIZE * FRACTION_OF_MAX_BULK_IMPORT_SCRIPT_INPUT_SIZE_ALLOWED);
//     private final static int DEFAULT_RETRY_ATTEMPT_ON_THROTTLING_FOR_INIT = 200;
//     private final static int DEFAULT_WAIT_TIME_ON_THROTTLING_FOR_INIT_IN_SECONDS = 60;
// 
//     private PartitionKeyDefinition partitionKeyDef;
//     private int offerThroughput;
// 
//     private static RetryOptions DEFAULT_INIT_RETRY_OPTIONS;
// 
//     static {
//         DEFAULT_INIT_RETRY_OPTIONS = new RetryOptions();
//         DEFAULT_INIT_RETRY_OPTIONS.setMaxRetryAttemptsOnThrottledRequests(DEFAULT_RETRY_ATTEMPT_ON_THROTTLING_FOR_INIT);
//         DEFAULT_INIT_RETRY_OPTIONS.setMaxRetryWaitTimeInSeconds(DEFAULT_WAIT_TIME_ON_THROTTLING_FOR_INIT_IN_SECONDS);
//     }
// 
//     private RetryOptions retryOptions = DEFAULT_INIT_RETRY_OPTIONS; 
// 
//     /**
//      * Use the instance of {@link DocumentClient} to bulk import to the given instance of {@link DocumentCollection}
//      * @param client an instance of {@link DocumentClient}
//      * @param partitionKeyDef specifies the {@link PartitionKeyDefinition} of the collection
//      * @param databaseName name of the database
//      * @param collectionName name of the collection
//      * @param offerThroughput specifies the collection throughput
//      * @return an instance of {@link Builder}
//      */
//     public Builder from(DocumentClient client,
//             String databaseName, 
//             String collectionName,
//             PartitionKeyDefinition partitionKeyDef,
//             int offerThroughput) {
// 
//         // TODO: validate the retry options for the client
//         this.client = client;
//         this.collectionLink = String.format("/dbs/%s/colls/%s", databaseName, collectionName);
//         this.partitionKeyDef = partitionKeyDef;
//         this.offerThroughput = offerThroughput;
//         return this;
//     }
// 
//     /**
//      * use the given size to configure max mini batch size.
//      *
//      * If not specified will use the default.
//      * @param size specifies the size of mini batch.
//      * @return {@link Builder}
//      */
//     public Builder withMaxMiniBatchSize(int size) {
//         Preconditions.checkArgument(size > 0, "maxMiniBatchSize cannot be negative");
//         Preconditions.checkArgument(size <= MAX_BULK_IMPORT_SCRIPT_INPUT_SIZE, "maxMiniBatchSize cannot be negative");
// 
//         this.maxMiniBatchSize = size;
//         return this;
//     }
// 
//     /**
//      * use the given retry option for initialization 
//      * 
//      * @param options an instance of {@link RetryOptions}
//      * @return {@link Builder}
//      */
//     public Builder withInitializationRetryOptions(RetryOptions options) {
//         this.retryOptions = options;
//         return this;
//     }
// 
//     /**
//      * Instantiates {@link DocumentBulkImporter} given the configured {@link Builder}.
//      *
//      * @return the new builder
//      * @throws Exception if there is any failure
//      */
//     public DocumentBulkImporter build() throws Exception {
//         DocumentBulkImporter importer = new DocumentBulkImporter(client, collectionLink, partitionKeyDef, offerThroughput);
//         try {
//             importer.setInitializationRetryOptions(retryOptions);
//             importer.setMaxMiniBatchSize(maxMiniBatchSize);
// 
//             importer.safeInit();
// 
//         } catch (Exception e) {
//             importer.close();
//             throw e;
//         }
//         return importer;
//     }
// 
//     private Builder() {}
// }


import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import com.microsoft.azure.documentdb.Document;
import com.microsoft.azure.documentdb.DocumentClient;
import com.microsoft.azure.documentdb.DocumentClientException;
import com.microsoft.azure.documentdb.Undefined;
import com.microsoft.azure.documentdb.bulkimport.DocumentBulkImporter.Builder;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
/**
 * The MIT License (MIT)
 * Copyright (c) 2017 Microsoft Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package com.microsoft.azure.documentdb.bulkimport;





@RunWith(Parameterized.class)
public class EndToEndBulkImportTests extends EndToEndTestBase {

    private DocumentClient client;

    public EndToEndBulkImportTests(DocumentClientConfiguration config) {
        this.client = new DocumentClient(config.getEndpoint(), config.getMasterKey(), config.getConnectionPolicy(),
                config.getConsistencyLevel());
    }

    @Before
    public void setup() throws Exception {
        super.setup(this.client);
        Thread.sleep(1000);
    }

    @After
    public void shutdown() throws DocumentClientException {
        super.shutdown(this.client);
    }

    @Test
    public void bulkImport() throws Exception {
// Path: bulkimport/src/main/java/com/microsoft/azure/documentdb/bulkimport/DocumentBulkImporter.java
// public static class Builder {
// 
//     private DocumentClient client;
//     private String collectionLink;
//     private int maxMiniBatchSize = (int) Math.floor(MAX_BULK_IMPORT_SCRIPT_INPUT_SIZE * FRACTION_OF_MAX_BULK_IMPORT_SCRIPT_INPUT_SIZE_ALLOWED);
//     private final static int DEFAULT_RETRY_ATTEMPT_ON_THROTTLING_FOR_INIT = 200;
//     private final static int DEFAULT_WAIT_TIME_ON_THROTTLING_FOR_INIT_IN_SECONDS = 60;
// 
//     private PartitionKeyDefinition partitionKeyDef;
//     private int offerThroughput;
// 
//     private static RetryOptions DEFAULT_INIT_RETRY_OPTIONS;
// 
//     static {
//         DEFAULT_INIT_RETRY_OPTIONS = new RetryOptions();
//         DEFAULT_INIT_RETRY_OPTIONS.setMaxRetryAttemptsOnThrottledRequests(DEFAULT_RETRY_ATTEMPT_ON_THROTTLING_FOR_INIT);
//         DEFAULT_INIT_RETRY_OPTIONS.setMaxRetryWaitTimeInSeconds(DEFAULT_WAIT_TIME_ON_THROTTLING_FOR_INIT_IN_SECONDS);
//     }
// 
//     private RetryOptions retryOptions = DEFAULT_INIT_RETRY_OPTIONS; 
// 
//     /**
//      * Use the instance of {@link DocumentClient} to bulk import to the given instance of {@link DocumentCollection}
//      * @param client an instance of {@link DocumentClient}
//      * @param partitionKeyDef specifies the {@link PartitionKeyDefinition} of the collection
//      * @param databaseName name of the database
//      * @param collectionName name of the collection
//      * @param offerThroughput specifies the collection throughput
//      * @return an instance of {@link Builder}
//      */
//     public Builder from(DocumentClient client,
//             String databaseName, 
//             String collectionName,
//             PartitionKeyDefinition partitionKeyDef,
//             int offerThroughput) {
// 
//         // TODO: validate the retry options for the client
//         this.client = client;
//         this.collectionLink = String.format("/dbs/%s/colls/%s", databaseName, collectionName);
//         this.partitionKeyDef = partitionKeyDef;
//         this.offerThroughput = offerThroughput;
//         return this;
//     }
// 
//     /**
//      * use the given size to configure max mini batch size.
//      *
//      * If not specified will use the default.
//      * @param size specifies the size of mini batch.
//      * @return {@link Builder}
//      */
//     public Builder withMaxMiniBatchSize(int size) {
//         Preconditions.checkArgument(size > 0, "maxMiniBatchSize cannot be negative");
//         Preconditions.checkArgument(size <= MAX_BULK_IMPORT_SCRIPT_INPUT_SIZE, "maxMiniBatchSize cannot be negative");
// 
//         this.maxMiniBatchSize = size;
//         return this;
//     }
// 
//     /**
//      * use the given retry option for initialization 
//      * 
//      * @param options an instance of {@link RetryOptions}
//      * @return {@link Builder}
//      */
//     public Builder withInitializationRetryOptions(RetryOptions options) {
//         this.retryOptions = options;
//         return this;
//     }
// 
//     /**
//      * Instantiates {@link DocumentBulkImporter} given the configured {@link Builder}.
//      *
//      * @return the new builder
//      * @throws Exception if there is any failure
//      */
//     public DocumentBulkImporter build() throws Exception {
//         DocumentBulkImporter importer = new DocumentBulkImporter(client, collectionLink, partitionKeyDef, offerThroughput);
//         try {
//             importer.setInitializationRetryOptions(retryOptions);
//             importer.setMaxMiniBatchSize(maxMiniBatchSize);
// 
//             importer.safeInit();
// 
//         } catch (Exception e) {
//             importer.close();
//             throw e;
//         }
//         return importer;
//     }
// 
//     private Builder() {}
// }


// Path: bulkimport/src/test/java/com/microsoft/azure/documentdb/bulkimport/EndToEndBulkImportTests.java
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import com.microsoft.azure.documentdb.Document;
import com.microsoft.azure.documentdb.DocumentClient;
import com.microsoft.azure.documentdb.DocumentClientException;
import com.microsoft.azure.documentdb.Undefined;
import com.microsoft.azure.documentdb.bulkimport.DocumentBulkImporter.Builder;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * The MIT License (MIT)
 * Copyright (c) 2017 Microsoft Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package com.microsoft.azure.documentdb.bulkimport;





@RunWith(Parameterized.class)
public class EndToEndBulkImportTests extends EndToEndTestBase {

    private DocumentClient client;

    public EndToEndBulkImportTests(DocumentClientConfiguration config) {
        this.client = new DocumentClient(config.getEndpoint(), config.getMasterKey(), config.getConnectionPolicy(),
                config.getConsistencyLevel());
    }

    @Before
    public void setup() throws Exception {
        super.setup(this.client);
        Thread.sleep(1000);
    }

    @After
    public void shutdown() throws DocumentClientException {
        super.shutdown(this.client);
    }

    @Test
    public void bulkImport() throws Exception {
        Builder bulkImporterBuilder = DocumentBulkImporter.builder().