<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 org.apache.solr.core;

import org.apache.commons.io.FileUtils;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

/**
 * Incorporate the open/close stress tests into unit tests.
 */
public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {

  private final Object locker = new Object();

  private int numCores = 20;
  private Map<String, Long> coreCounts;
  private List<String> coreNames;

  static final int COMMIT_WITHIN = 5000;

  final int indexingThreads = 15;
  final int queryThreads = 15;

  final int resetInterval = 30 * 60; // minutes to report then delete everything
  long cumulativeDocs = 0;

  String url;

  JettySolrRunner jetty = null;

  File solrHomeDirectory;

  List<HttpSolrServer> indexingServers = new ArrayList<HttpSolrServer>(indexingThreads);
  List<HttpSolrServer> queryServers = new ArrayList<HttpSolrServer>(queryThreads);

  static String savedFactory;

  //  Keep the indexes from being randomly generated.
  @BeforeClass
  public static void beforeClass() {
    savedFactory = System.getProperty("solr.DirectoryFactory");
    System.setProperty("solr.directoryFactory", "org.apache.solr.core.MockFSDirectoryFactory");
  }

  @AfterClass
  public static void afterClass() {
    if (savedFactory == null) {
      System.clearProperty("solr.directoryFactory");
    } else {
      System.setProperty("solr.directoryFactory", savedFactory);
    }
  }

  @Before
  public void setupServer() throws Exception {
    coreCounts = new TreeMap<String, Long>();
    coreNames = new ArrayList<String>();
    cumulativeDocs = 0;

    solrHomeDirectory = new File(TEMP_DIR, "OpenCloseCoreStressTest_");
    FileUtils.deleteDirectory(solrHomeDirectory); // Insure that a failed test didn't leave something lying around.

    jetty = new JettySolrRunner(solrHomeDirectory.getAbsolutePath(), "/solr", 0);
  }

  @After
  public void tearDownServer() throws Exception {
    if (jetty != null) jetty.stop();
    FileUtils.deleteDirectory(solrHomeDirectory);
  }

  @Test
  @Slow
  public void test30SecondsOld() throws Exception {
    doStress(30, true);
  }

  @Test
  @Slow
  public void test30SecondsNew() throws Exception {
    doStress(30, false);
  }

  @Test
  @Nightly
  public void test10MinutesOld() throws Exception {
    doStress(300, true);
  }

  @Test
  @Nightly
  public void test10MinutesNew() throws Exception {
    doStress(300, false);
  }

  @Test
  @Weekly
  public void test1HourOld() throws Exception {
    doStress(1800, true);
  }
<commit_msg>SOLR-5345: A first pass toning down OpenCloseCoreStressTest<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 org.apache.solr.core;

import org.apache.commons.io.FileUtils;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

/**
 * Incorporate the open/close stress tests into unit tests.
 */
public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {

  private final Object locker = new Object();

  private int numCores = TEST_NIGHTLY ? 7 : 5;
  private Map<String, Long> coreCounts;
  private List<String> coreNames;

  static final int COMMIT_WITHIN = 5000;

  final int indexingThreads = TEST_NIGHTLY ? 9 : 5;
  final int queryThreads = TEST_NIGHTLY ? 9 : 5;

  final int resetInterval = 30 * 60; // minutes to report then delete everything
  long cumulativeDocs = 0;

  String url;

  JettySolrRunner jetty = null;

  File solrHomeDirectory;

  List<HttpSolrServer> indexingServers = new ArrayList<HttpSolrServer>(indexingThreads);
  List<HttpSolrServer> queryServers = new ArrayList<HttpSolrServer>(queryThreads);

  static String savedFactory;

  @Before
  public void setupServer() throws Exception {
    coreCounts = new TreeMap<String, Long>();
    coreNames = new ArrayList<String>();
    cumulativeDocs = 0;

    solrHomeDirectory = new File(TEMP_DIR, "OpenCloseCoreStressTest_");
    FileUtils.deleteDirectory(solrHomeDirectory); // Ensure that a failed test didn't leave something lying around.

    jetty = new JettySolrRunner(solrHomeDirectory.getAbsolutePath(), "/solr", 0);
  }

  @After
  public void tearDownServer() throws Exception {
    if (jetty != null) jetty.stop();
    FileUtils.deleteDirectory(solrHomeDirectory);
  }

  @Test
  @Slow
  public void test15SecondsOld() throws Exception {
    doStress(15, true);
  }

  @Test
  @Slow
  public void test15SecondsNew() throws Exception {
    doStress(15, false);
  }

  @Test
  @Nightly
  public void test10MinutesOld() throws Exception {
    doStress(300, true);
  }

  @Test
  @Nightly
  public void test10MinutesNew() throws Exception {
    doStress(300, false);
  }

  @Test
  @Weekly
  public void test1HourOld() throws Exception {
    doStress(1800, true);
  }

{'fraction_non_alphanumeric': 0.09166151945645461, 'fraction_numerical': 0.0118591723285979, 'mean_word_length': 4.408149632598531, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '2013917', 'n_tokens_mistral': 2543, 'n_tokens_neox': 2391, 'n_words': 706}