diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-04-17 14:40:30 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-04-17 14:40:30 +0200 |
commit | c8cdfb65631a6814f2d85e18171badc9144ed33e (patch) | |
tree | f807a0a4a9fd288c658611e36e5e9bb25e740b65 /container-search/src/test/java/com/yahoo/search/searchchain | |
parent | 6b9f956080484c22e894ee0ccd2692c2f442a333 (diff) |
Remove usage of junit.framework
Diffstat (limited to 'container-search/src/test/java/com/yahoo/search/searchchain')
4 files changed, 50 insertions, 23 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/searchchain/test/AsyncExecutionOfOneChainTestCase.java b/container-search/src/test/java/com/yahoo/search/searchchain/test/AsyncExecutionOfOneChainTestCase.java index 44d5dc29a2d..182ec7568f3 100644 --- a/container-search/src/test/java/com/yahoo/search/searchchain/test/AsyncExecutionOfOneChainTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/searchchain/test/AsyncExecutionOfOneChainTestCase.java @@ -10,19 +10,24 @@ import com.yahoo.search.result.HitGroup; import com.yahoo.search.searchchain.AsyncExecution; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.searchchain.FutureResult; -import junit.framework.TestCase; +import org.junit.Test; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import static org.junit.Assert.assertEquals; + /** * @author bratseth */ -public class AsyncExecutionOfOneChainTestCase extends TestCase { +public class AsyncExecutionOfOneChainTestCase { + + private static final double delta = 0.0000001; /** Tests having a result with some slow source data which should pass directly to rendering */ + @Test public void testParallelExecutionOfOneChain() { // Setup Chain<Searcher> mainChain=new Chain<>(new ParallelExecutor(),new ResultProcessor(),new RegularProvider()); @@ -32,12 +37,12 @@ public class AsyncExecutionOfOneChainTestCase extends TestCase { // Verify assertEquals("Received 2 hits from 3 threads",3*2,result.hits().size()); - assertEquals(1.0, result.hits().get("thread-0:hit-0").getRelevance().getScore()); - assertEquals(1.0, result.hits().get("thread-1:hit-0").getRelevance().getScore()); - assertEquals(1.0, result.hits().get("thread-2:hit-0").getRelevance().getScore()); - assertEquals(0.5, result.hits().get("thread-0:hit-1").getRelevance().getScore()); - assertEquals(0.5, result.hits().get("thread-1:hit-1").getRelevance().getScore()); - assertEquals(0.5, result.hits().get("thread-2:hit-1").getRelevance().getScore()); + assertEquals(1.0, result.hits().get("thread-0:hit-0").getRelevance().getScore(), delta); + assertEquals(1.0, result.hits().get("thread-1:hit-0").getRelevance().getScore(), delta); + assertEquals(1.0, result.hits().get("thread-2:hit-0").getRelevance().getScore(), delta); + assertEquals(0.5, result.hits().get("thread-0:hit-1").getRelevance().getScore(), delta); + assertEquals(0.5, result.hits().get("thread-1:hit-1").getRelevance().getScore(), delta); + assertEquals(0.5, result.hits().get("thread-2:hit-1").getRelevance().getScore(), delta); } private class ParallelExecutor extends Searcher { diff --git a/container-search/src/test/java/com/yahoo/search/searchchain/test/AsyncExecutionTestCase.java b/container-search/src/test/java/com/yahoo/search/searchchain/test/AsyncExecutionTestCase.java index c5d756e81e1..9ea637a5554 100644 --- a/container-search/src/test/java/com/yahoo/search/searchchain/test/AsyncExecutionTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/searchchain/test/AsyncExecutionTestCase.java @@ -10,17 +10,24 @@ import com.yahoo.search.result.Hit; import com.yahoo.search.searchchain.AsyncExecution; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.searchchain.FutureResult; +import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + /** * Test for aynchrounous execution - * @author <a href="mailto:arnebef@yahoo-inc.com">Arne Bergene Fossaa</a> + * + * @author Arne Bergene Fossaa */ -public class AsyncExecutionTestCase extends junit.framework.TestCase { +public class AsyncExecutionTestCase { public class WaitingSearcher extends Searcher { @@ -50,7 +57,8 @@ public class AsyncExecutionTestCase extends junit.framework.TestCase { } - //This should take ~50+ ms + // This should take ~50+ ms + @Test public void testAsync() { List<Searcher> searchList = new ArrayList<>(); searchList.add(new WaitingSearcher("one",60000)); @@ -64,6 +72,7 @@ public class AsyncExecutionTestCase extends junit.framework.TestCase { assertTrue(result.hits().getError() != null); } + @Test public void testWaitForAll() { Chain<Searcher> slowChain = new Chain<>( new ComponentId("slow"), @@ -89,6 +98,7 @@ public class AsyncExecutionTestCase extends junit.framework.TestCase { assertNull(results.get(1).hits().getErrorHit()); } + @Test public void testSync() { Query query=new Query("?query=test"); Searcher searcher=new ResultProducingSearcher(); @@ -98,6 +108,7 @@ public class AsyncExecutionTestCase extends junit.framework.TestCase { assertEquals("hello",result.hits().get(0).getField("test")); } + @Test public void testSyncThroughSync() { Query query=new Query("?query=test"); Searcher searcher=new ResultProducingSearcher(); @@ -107,6 +118,7 @@ public class AsyncExecutionTestCase extends junit.framework.TestCase { assertEquals("hello",result.hits().get(0).getField("test")); } + @Test public void testAsyncThroughSync() { Query query=new Query("?query=test"); Searcher searcher=new ResultProducingSearcher(); @@ -134,7 +146,6 @@ public class AsyncExecutionTestCase extends junit.framework.TestCase { } - @SuppressWarnings("deprecation") public void testAsyncExecutionTimeout() { Chain<Searcher> chain = new Chain<>(new Searcher() { @Override diff --git a/container-search/src/test/java/com/yahoo/search/searchchain/test/ExecutionTestCase.java b/container-search/src/test/java/com/yahoo/search/searchchain/test/ExecutionTestCase.java index fb9af72a715..c3ccccdc5be 100644 --- a/container-search/src/test/java/com/yahoo/search/searchchain/test/ExecutionTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/searchchain/test/ExecutionTestCase.java @@ -19,14 +19,21 @@ import com.yahoo.search.result.Hit; import com.yahoo.search.searchchain.Execution; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + /** * Tests basic search chain execution functionality * * @author bratseth */ -@SuppressWarnings("deprecation") -public class ExecutionTestCase extends junit.framework.TestCase { +public class ExecutionTestCase { + @Test public void testLinearExecutions() { // Make a chain List<Searcher> searchers1=new ArrayList<>(); @@ -58,6 +65,7 @@ public class ExecutionTestCase extends junit.framework.TestCase { assertNotNull(result2.hits().get("searcher6-1")); } + @Test public void testNestedExecution() { // Make a chain List<Searcher> searchers1=new ArrayList<>(); @@ -81,6 +89,7 @@ public class ExecutionTestCase extends junit.framework.TestCase { assertNotNull(result1.hits().get("searcher3-2-filled")); } + @Test public void testContextCacheSingleLengthSearchChain() { IndexFacts[] contextsBefore = new IndexFacts[1]; IndexFacts[] contextsAfter = new IndexFacts[1]; @@ -93,6 +102,7 @@ public class ExecutionTestCase extends junit.framework.TestCase { assertSame(contextsBefore[0], contextsAfter[0]); } + @Test public void testContextCache() { IndexFacts[] contextsBefore = new IndexFacts[5]; IndexFacts[] contextsAfter = new IndexFacts[5]; @@ -118,6 +128,7 @@ public class ExecutionTestCase extends junit.framework.TestCase { assertSame(contextsBefore[3], contextsBefore[4]); } + @Test public void testContextCacheMoreSearchers() { IndexFacts[] contextsBefore = new IndexFacts[7]; IndexFacts[] contextsAfter = new IndexFacts[7]; @@ -299,5 +310,4 @@ public class ExecutionTestCase extends junit.framework.TestCase { } - } diff --git a/container-search/src/test/java/com/yahoo/search/searchchain/test/VespaAsyncSearcherTest.java b/container-search/src/test/java/com/yahoo/search/searchchain/test/VespaAsyncSearcherTest.java index 9c7be743460..567b73783b1 100644 --- a/container-search/src/test/java/com/yahoo/search/searchchain/test/VespaAsyncSearcherTest.java +++ b/container-search/src/test/java/com/yahoo/search/searchchain/test/VespaAsyncSearcherTest.java @@ -8,17 +8,18 @@ import com.yahoo.search.Searcher; import com.yahoo.search.searchchain.AsyncExecution; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.searchchain.FutureResult; +import org.junit.Test; + import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; - /** * Externally provided test for async execution of search chains. * - * @author <a href="mailto:pthomas@yahoo-inc.com">Peter Thomas</a> + * @author Peter Thomas */ -public class VespaAsyncSearcherTest extends TestCase { +public class VespaAsyncSearcherTest { + private static class FirstSearcher extends Searcher { @Override @@ -46,13 +47,13 @@ public class VespaAsyncSearcherTest extends TestCase { } + @Test public void testAsyncExecution() { - Chain<Searcher> chain = new Chain<>(new FirstSearcher(), - new SecondSearcher()); - Execution execution = new Execution(chain, - Execution.Context.createContextStub(null)); + Chain<Searcher> chain = new Chain<>(new FirstSearcher(), new SecondSearcher()); + Execution execution = new Execution(chain, Execution.Context.createContextStub(null)); Query query = new Query(); // fails with exception on old versions execution.search(query); } + } |