Apache Lucene open-source search software
LTR Test Hardening:
Chris Hostetter3ed96026d353
diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRQParserExplain.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRQParserExplain.javaindex b4a821391f8..14fb7e1a0f9 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRQParserExplain.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRQParserExplain.java@@ -18,20 +18,20 @@ package org.apache.solr.ltr;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.model.LinearModel;-import org.junit.AfterClass;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestLTRQParserExplain extends TestRerankBase {- @BeforeClass- public static void setup() throws Exception {+ @Before+ public void setup() throws Exception {setuptest(true);loadFeatures("features-store-test-model.json");}- @AfterClass- public static void after() throws Exception {+ @After+ public void after() throws Exception {aftertest();}diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRWithFacet.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRWithFacet.javaindex db8fb38b3fc..31c2b761a59 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRWithFacet.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRWithFacet.java@@ -20,14 +20,14 @@ package org.apache.solr.ltr;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.feature.SolrFeature;import org.apache.solr.ltr.model.LinearModel;-import org.junit.AfterClass;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestLTRWithFacet extends TestRerankBase {- @BeforeClass- public static void before() throws Exception {+ @Before+ public void before() throws Exception {setuptest(false);assertU(adoc("id", "1", "title", "a1", "description", "E", "popularity",@@ -48,6 +48,12 @@ public class TestLTRWithFacet extends TestRerankBase {"D", "popularity", "8"));assertU(commit());}++ @After+ public void after() throws Exception {+ aftertest();+ }+@Testpublic void testRankingSolrFacet() throws Exception {@@ -91,13 +97,6 @@ public class TestLTRWithFacet extends TestRerankBase {assertJQ("/query" + query.toQueryString(), ""+ "/facet_counts/facet_fields/description=="+ "['b', 4, 'e', 2, 'c', 1, 'd', 1]");- // aftertest();-- }-- @AfterClass- public static void after() throws Exception {- aftertest();}}diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRWithSort.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRWithSort.javaindex c3c9857b19c..708fdc8105b 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRWithSort.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestLTRWithSort.java@@ -20,14 +20,14 @@ package org.apache.solr.ltr;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.feature.SolrFeature;import org.apache.solr.ltr.model.LinearModel;-import org.junit.AfterClass;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestLTRWithSort extends TestRerankBase {- @BeforeClass- public static void before() throws Exception {+ @Before+ public void before() throws Exception {setuptest(false);assertU(adoc("id", "1", "title", "a1", "description", "E", "popularity","1"));@@ -47,6 +47,11 @@ public class TestLTRWithSort extends TestRerankBase {"D", "popularity", "8"));assertU(commit());}++ @After+ public void after() throws Exception {+ aftertest();+ }@Testpublic void testRankingSolrSort() throws Exception {@@ -90,13 +95,6 @@ public class TestLTRWithSort extends TestRerankBase {assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='1'");assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/score==1.0");- // aftertest();-- }-- @AfterClass- public static void after() throws Exception {- aftertest();}}diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestRerankBase.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestRerankBase.javaindex 1cffeccf3d8..9d22cf4e9f8 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestRerankBase.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/TestRerankBase.java@@ -36,6 +36,7 @@ import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.util.ContentStream;import org.apache.solr.common.util.ContentStreamBase;import org.apache.solr.common.util.Utils;+import org.apache.solr.core.SolrCore;import org.apache.solr.core.SolrResourceLoader;import org.apache.solr.ltr.feature.Feature;import org.apache.solr.ltr.feature.FeatureException;@@ -129,11 +130,15 @@ public class TestRerankBase extends RestTestBase {}public static ManagedFeatureStore getManagedFeatureStore() {- return ManagedFeatureStore.getManagedFeatureStore(h.getCore());+ try (SolrCore core = jetty.getCoreContainer().getCore(DEFAULT_TEST_CORENAME)) {+ return ManagedFeatureStore.getManagedFeatureStore(core);+ }}public static ManagedModelStore getManagedModelStore() {- return ManagedModelStore.getManagedModelStore(h.getCore());+ try (SolrCore core = jetty.getCoreContainer().getCore(DEFAULT_TEST_CORENAME)) {+ return ManagedModelStore.getManagedModelStore(core);+ }}protected static SortedMap<ServletHolder,String> setupTestInit(@@ -192,7 +197,6 @@ public class TestRerankBase extends RestTestBase {public static void setuptest(String solrconfig, String schema)throws Exception {- initCore(solrconfig, schema);SortedMap<ServletHolder,String> extraServlets =setupTestInit(solrconfig,schema,false);@@ -204,7 +208,6 @@ public class TestRerankBase extends RestTestBase {public static void setupPersistentTest(String solrconfig, String schema)throws Exception {- initCore(solrconfig, schema);SortedMap<ServletHolder,String> extraServlets =setupTestInit(solrconfig,schema,true);diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestEdisMaxSolrFeature.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestEdisMaxSolrFeature.javaindex 4fd77e317cd..e162c8c467f 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestEdisMaxSolrFeature.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestEdisMaxSolrFeature.java@@ -19,14 +19,14 @@ package org.apache.solr.ltr.feature;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.model.LinearModel;-import org.junit.AfterClass;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestEdisMaxSolrFeature extends TestRerankBase {- @BeforeClass- public static void before() throws Exception {+ @Before+ public void before() throws Exception {setuptest(false);assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity",@@ -48,8 +48,8 @@ public class TestEdisMaxSolrFeature extends TestRerankBase {assertU(commit());}- @AfterClass- public static void after() throws Exception {+ @After+ public void after() throws Exception {aftertest();}diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFeatureLogging.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFeatureLogging.javaindex 52fe70ef088..e7af2506b5f 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFeatureLogging.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFeatureLogging.java@@ -21,19 +21,19 @@ import org.apache.solr.ltr.FeatureLoggerTestUtils;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.model.LinearModel;import org.apache.solr.ltr.store.FeatureStore;-import org.junit.AfterClass;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestFeatureLogging extends TestRerankBase {- @BeforeClass- public static void setup() throws Exception {+ @Before+ public void setup() throws Exception {setuptest(true);}- @AfterClass- public static void after() throws Exception {+ @After+ public void after() throws Exception {aftertest();}diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFieldLengthFeature.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFieldLengthFeature.javaindex 64f9778ca61..b913d1bd72b 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFieldLengthFeature.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFieldLengthFeature.java@@ -21,14 +21,14 @@ import java.util.LinkedHashMap;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.model.LinearModel;-import org.junit.AfterClass;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestFieldLengthFeature extends TestRerankBase {- @BeforeClass- public static void before() throws Exception {+ @Before+ public void before() throws Exception {setuptest(false);assertU(adoc("id", "1", "title", "w1", "description", "w1"));@@ -45,8 +45,8 @@ public class TestFieldLengthFeature extends TestRerankBase {assertU(commit());}- @AfterClass- public static void after() throws Exception {+ @After+ public void after() throws Exception {aftertest();}diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFieldValueFeature.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFieldValueFeature.javaindex ceaf6e6c8fd..108044b5cbd 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFieldValueFeature.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFieldValueFeature.java@@ -22,16 +22,16 @@ import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.FeatureLoggerTestUtils;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.model.LinearModel;-import org.junit.AfterClass;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestFieldValueFeature extends TestRerankBase {private static final float FIELD_VALUE_FEATURE_DEFAULT_VAL = 0.0f;- @BeforeClass- public static void before() throws Exception {+ @Before+ public void before() throws Exception {setuptest(false);assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity",@@ -63,8 +63,8 @@ public class TestFieldValueFeature extends TestRerankBase {new String[] {"popularity"}, "{\"weights\":{\"popularity\":1.0}}");}- @AfterClass- public static void after() throws Exception {+ @After+ public void after() throws Exception {aftertest();}diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFilterSolrFeature.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFilterSolrFeature.javaindex d3c72109fa5..d42176e55e2 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFilterSolrFeature.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestFilterSolrFeature.java@@ -21,13 +21,13 @@ import org.apache.solr.ltr.FeatureLoggerTestUtils;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.model.LinearModel;import org.apache.solr.ltr.store.rest.ManagedFeatureStore;-import org.junit.AfterClass;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestFilterSolrFeature extends TestRerankBase {- @BeforeClass- public static void before() throws Exception {+ @Before+ public void before() throws Exception {setuptest(false);assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity",@@ -49,8 +49,8 @@ public class TestFilterSolrFeature extends TestRerankBase {assertU(commit());}- @AfterClass- public static void after() throws Exception {+ @After+ public void after() throws Exception {aftertest();}diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestNoMatchSolrFeature.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestNoMatchSolrFeature.javaindex a9395bf31a1..48c1262c547 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestNoMatchSolrFeature.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestNoMatchSolrFeature.java@@ -25,14 +25,14 @@ import org.apache.solr.ltr.FeatureLoggerTestUtils;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.model.LinearModel;import org.apache.solr.ltr.model.MultipleAdditiveTreesModel;-import org.junit.AfterClass;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestNoMatchSolrFeature extends TestRerankBase {- @BeforeClass- public static void before() throws Exception {+ @Before+ public void before() throws Exception {setuptest(false);assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity",@@ -78,8 +78,8 @@ public class TestNoMatchSolrFeature extends TestRerankBase {"{\"weights\":{\"nomatchfeature4\":1.0}}");}- @AfterClass- public static void after() throws Exception {+ @After+ public void after() throws Exception {aftertest();}diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestOriginalScoreFeature.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestOriginalScoreFeature.javaindex b0af388ddca..8ff56842605 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestOriginalScoreFeature.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestOriginalScoreFeature.java@@ -26,14 +26,14 @@ import org.apache.solr.common.util.Utils;import org.apache.solr.ltr.FeatureLoggerTestUtils;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.model.LinearModel;-import org.junit.AfterClass;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestOriginalScoreFeature extends TestRerankBase {- @BeforeClass- public static void before() throws Exception {+ @Before+ public void before() throws Exception {setuptest(false);assertU(adoc("id", "1", "title", "w1"));@@ -47,8 +47,8 @@ public class TestOriginalScoreFeature extends TestRerankBase {assertU(commit());}- @AfterClass- public static void after() throws Exception {+ @After+ public void after() throws Exception {aftertest();}diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestRankingFeature.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestRankingFeature.javaindex 8db1a4bceb4..eab96105684 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestRankingFeature.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestRankingFeature.java@@ -21,15 +21,15 @@ import java.util.LinkedHashMap;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.model.LinearModel;-import org.junit.AfterClass;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestRankingFeature extends TestRerankBase {- @BeforeClass- public static void before() throws Exception {+ @Before+ public void before() throws Exception {setuptest(false);assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity",@@ -51,8 +51,8 @@ public class TestRankingFeature extends TestRerankBase {assertU(commit());}- @AfterClass- public static void after() throws Exception {+ @After+ public void after() throws Exception {aftertest();}@@ -118,7 +118,6 @@ public class TestRankingFeature extends TestRerankBase {"/error/msg/=='"+FeatureException.class.getName()+": " +"java.lang.UnsupportedOperationException: " +"Unable to extract feature for powdesS'");- // aftertest();}diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScoreWithQ.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScoreWithQ.javaindex 8ca63124d72..9b7e7683d16 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScoreWithQ.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScoreWithQ.java@@ -19,14 +19,14 @@ package org.apache.solr.ltr.feature;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.model.LinearModel;-import org.junit.AfterClass;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestUserTermScoreWithQ extends TestRerankBase {- @BeforeClass- public static void before() throws Exception {+ @Before+ public void before() throws Exception {setuptest(false);assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity",@@ -48,8 +48,8 @@ public class TestUserTermScoreWithQ extends TestRerankBase {assertU(commit());}- @AfterClass- public static void after() throws Exception {+ @After+ public void after() throws Exception {aftertest();}diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorerQuery.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorerQuery.javaindex 29a537223ae..3b6b93d6392 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorerQuery.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorerQuery.java@@ -19,14 +19,14 @@ package org.apache.solr.ltr.feature;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.model.LinearModel;-import org.junit.AfterClass;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestUserTermScorerQuery extends TestRerankBase {- @BeforeClass- public static void before() throws Exception {+ @Before+ public void before() throws Exception {setuptest(false);assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity",@@ -48,8 +48,8 @@ public class TestUserTermScorerQuery extends TestRerankBase {assertU(commit());}- @AfterClass- public static void after() throws Exception {+ @After+ public void after() throws Exception {aftertest();}diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorereQDF.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorereQDF.javaindex 62061ca3694..b5882d5e8e2 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorereQDF.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestUserTermScorereQDF.java@@ -19,14 +19,14 @@ package org.apache.solr.ltr.feature;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.model.LinearModel;-import org.junit.AfterClass;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestUserTermScorereQDF extends TestRerankBase {- @BeforeClass- public static void before() throws Exception {+ @Before+ public void before() throws Exception {setuptest(false);assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity",@@ -48,8 +48,8 @@ public class TestUserTermScorereQDF extends TestRerankBase {assertU(commit());}- @AfterClass- public static void after() throws Exception {+ @After+ public void after() throws Exception {aftertest();}diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestValueFeature.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestValueFeature.javaindex 56f9efbcc11..8a3b014f05c 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestValueFeature.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/feature/TestValueFeature.java@@ -21,14 +21,14 @@ import java.util.LinkedHashMap;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.TestRerankBase;import org.apache.solr.ltr.model.LinearModel;-import org.junit.AfterClass;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestValueFeature extends TestRerankBase {- @BeforeClass- public static void before() throws Exception {+ @Before+ public void before() throws Exception {setuptest(false);assertU(adoc("id", "1", "title", "w1"));@@ -42,8 +42,8 @@ public class TestValueFeature extends TestRerankBase {assertU(commit());}- @AfterClass- public static void after() throws Exception {+ @After+ public void after() throws Exception {aftertest();}diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestAdapterModel.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestAdapterModel.javaindex 09814011104..b0f8b1f28fd 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestAdapterModel.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestAdapterModel.java@@ -38,7 +38,8 @@ import org.apache.solr.ltr.feature.Feature;import org.apache.solr.ltr.feature.FieldValueFeature;import org.apache.solr.ltr.norm.Normalizer;import org.apache.solr.ltr.store.rest.ManagedModelStore;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestAdapterModel extends TestRerankBase {@@ -46,15 +47,15 @@ public class TestAdapterModel extends TestRerankBase {private static int numDocs = 0;private static float scoreValue;- @BeforeClass- public static void setupBeforeClass() throws Exception {+ @Before+ public void setup() throws Exception {setuptest(false);- for (int ii=1; ii<=random().nextInt(10); ++ii) {+ numDocs = random().nextInt(10);+ for (int ii=1; ii <= numDocs; ++ii) {String id = Integer.toString(ii);assertU(adoc("id", id, "popularity", ii+"00"));- ++numDocs;}assertU(commit());@@ -76,6 +77,10 @@ public class TestAdapterModel extends TestRerankBase {"{\"answerFileName\":\"" + scoreValueFile.getName() + "\"}");assertJPut(ManagedModelStore.REST_END_POINT, modelJson, "/responseHeader/status==0");}+ @After+ public void cleanup() throws Exception {+ aftertest();+ }@Testpublic void test() throws Exception {diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestDefaultWrapperModel.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestDefaultWrapperModel.javaindex 25e716a8251..00ed14d8ad5 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestDefaultWrapperModel.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestDefaultWrapperModel.java@@ -31,19 +31,19 @@ import org.apache.solr.ltr.feature.Feature;import org.apache.solr.ltr.feature.FieldValueFeature;import org.apache.solr.ltr.feature.ValueFeature;import org.apache.solr.ltr.store.rest.ManagedModelStore;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestDefaultWrapperModel extends TestRerankBase {final private static String featureStoreName = "test";- private static String baseModelJson = null;private static File baseModelFile = null;static List<Feature> features = null;- @BeforeClass- public static void setupBeforeClass() throws Exception {+ @Before+ public void setupBeforeClass() throws Exception {setuptest(false);assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity", "1"));assertU(adoc("id", "2", "title", "w2", "description", "w2", "popularity", "2"));@@ -58,7 +58,7 @@ public class TestDefaultWrapperModel extends TestRerankBase {features.add(getManagedFeatureStore().getFeatureStore("test").get("popularity"));features.add(getManagedFeatureStore().getFeatureStore("test").get("const"));- baseModelJson = getModelInJson("linear", LinearModel.class.getName(),+ final String baseModelJson = getModelInJson("linear", LinearModel.class.getName(),new String[] {"popularity", "const"},featureStoreName,"{\"weights\":{\"popularity\":-1.0, \"const\":1.0}}");@@ -70,6 +70,13 @@ public class TestDefaultWrapperModel extends TestRerankBase {}baseModelFile.deleteOnExit();}++ @After+ public void cleanup() throws Exception {+ features = null;+ baseModelFile = null;+ aftertest();+ }private static String getDefaultWrapperModelInJson(String wrapperModelName, String[] features, String params) {return getModelInJson(wrapperModelName, DefaultWrapperModel.class.getName(),diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestLinearModel.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestLinearModel.javaindex 0abba9105bf..d5950e640f0 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestLinearModel.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestLinearModel.java@@ -29,7 +29,8 @@ import org.apache.solr.ltr.norm.IdentityNormalizer;import org.apache.solr.ltr.norm.Normalizer;import org.apache.solr.ltr.store.FeatureStore;import org.apache.solr.ltr.store.rest.ManagedModelStore;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestLinearModel extends TestRerankBase {@@ -58,15 +59,21 @@ public class TestLinearModel extends TestRerankBase {static ManagedModelStore store = null;static FeatureStore fstore = null;- @BeforeClass- public static void setup() throws Exception {+ @Before+ public void setup() throws Exception {setuptest(true);// loadFeatures("features-store-test-model.json");store = getManagedModelStore();fstore = getManagedFeatureStore().getFeatureStore("test");}-+ @After+ public void cleanup() throws Exception {+ store = null;+ fstore = null;+ aftertest();+ }+@Testpublic void getInstanceTest() {final Map<String,Object> weights = new HashMap<>();diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestMultipleAdditiveTreesModel.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestMultipleAdditiveTreesModel.javaindex d57d2f39cb3..8cb59f2dd82 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestMultipleAdditiveTreesModel.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestMultipleAdditiveTreesModel.java@@ -18,17 +18,16 @@ package org.apache.solr.ltr.model;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.ltr.TestRerankBase;-import org.junit.AfterClass;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;import static org.hamcrest.core.StringContains.containsString;public class TestMultipleAdditiveTreesModel extends TestRerankBase {-- @BeforeClass- public static void before() throws Exception {+ @Before+ public void before() throws Exception {setuptest(false);assertU(adoc("id", "1", "title", "w1", "description", "w1", "popularity","1"));@@ -39,8 +38,8 @@ public class TestMultipleAdditiveTreesModel extends TestRerankBase {assertU(commit());}- @AfterClass- public static void after() throws Exception {+ @After+ public void after() throws Exception {aftertest();}diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestNeuralNetworkModel.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestNeuralNetworkModel.javaindex 9614733565f..045c625a218 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestNeuralNetworkModel.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/model/TestNeuralNetworkModel.java@@ -28,8 +28,8 @@ import org.apache.solr.ltr.feature.Feature;import org.apache.solr.ltr.norm.IdentityNormalizer;import org.apache.solr.ltr.norm.Normalizer;import org.apache.solr.util.SolrPluginUtils;-import org.junit.AfterClass;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestNeuralNetworkModel extends TestRerankBase {@@ -44,13 +44,13 @@ public class TestNeuralNetworkModel extends TestRerankBase {features, norms, featureStoreName, allFeatures, params);}- @BeforeClass- public static void setup() throws Exception {+ @Before+ public void setup() throws Exception {setuptest(false);}- @AfterClass- public static void after() throws Exception {+ @After+ public void after() throws Exception {aftertest();}diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestManagedFeatureStore.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestManagedFeatureStore.javaindex 9ee1ad4cdd7..1cd4f613d6a 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestManagedFeatureStore.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestManagedFeatureStore.java@@ -25,18 +25,25 @@ import org.apache.solr.ltr.feature.FeatureException;import org.apache.solr.ltr.feature.OriginalScoreFeature;import org.apache.solr.ltr.feature.ValueFeature;import org.apache.solr.ltr.store.FeatureStore;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestManagedFeatureStore extends SolrTestCaseJ4 {- private static ManagedFeatureStore fstore = null;+ private ManagedFeatureStore fstore = null;- @BeforeClass- public static void setup() throws Exception {+ @Before+ public void setup() throws Exception {initCore("solrconfig-ltr.xml", "schema.xml");fstore = ManagedFeatureStore.getManagedFeatureStore(h.getCore());}+ @After+ public void cleanup() throws Exception {+ fstore = null;+ deleteCore();+ }+private static Map<String,Object> createMap(String name, String className, Map<String,Object> params) {final Map<String,Object> map = new HashMap<String,Object>();diff --git a/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManagerPersistence.java b/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManagerPersistence.javaindex bd93027cbb4..0e829e68d95 100644--- a/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManagerPersistence.java+++ b/solr/contrib/ltr/src/test/org/apache/solr/ltr/store/rest/TestModelManagerPersistence.java@@ -35,15 +35,20 @@ import org.apache.solr.ltr.model.DefaultWrapperModel;import org.apache.solr.ltr.model.LinearModel;import org.apache.solr.ltr.norm.Normalizer;import org.apache.solr.ltr.store.FeatureStore;-import org.junit.BeforeClass;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestModelManagerPersistence extends TestRerankBase {- @BeforeClass- public static void init() throws Exception {+ @Before+ public void init() throws Exception {setupPersistenttest(true);}+ @After+ public void cleanup() throws Exception {+ aftertest();+ }// executed first@Test