<commit_before>package org.jenkinsci.plugins.lucene.search.databackend;

import org.apache.commons.io.FileUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.core.ConfigSolr;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrResourceLoader;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.xml.sax.SAXException;

import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static org.junit.Assert.assertEquals;

public class SolrSearchBackendTest {

    @Rule
    public JenkinsRule rule = new JenkinsRule();

    int solrPort;
    private ExecutorService backgroundWorker;
    private JenkinsSearchBackend jenkinsSearchBackend;
    private EmbeddedSolrServer solrServer;



    @Before
    public void setup() throws Exception {
        solrPort = findFreePort();

        SolrResourceLoader solrResourceLoader = new SolrResourceLoader(SolrResourceLoader.locateSolrHome());
        String configSolrXml = "<solr>"
                + "  <solrcloud>"
                + "    <str name=\"host\">${host:}</str>"
                + "    <int name=\"hostPort\">" + solrPort + "</int>"
                + "    <str name=\"hostContext\">${hostContext:solr}</str>"
                + "    <int name=\"zkClientTimeout\">${zkClientTimeout:30000}</int>"
                + "    <bool name=\"genericCoreNodeNames\">${genericCoreNodeNames:true}</bool>"
                + "  </solrcloud>"
                + "  <shardHandlerFactory name=\"shardHandlerFactory\""
                + "    class=\"HttpShardHandlerFactory\">"
                + "    <int name=\"socketTimeout\">${socketTimeout:0}</int>"
                + "    <int name=\"connTimeout\">${connTimeout:0}</int>"
                + "  </shardHandlerFactory>"
                + "</solr>";
        ConfigSolr config = ConfigSolr.fromString(solrResourceLoader, configSolrXml);
        CoreContainer container = new CoreContainer(solrResourceLoader, config);
//        FileUtils.deleteQuietly(new File("testdata/solr"));
//        CoreContainer container = new CoreContainer("testdata/solr");
        container.load();
        solrServer = new EmbeddedSolrServer(container, "collection1");
        assertEquals(200, solrServer.ping().getStatus());

        backgroundWorker = Executors.newFixedThreadPool(1);
        jenkinsSearchBackend = new JenkinsSearchBackend(rule, backgroundWorker);




    }

    @After
    public void tearDown() {
        backgroundWorker.shutdownNow();
        solrServer.shutdown();
    }

    private int findFreePort() throws IOException {
        Random rnd = new Random();
        for (int i = 0; i < 100; i++) {
            int testPort = rnd.nextInt(64000) + 1024;
            try {
                ServerSocket serverSocket = new ServerSocket(testPort);
                serverSocket.close();
                return testPort;
            } catch (IOException ex) {
            }
        }
        throw new IOException("Could not find available port");
    }

    @Test(timeout = 10000)
    public void givenLuceneWhenJobsWithBuildsAreExecutedThenTheyShouldBeSearchable()
            throws IOException, ExecutionException, InterruptedException, SAXException, URISyntaxException {
        jenkinsSearchBackend.setSolrBackend(false, solrPort);
        jenkinsSearchBackend.testBuildAndRebuild();
    }
}<commit_msg>Trying new path<commit_after>package org.jenkinsci.plugins.lucene.search.databackend;

import org.apache.commons.io.FileUtils;
import org.apache.hadoop.fs.FileUtil;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.core.ConfigSolr;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrResourceLoader;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.xml.sax.SAXException;

import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static org.junit.Assert.assertEquals;

public class SolrSearchBackendTest {

    @Rule
    public JenkinsRule rule = new JenkinsRule();

    int solrPort;
    private ExecutorService backgroundWorker;
    private JenkinsSearchBackend jenkinsSearchBackend;
    private EmbeddedSolrServer solrServer;

    @Before
    public void setup() throws Exception {
        solrPort = findFreePort();

        FileUtils.copyDirectory(new File("src/main/resources/solr/"), new File("target/solr/"));

        SolrResourceLoader solrResourceLoader = new SolrResourceLoader(new File("target/solr").getCanonicalPath());
        String configSolrXml = "<solr>"
                + "  <solrcloud>"
                + "    <str name=\"host\">${host:}</str>"
                + "    <int name=\"hostPort\">" + solrPort + "</int>"
                + "    <str name=\"hostContext\">${hostContext:solr}</str>"
                + "    <int name=\"zkClientTimeout\">${zkClientTimeout:30000}</int>"
                + "    <bool name=\"genericCoreNodeNames\">${genericCoreNodeNames:true}</bool>"
                + "  </solrcloud>"
                + "  <shardHandlerFactory name=\"shardHandlerFactory\""
                + "    class=\"HttpShardHandlerFactory\">"
                + "    <int name=\"socketTimeout\">${socketTimeout:0}</int>"
                + "    <int name=\"connTimeout\">${connTimeout:0}</int>"
                + "  </shardHandlerFactory>"
                + "</solr>";
        ConfigSolr config = ConfigSolr.fromString(solrResourceLoader, configSolrXml);
        CoreContainer container = new CoreContainer(solrResourceLoader, config);
        FileUtils.deleteQuietly(new File("testdata/solr/data"));
//        CoreContainer container = new CoreContainer("testdata/solr");
        container.load();
        solrServer = new EmbeddedSolrServer(container, "collection1");
        assertEquals(200, solrServer.ping().getStatus());

        backgroundWorker = Executors.newFixedThreadPool(1);
        jenkinsSearchBackend = new JenkinsSearchBackend(rule, backgroundWorker);
    }

    @After
    public void tearDown() {
        backgroundWorker.shutdownNow();
        solrServer.shutdown();
    }

    private int findFreePort() throws IOException {
        Random rnd = new Random();
        for (int i = 0; i < 100; i++) {
            int testPort = rnd.nextInt(64000) + 1024;
            try {
                ServerSocket serverSocket = new ServerSocket(testPort);
                serverSocket.close();
                return testPort;
            } catch (IOException ex) {
            }
        }
        throw new IOException("Could not find available port");
    }

    @Test(timeout = 10000)
    public void givenSolrWhenJobsWithBuildsAreExecutedThenTheyShouldBeSearchable()
            throws IOException, ExecutionException, InterruptedException, SAXException, URISyntaxException {
        jenkinsSearchBackend.setSolrBackend(false, solrPort);
        jenkinsSearchBackend.testBuildAndRebuild();
    }
}
{'fraction_non_alphanumeric': 0.1162109375, 'fraction_numerical': 0.00732421875, 'mean_word_length': 3.0599603567889, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6004284', 'n_tokens_mistral': 2424, 'n_tokens_neox': 2300, 'n_words': 419}