Skip to content

Commit

Permalink
SOLR-13539: Introduce EmbeddedSolrServerTestBase
Browse files Browse the repository at this point in the history
This groundwork commit allows tests to randomize request content-type
more flexibly.  This will be taken advantage of by subsequent commits.

Co-Authored-By: Thomas Woeckinger
Closes: #755
  • Loading branch information
gerlowskija committed Aug 29, 2019
1 parent f276651 commit 319cb00
Show file tree
Hide file tree
Showing 12 changed files with 244 additions and 97 deletions.
4 changes: 2 additions & 2 deletions solr/core/src/test/org/apache/solr/update/RootFieldTest.java
Expand Up @@ -17,7 +17,7 @@

package org.apache.solr.update;

import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.EmbeddedSolrServerTestBase;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.common.SolrDocument;
Expand All @@ -32,7 +32,7 @@

import static org.hamcrest.CoreMatchers.is;

public class RootFieldTest extends SolrJettyTestBase {
public class RootFieldTest extends EmbeddedSolrServerTestBase {
private static boolean useRootSchema;
private static final String MESSAGE = "Update handler should create and process _root_ field " +
"unless there is no such a field in schema";
Expand Down
34 changes: 17 additions & 17 deletions solr/solrj/src/test/org/apache/solr/client/solrj/GetByIdTest.java
Expand Up @@ -18,7 +18,7 @@

import java.util.Arrays;

import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.EmbeddedSolrServerTestBase;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.params.CommonParams;
Expand All @@ -27,13 +27,13 @@
import org.junit.BeforeClass;
import org.junit.Test;

public class GetByIdTest extends SolrJettyTestBase {
public class GetByIdTest extends EmbeddedSolrServerTestBase {

@BeforeClass
public static void beforeClass() throws Exception {
initCore();
}

@Before
@Override
public void setUp() throws Exception {
Expand All @@ -43,39 +43,39 @@ public void setUp() throws Exception {
sdoc("id", "1", "term_s", "Microsoft", "term2_s", "MSFT"),
sdoc("id", "2", "term_s", "Apple", "term2_s", "AAPL"),
sdoc("id", "3", "term_s", "Yahoo", "term2_s", "YHOO")));

getSolrClient().commit(true, true);
}

@Test
public void testGetId() throws Exception {
SolrDocument rsp = getSolrClient().getById("0");
assertNull(rsp);

rsp = getSolrClient().getById("1");
assertEquals("1", rsp.get("id"));
assertEquals("Microsoft", rsp.get("term_s"));
assertEquals("MSFT", rsp.get("term2_s"));

rsp = getSolrClient().getById("2");
rsp = getSolrClient().getById("2");
assertEquals("2", rsp.get("id"));
assertEquals("Apple", rsp.get("term_s"));
assertEquals("AAPL", rsp.get("term2_s"));
}

@Test
public void testGetIdWithParams() throws Exception {
final SolrParams ID_FL_ONLY = params(CommonParams.FL, "id");

SolrDocument rsp = getSolrClient().getById("0", ID_FL_ONLY);
assertNull(rsp);

rsp = getSolrClient().getById("1", ID_FL_ONLY);
assertEquals("1", rsp.get("id"));
assertNull("This field should have been removed from the response.", rsp.get("term_s"));
assertNull("This field should have been removed from the response.", rsp.get("term2_s"));

rsp = getSolrClient().getById("2", ID_FL_ONLY);
rsp = getSolrClient().getById("2", ID_FL_ONLY);
assertEquals("2", rsp.get("id"));
assertNull("This field should have been removed from the response.", rsp.get("term_s"));
assertNull("This field should have been removed from the response.", rsp.get("term2_s"));
Expand All @@ -88,25 +88,25 @@ public void testGetIds() throws Exception {
assertEquals("1", rsp.get(0).get("id"));
assertEquals("Microsoft", rsp.get(0).get("term_s"));
assertEquals("MSFT", rsp.get(0).get("term2_s"));

assertEquals("2", rsp.get(1).get("id"));
assertEquals("Apple", rsp.get(1).get("term_s"));
assertEquals("AAPL", rsp.get(1).get("term2_s"));

assertEquals("3", rsp.get(2).get("id"));
assertEquals("Yahoo", rsp.get(2).get("term_s"));
assertEquals("YHOO", rsp.get(2).get("term2_s"));
}

@Test
public void testGetIdsWithParams() throws Exception {
SolrDocumentList rsp = getSolrClient().getById(Arrays.asList("0", "1", "2"), params(CommonParams.FL, "id"));
assertEquals(2, rsp.getNumFound());

assertEquals("1", rsp.get(0).get("id"));
assertNull("This field should have been removed from the response.", rsp.get(0).get("term_s"));
assertNull("This field should have been removed from the response.", rsp.get(0).get("term2_s"));

assertEquals("2", rsp.get(1).get("id"));
assertNull("This field should have been removed from the response.", rsp.get(1).get("term_s"));
assertNull("This field should have been removed from the response.", rsp.get(1).get("term2_s"));
Expand Down
Expand Up @@ -16,7 +16,12 @@
*/
package org.apache.solr.client.solrj;

import org.apache.solr.SolrJettyTestBase;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;

import org.apache.solr.EmbeddedSolrServerTestBase;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.UpdateResponse;
Expand All @@ -25,16 +30,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;

/**
*
* @since solr 1.3
*/
public abstract class LargeVolumeTestBase extends SolrJettyTestBase
public abstract class LargeVolumeTestBase extends EmbeddedSolrServerTestBase
{
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

Expand Down
Expand Up @@ -27,6 +27,6 @@
public class LargeVolumeBinaryJettyTest extends LargeVolumeTestBase {
@BeforeClass
public static void beforeTest() throws Exception {
createAndStartJetty(legacyExampleCollection1SolrHome());
initCore();
}
}
Expand Up @@ -24,6 +24,6 @@
public class LargeVolumeJettyTest extends LargeVolumeTestBase {
@BeforeClass
public static void beforeTest() throws Exception {
createAndStartJetty(legacyExampleCollection1SolrHome());
initCore();
}
}
Expand Up @@ -29,6 +29,6 @@ public class SolrExampleEmbeddedTest extends SolrExampleTests {

@BeforeClass
public static void beforeTest() throws Exception {
initCore();
createAndStartJetty(legacyExampleCollection1SolrHome());
}
}
Expand Up @@ -16,23 +16,23 @@
*/
package org.apache.solr.client.solrj.request;

import junit.framework.Assert;
import java.io.File;

import org.apache.commons.io.FileUtils;
import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.EmbeddedSolrServerTestBase;
import org.apache.solr.client.solrj.response.SolrPingResponse;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.File;
import junit.framework.Assert;

/**
* Test SolrPing in Solrj
*/
public class SolrPingTest extends SolrJettyTestBase {
public class SolrPingTest extends EmbeddedSolrServerTestBase {

@BeforeClass
public static void beforeClass() throws Exception {
Expand Down
Expand Up @@ -15,31 +15,33 @@
* limitations under the License.
*/
package org.apache.solr.client.solrj.response;

import java.util.List;
import junit.framework.Assert;

import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.EmbeddedSolrServerTestBase;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.response.TermsResponse.Term;
import org.apache.solr.common.SolrInputDocument;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import junit.framework.Assert;

/**
* Test for TermComponent's response in Solrj
*/
public class TermsResponseTest extends SolrJettyTestBase {

public class TermsResponseTest extends EmbeddedSolrServerTestBase {
@BeforeClass
public static void beforeTest() throws Exception {
public static void beforeClass() throws Exception {
initCore();
}

@Before
@Override
public void setUp() throws Exception{
public void setUp() throws Exception {
super.setUp();
clearIndex();
assertU(commit());
Expand All @@ -62,7 +64,7 @@ public void testTermsResponse() throws Exception {
query.setTermsPrefix("s");
query.addTermsField("terms_s");
query.setTermsMinCount(1);

QueryRequest request = new QueryRequest(query);
List<Term> terms = request.process(getSolrClient()).getTermsResponse().getTerms("terms_s");

Expand Down
Expand Up @@ -15,8 +15,10 @@
* limitations under the License.
*/
package org.apache.solr.client.solrj.response;
import junit.framework.Assert;
import org.apache.solr.SolrJettyTestBase;

import java.util.List;

import org.apache.solr.EmbeddedSolrServerTestBase;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.response.SpellCheckResponse.Collation;
Expand All @@ -27,20 +29,21 @@
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.List;
import junit.framework.Assert;

/**
* Test for SpellCheckComponent's response in Solrj
*
*
* @since solr 1.3
*/
public class TestSpellCheckResponse extends SolrJettyTestBase {
public class TestSpellCheckResponse extends EmbeddedSolrServerTestBase {

@BeforeClass
public static void beforeTest() throws Exception {
public static void beforeClass() throws Exception {
initCore();
}

static String field = "name";

@Test
Expand Down Expand Up @@ -101,7 +104,7 @@ public void testSpellCheckResponse_Extended() throws Exception {
// Hmmm... the API for SpellCheckResponse could be nicer:
response.getSuggestions().get(0).getAlternatives().get(0);
}

@Test
public void testSpellCheckCollationResponse() throws Exception {
getSolrClient();
Expand All @@ -128,7 +131,7 @@ public void testSpellCheckCollationResponse() throws Exception {
doc.setField("name", "fat of homer");
client.add(doc);
client.commit(true, true);

//Test Backwards Compatibility
SolrQuery query = new SolrQuery("name:(+fauth +home +loane)");
query.set(CommonParams.QT, "/spell");
Expand All @@ -139,15 +142,15 @@ public void testSpellCheckCollationResponse() throws Exception {
SpellCheckResponse response = request.process(client).getSpellCheckResponse();
response = request.process(client).getSpellCheckResponse();
assertTrue("name:(+faith +hope +loaves)".equals(response.getCollatedResult()));

//Test Expanded Collation Results
query.set(SpellingParams.SPELLCHECK_COLLATE_EXTENDED_RESULTS, true);
query.set(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, 10);
query.set(SpellingParams.SPELLCHECK_MAX_COLLATIONS, 2);
query.set(SpellingParams.SPELLCHECK_MAX_COLLATIONS, 2);
request = new QueryRequest(query);
response = request.process(client).getSpellCheckResponse();
assertTrue("name:(+faith +hope +love)".equals(response.getCollatedResult()) || "name:(+faith +hope +loaves)".equals(response.getCollatedResult()));

List<Collation> collations = response.getCollatedResults();
assertEquals(2, collations.size());
for(Collation collation : collations)
Expand All @@ -174,20 +177,20 @@ public void testSpellCheckCollationResponse() throws Exception {
}
}
}

query.set(SpellingParams.SPELLCHECK_COLLATE_EXTENDED_RESULTS, false);
response = request.process(client).getSpellCheckResponse();
{
collations = response.getCollatedResults();
assertEquals(2, collations.size());
String collation1 = collations.get(0).getCollationQueryString();
String collation2 = collations.get(1).getCollationQueryString();
assertFalse(collation1 + " equals " + collation2,
assertFalse(collation1 + " equals " + collation2,
collation1.equals(collation2));
for(Collation collation : collations) {
assertTrue("name:(+faith +hope +love)".equals(collation.getCollationQueryString()) || "name:(+faith +hope +loaves)".equals(collation.getCollationQueryString()));
}
}
}

}
}
Expand Up @@ -15,11 +15,12 @@
* limitations under the License.
*/
package org.apache.solr.client.solrj.response;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.EmbeddedSolrServerTestBase;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.QueryRequest;
Expand All @@ -32,9 +33,10 @@
* Test for SuggesterComponent's response in Solrj
*
*/
public class TestSuggesterResponse extends SolrJettyTestBase {
public class TestSuggesterResponse extends EmbeddedSolrServerTestBase {

@BeforeClass
public static void beforeTest() throws Exception {
public static void beforeClass() throws Exception {
initCore();
}

Expand Down

0 comments on commit 319cb00

Please sign in to comment.