lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yonik Seeley <yo...@lucidimagination.com>
Subject Re: solr test development
Date Fri, 15 Oct 2010 21:06:35 GMT
Related: please try and not create new solrconfig.xml or schema.xml
objects unless you need to.
And if you do, and it's a really special purpose one, try cutting it
down to the bare minimum needed to get the test to work.

Example: I just cut down solrconfig-altdirectory.xml to this:
<config>
  <requestHandler name="standard"
class="solr.StandardRequestHandler"></requestHandler>
  <directoryFactory name="DirectoryFactory"
class="org.apache.solr.core.AlternateDirectoryTest$TestFSDirectoryFactory"></directoryFactory>
  <indexReaderFactory name="IndexReaderFactory"
class="org.apache.solr.core.AlternateDirectoryTest$TestIndexReaderFactory"></indexReaderFactory
>
</config>


-Yonik
http://www.lucidimagination.com



On Fri, Oct 15, 2010 at 9:48 AM, Yonik Seeley
<yonik@lucidimagination.com> wrote:
> Maintaining and fixing tests in solr has been a pain - I think mostly
> because in the past we probably reviewed core code well, but perhaps
> not the test code.  For test code, we should really strive for
> conciseness and maintainability.  Most things should be tested through
> higher level requests, and not by poking around in the guts (which
> makes it very hard to change how something is implemented).
>
> I've been rewriting some broken tests... for example replacing this:
>
>  @Test
>  public void testBasics() throws Exception {
>    SolrCore core = h.getCore();
>    SearchComponent tvComp = core.getSearchComponent("tvComponent");
>    assertTrue("tvComp is null and it shouldn't be", tvComp != null);
>    ModifiableSolrParams params = new ModifiableSolrParams();
>    params.add(CommonParams.Q, "id:0");
>    params.add(CommonParams.QT, "tvrh");
>    params.add(TermVectorParams.TF, "true");
>    params.add(TermVectorComponent.COMPONENT_NAME, "true");
>    SolrRequestHandler handler = core.getRequestHandler("tvrh");
>    SolrQueryResponse rsp;
>    rsp = new SolrQueryResponse();
>    rsp.add("responseHeader", new SimpleOrderedMap());
>    handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
>    NamedList values = rsp.getValues();
>    NamedList termVectors = (NamedList)
> values.get(TermVectorComponent.TERM_VECTORS);
>    assertTrue("termVectors is null and it shouldn't be", termVectors != null);
>    if (VERBOSE) System.out.println("TVs:" + termVectors);
>    NamedList doc = (NamedList) termVectors.getVal(0);
>    assertTrue("doc is null and it shouldn't be", doc != null);
>    assertEquals(doc.size(), 5);
>    NamedList field = (NamedList) doc.get("test_posofftv");
>    assertTrue("field is null and it shouldn't be", field != null);
>    assertTrue(field.size() + " does not equal: " + 2, field.size() == 2);
>    NamedList titl = (NamedList) field.get("titl");
>    assertTrue("titl is null and it shouldn't be", titl != null);
>    assertTrue(titl.get("tf") + " does not equal: " + 2, ((Integer)
> titl.get("tf")) == 2);
>    //there should not be any positions or offsets
>    NamedList positions = (NamedList) titl.get("positions");
>    assertTrue("positions is not null and it should be", positions == null);
>    NamedList offsets = (NamedList) titl.get("offsets");
>    assertTrue("offsets is not null and it should be", offsets == null);
>    String uniqueKeyFieldName = (String) termVectors.getVal(1);
>    assertTrue("uniqueKeyFieldName is null and it shouldn't be",
> uniqueKeyFieldName != null);
>    assertTrue(uniqueKeyFieldName + " is not equal to " + "id",
> uniqueKeyFieldName.equals("id") == true);
>  }
>
>
> With this:
>
>  @Test
>  public void testBasics() throws Exception {
>    assertJQ(req("json.nl","map", "qt",tv, "q", "id:0",
> TermVectorComponent.COMPONENT_NAME, "true", TermVectorParams.TF,
> "true")
>       ,"/termVectors=={'doc-0':{'uniqueKey':'0'," +
>            " 'test_basictv':{'anoth':{'tf':1},'titl':{'tf':2}}," +
>            " 'test_offtv':{'anoth':{'tf':1},'titl':{'tf':2}}," +
>            " 'test_posofftv':{'anoth':{'tf':1},'titl':{'tf':2}}," +
>            " 'test_postv':{'anoth':{'tf':1},'titl':{'tf':2}}}," +
>            " 'uniqueKeyFieldName':'id'}"
>    );
>  }
>
> I think it's clear which is more easily understandable and
> maintainable, and doesn't leak resources.
>
> -Yonik
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


Mime
View raw message