tests: convert to junit4 and fix bugs

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@954609 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2010-06-14 19:45:44 +00:00
parent 36ca32598f
commit 9427cad502
2 changed files with 37 additions and 40 deletions

View File

@ -17,53 +17,37 @@
package org.apache.solr.search.function; package org.apache.solr.search.function;
import org.apache.lucene.analysis.ngram.EdgeNGramTokenFilter; import org.apache.lucene.search.FieldCache;
import org.apache.lucene.queryParser.ParseException; import org.apache.solr.SolrTestCaseJ4;
import org.apache.lucene.search.Query; import org.junit.BeforeClass;
import org.apache.solr.search.ValueSourceParser; import org.junit.Test;
import org.apache.solr.search.FunctionQParser;
import org.apache.solr.search.function.DocValues;
import org.apache.solr.search.function.QueryValueSource;
import org.apache.solr.search.function.SimpleFloatFunction;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.util.AbstractSolrTestCase;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrCore;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.Arrays;
import java.io.File; import static org.junit.Assert.assertTrue;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.FileOutputStream;
/** /**
* Tests some basic functionality of Solr while demonstrating good * Tests some basic functionality of Solr while demonstrating good
* Best Practices for using AbstractSolrTestCase * Best Practices for using AbstractSolrTestCase
*/ */
public class TestFunctionQuery extends AbstractSolrTestCase { public class TestFunctionQuery extends SolrTestCaseJ4 {
@BeforeClass
public String getSchemaFile() { return "schema11.xml"; } public static void beforeClass() throws Exception {
public String getSolrConfigFile() { return "solrconfig-functionquery.xml"; } initCore("solrconfig-functionquery.xml","schema11.xml");
public String getCoreName() { return "basic"; }
public void setUp() throws Exception {
// if you override setUp or tearDown, you better call
// the super classes version
super.setUp();
}
public void tearDown() throws Exception {
// if you override setUp or tearDown, you better call
// the super classes version
super.tearDown();
} }
String base = "external_foo_extf"; String base = "external_foo_extf";
static long start = System.currentTimeMillis();
void makeExternalFile(String field, String contents, String charset) { void makeExternalFile(String field, String contents, String charset) {
String dir = h.getCore().getDataDir(); String dir = h.getCore().getDataDir();
String filename = dir + "/external_" + field + "." + System.currentTimeMillis(); String filename = dir + "/external_" + field + "." + (start++);
try { try {
Writer out = new OutputStreamWriter(new FileOutputStream(filename), charset); Writer out = new OutputStreamWriter(new FileOutputStream(filename), charset);
out.write(contents); out.write(contents);
@ -196,14 +180,18 @@ public class TestFunctionQuery extends AbstractSolrTestCase {
singleTest(field,"sum(query($v1,5),query($v1,7))", singleTest(field,"sum(query($v1,5),query($v1,7))",
Arrays.asList("v1","\0:[* TO *]"), 88,12 Arrays.asList("v1","\0:[* TO *]"), 88,12
); );
purgeFieldCache(FieldCache.DEFAULT); // avoid FC insanity
} }
@Test
public void testFunctions() { public void testFunctions() {
doTest("foo_pf"); // a plain float field doTest("foo_pf"); // a plain float field
doTest("foo_f"); // a sortable float field doTest("foo_f"); // a sortable float field
doTest("foo_tf"); // a trie float field doTest("foo_tf"); // a trie float field
} }
@Test
public void testExternalField() { public void testExternalField() {
String field = "foo_extf"; String field = "foo_extf";
@ -225,6 +213,7 @@ public class TestFunctionQuery extends AbstractSolrTestCase {
makeExternalFile(field, "0=1","UTF-8"); makeExternalFile(field, "0=1","UTF-8");
assertU(adoc("id", "10000")); // will get same reader if no index change assertU(adoc("id", "10000")); // will get same reader if no index change
assertU(commit()); assertU(commit());
singleTest(field, "sqrt(\0)");
assertTrue(orig != FileFloatSource.onlyForTesting); assertTrue(orig != FileFloatSource.onlyForTesting);
@ -276,9 +265,14 @@ public class TestFunctionQuery extends AbstractSolrTestCase {
singleTest(field, "\0", answers); singleTest(field, "\0", answers);
// System.out.println("Done test "+i); // System.out.println("Done test "+i);
} }
purgeFieldCache(FieldCache.DEFAULT); // avoid FC insanity
} }
@Test
public void testGeneral() throws Exception { public void testGeneral() throws Exception {
clearIndex();
assertU(adoc("id","1", "a_tdt","2009-08-31T12:10:10.123Z", "b_tdt","2009-08-31T12:10:10.124Z")); assertU(adoc("id","1", "a_tdt","2009-08-31T12:10:10.123Z", "b_tdt","2009-08-31T12:10:10.124Z"));
assertU(adoc("id","2")); assertU(adoc("id","2"));
assertU(commit()); // create more than one segment assertU(commit()); // create more than one segment
@ -327,11 +321,12 @@ public class TestFunctionQuery extends AbstractSolrTestCase {
assertQ(req("fl","*,score","q", q, "qq","text:batman", "fq",fq), "//float[@name='score']<'1.0'"); assertQ(req("fl","*,score","q", q, "qq","text:batman", "fq",fq), "//float[@name='score']<'1.0'");
assertQ(req("fl","*,score","q", q, "qq","text:superman", "fq",fq), "//float[@name='score']>'1.0'"); assertQ(req("fl","*,score","q", q, "qq","text:superman", "fq",fq), "//float[@name='score']>'1.0'");
doTestDegreeRads();
doTestFuncs(); purgeFieldCache(FieldCache.DEFAULT); // avoid FC insanity
} }
public void doTestDegreeRads() throws Exception { @Test
public void testDegreeRads() throws Exception {
assertU(adoc("id", "1", "x_td", "0", "y_td", "0")); assertU(adoc("id", "1", "x_td", "0", "y_td", "0"));
assertU(adoc("id", "2", "x_td", "90", "y_td", String.valueOf(Math.PI / 2))); assertU(adoc("id", "2", "x_td", "90", "y_td", String.valueOf(Math.PI / 2)));
assertU(adoc("id", "3", "x_td", "45", "y_td", String.valueOf(Math.PI / 4))); assertU(adoc("id", "3", "x_td", "45", "y_td", String.valueOf(Math.PI / 4)));
@ -347,6 +342,7 @@ public class TestFunctionQuery extends AbstractSolrTestCase {
assertQ(req("fl", "*,score", "q", "{!func}deg(y_td)", "fq", "id:3"), "//float[@name='score']='45.0'"); assertQ(req("fl", "*,score", "q", "{!func}deg(y_td)", "fq", "id:3"), "//float[@name='score']='45.0'");
} }
@Test
public void testStrDistance() throws Exception { public void testStrDistance() throws Exception {
assertU(adoc("id", "1", "x_s", "foil")); assertU(adoc("id", "1", "x_s", "foil"));
assertU(commit()); assertU(commit());
@ -363,7 +359,8 @@ public class TestFunctionQuery extends AbstractSolrTestCase {
"//float[@name='score']='" + sval + "'"); "//float[@name='score']='" + sval + "'");
} }
public void doTestFuncs() throws Exception { @Test
public void testFuncs() throws Exception {
assertU(adoc("id", "1", "foo_d", "9")); assertU(adoc("id", "1", "foo_d", "9"));
assertU(commit()); assertU(commit());

View File

@ -114,13 +114,13 @@
class="solr.search.LRUCache" class="solr.search.LRUCache"
size="512" size="512"
initialSize="512" initialSize="512"
autowarmCount="256"/> autowarmCount="0"/>
<queryResultCache <queryResultCache
class="solr.search.LRUCache" class="solr.search.LRUCache"
size="512" size="512"
initialSize="512" initialSize="512"
autowarmCount="1024"/> autowarmCount="0"/>
<documentCache <documentCache
class="solr.search.LRUCache" class="solr.search.LRUCache"