Skip to content
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion gradle/validation/spotless.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ configure(project(":solr").subprojects) { prj ->
// Exclude certain files (generated ones, mostly).
switch (project.path) {
case ":solr:core":
targetExclude "src/**/*.java"
targetExclude "src/java/**/*.java"
break
case ":solr:solrj":
targetExclude "src/test/org/apache/solr/client/solrj/io/stream/*.java"
Expand Down
92 changes: 44 additions & 48 deletions solr/core/src/test/org/apache/solr/AnalysisAfterCoreReloadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
*/
package org.apache.solr;

import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import org.apache.commons.io.FileUtils;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
Expand All @@ -28,22 +35,14 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;

public class AnalysisAfterCoreReloadTest extends SolrTestCaseJ4 {

private static String tmpSolrHome;
int port = 0;
static final String context = "/solr";

static final String collection = "collection1";

@BeforeClass
public static void beforeClass() throws Exception {
tmpSolrHome = createTempDir().toFile().getAbsolutePath();
Expand All @@ -52,80 +51,78 @@ public static void beforeClass() throws Exception {
}

@AfterClass
public static void AfterClass() throws Exception {

}

public static void AfterClass() throws Exception {}

public void testStopwordsAfterCoreReload() throws Exception {
SolrInputDocument doc = new SolrInputDocument();
doc.setField( "id", "42" );
doc.setField( "teststop", "terma stopworda stopwordb stopwordc" );
doc.setField("id", "42");
doc.setField("teststop", "terma stopworda stopwordb stopwordc");

// default stopwords - stopworda and stopwordb

UpdateRequest up = new UpdateRequest();
up.setAction(ACTION.COMMIT, true, true);
up.add( doc );
up.process( getSolrCore() );
up.add(doc);
up.process(getSolrCore());

SolrQuery q = new SolrQuery();
QueryRequest r = new QueryRequest( q );
q.setQuery( "teststop:terma" );
assertEquals( 1, r.process( getSolrCore() ).getResults().size() );
QueryRequest r = new QueryRequest(q);
q.setQuery("teststop:terma");
assertEquals(1, r.process(getSolrCore()).getResults().size());

q = new SolrQuery();
r = new QueryRequest( q );
q.setQuery( "teststop:stopworda" );
assertEquals( 0, r.process( getSolrCore() ).getResults().size() );
r = new QueryRequest(q);
q.setQuery("teststop:stopworda");
assertEquals(0, r.process(getSolrCore()).getResults().size());

q = new SolrQuery();
r = new QueryRequest( q );
q.setQuery( "teststop:stopwordb" );
assertEquals( 0, r.process( getSolrCore() ).getResults().size() );
r = new QueryRequest(q);
q.setQuery("teststop:stopwordb");
assertEquals(0, r.process(getSolrCore()).getResults().size());

q = new SolrQuery();
r = new QueryRequest( q );
q.setQuery( "teststop:stopwordc" );
assertEquals( 1, r.process( getSolrCore() ).getResults().size() );
r = new QueryRequest(q);
q.setQuery("teststop:stopwordc");
assertEquals(1, r.process(getSolrCore()).getResults().size());

// overwrite stopwords file with stopword list ["stopwordc"] and reload the core
overwriteStopwords("stopwordc\n");
h.getCoreContainer().reload(collection);

up.process( getSolrCore() );
up.process(getSolrCore());

q = new SolrQuery();
r = new QueryRequest( q );
q.setQuery( "teststop:terma" );
assertEquals( 1, r.process( getSolrCore() ).getResults().size() );
r = new QueryRequest(q);
q.setQuery("teststop:terma");
assertEquals(1, r.process(getSolrCore()).getResults().size());

q = new SolrQuery();
r = new QueryRequest( q );
q.setQuery( "teststop:stopworda" );
r = new QueryRequest(q);
q.setQuery("teststop:stopworda");
// stopworda is no longer a stopword
assertEquals( 1, r.process( getSolrCore() ).getResults().size() );
assertEquals(1, r.process(getSolrCore()).getResults().size());

q = new SolrQuery();
r = new QueryRequest( q );
q.setQuery( "teststop:stopwordb" );
r = new QueryRequest(q);
q.setQuery("teststop:stopwordb");
// stopwordb is no longer a stopword
assertEquals( 1, r.process( getSolrCore() ).getResults().size() );
assertEquals(1, r.process(getSolrCore()).getResults().size());

q = new SolrQuery();
r = new QueryRequest( q );
q.setQuery( "teststop:stopwordc" );
r = new QueryRequest(q);
q.setQuery("teststop:stopwordc");
// stopwordc should be a stopword
assertEquals( 0, r.process( getSolrCore() ).getResults().size() );
assertEquals(0, r.process(getSolrCore()).getResults().size());
}

private void overwriteStopwords(String stopwords) throws IOException {
try (SolrCore core = h.getCoreContainer().getCore(collection)) {
Path configPath = core.getResourceLoader().getConfigPath();
Files.move(configPath.resolve("stopwords.txt"), configPath.resolve("stopwords.txt.bak"));
Files.write(configPath.resolve("stopwords.txt"), stopwords.getBytes(StandardCharsets.UTF_8));
}
}

@Override
public void tearDown() throws Exception {
Path configPath;
Expand All @@ -142,5 +139,4 @@ public void tearDown() throws Exception {
protected SolrClient getSolrCore() {
return new EmbeddedSolrServer(h.getCoreContainer(), collection);
}

}
Loading