<commit_before>/*
 * Copyright 2012-2014 MarkLogic Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.marklogic.client.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Logger;
import java.util.logging.Level;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import com.marklogic.client.document.DocumentDescriptor;
import com.marklogic.client.document.DocumentManager.Metadata;
import com.marklogic.client.document.DocumentPage;
import com.marklogic.client.document.DocumentRecord;
import com.marklogic.client.document.DocumentWriteSet;
import com.marklogic.client.document.JSONDocumentManager;
import com.marklogic.client.document.TextDocumentManager;
import com.marklogic.client.document.XMLDocumentManager;
import com.marklogic.client.io.DocumentMetadataHandle;
import com.marklogic.client.io.Format;
import com.marklogic.client.io.JacksonHandle;
import com.marklogic.client.io.JAXBHandle;
import com.marklogic.client.io.SearchHandle;
import com.marklogic.client.io.StringHandle;
import com.marklogic.client.query.DeleteQueryDefinition;
import com.marklogic.client.query.QueryManager;
import com.marklogic.client.query.StructuredQueryBuilder;

/** Loads data from cities15000.txt which contains every city above 15000 people, and adds
 * data from countryInfo.txt.
 **/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class BulkReadWriteTest {
    private static final int BATCH_SIZE = 100;
    static final String DIRECTORY = "/cities/";
    private static final String COUNTRIES_FILE = "countryInfo.txt";
    private static final String CITIES_FILE = "cities_above_300K.txt";
    static final int RECORDS_EXPECTED = 1363;
    private static JAXBContext context = null;

    @BeforeClass
    public static void beforeClass() throws JAXBException {
        Common.connect();
        context = JAXBContext.newInstance(City.class);
        System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "debug");
    }
    @AfterClass
    public static void afterClass() {
        cleanUp();
        Common.release();
    }

    interface CityWriter {
        public void addCity(City city);
        public void finishBatch();
        public void setNumRecords(int numWritten);
    }

    private class BulkCityWriter implements CityWriter {
        private XMLDocumentManager docMgr = Common.client.newXMLDocumentManager();
        private JAXBContext context;
        private DocumentWriteSet writeSet = docMgr.newWriteSet();

        BulkCityWriter() throws JAXBException {
            context = JAXBContext.newInstance(City.class);
        }

        public void addCity(City city) {<commit_msg>turn off wire-level debug<commit_after>/*
 * Copyright 2012-2014 MarkLogic Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.marklogic.client.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Logger;
import java.util.logging.Level;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import com.marklogic.client.document.DocumentDescriptor;
import com.marklogic.client.document.DocumentManager.Metadata;
import com.marklogic.client.document.DocumentPage;
import com.marklogic.client.document.DocumentRecord;
import com.marklogic.client.document.DocumentWriteSet;
import com.marklogic.client.document.JSONDocumentManager;
import com.marklogic.client.document.TextDocumentManager;
import com.marklogic.client.document.XMLDocumentManager;
import com.marklogic.client.io.DocumentMetadataHandle;
import com.marklogic.client.io.Format;
import com.marklogic.client.io.JacksonHandle;
import com.marklogic.client.io.JAXBHandle;
import com.marklogic.client.io.SearchHandle;
import com.marklogic.client.io.StringHandle;
import com.marklogic.client.query.DeleteQueryDefinition;
import com.marklogic.client.query.QueryManager;
import com.marklogic.client.query.StructuredQueryBuilder;

/** Loads data from cities15000.txt which contains every city above 15000 people, and adds
 * data from countryInfo.txt.
 **/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class BulkReadWriteTest {
    private static final int BATCH_SIZE = 100;
    static final String DIRECTORY = "/cities/";
    private static final String COUNTRIES_FILE = "countryInfo.txt";
    private static final String CITIES_FILE = "cities_above_300K.txt";
    static final int RECORDS_EXPECTED = 1363;
    private static JAXBContext context = null;

    @BeforeClass
    public static void beforeClass() throws JAXBException {
        Common.connect();
        context = JAXBContext.newInstance(City.class);
        //System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "debug");
    }
    @AfterClass
    public static void afterClass() {
        cleanUp();
        Common.release();
    }

    interface CityWriter {
        public void addCity(City city);
        public void finishBatch();
        public void setNumRecords(int numWritten);
    }

    private class BulkCityWriter implements CityWriter {
        private XMLDocumentManager docMgr = Common.client.newXMLDocumentManager();
        private JAXBContext context;
        private DocumentWriteSet writeSet = docMgr.newWriteSet();

        BulkCityWriter() throws JAXBException {
            context = JAXBContext.newInstance(City.class);
        }

        public void addCity(City city) {
{'fraction_non_alphanumeric': 0.08824331696672122, 'fraction_numerical': 0.00872885979268958, 'mean_word_length': 4.325344952795933, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '677289', 'n_tokens_mistral': 2115, 'n_tokens_neox': 2018, 'n_words': 543}