diff options
40 files changed, 660 insertions, 401 deletions
diff --git a/messagebus/src/test/java/com/yahoo/messagebus/SendProxyTestCase.java b/messagebus/src/test/java/com/yahoo/messagebus/SendProxyTestCase.java index fe9611b0a37..3e6d95c6c54 100644 --- a/messagebus/src/test/java/com/yahoo/messagebus/SendProxyTestCase.java +++ b/messagebus/src/test/java/com/yahoo/messagebus/SendProxyTestCase.java @@ -13,7 +13,6 @@ import com.yahoo.messagebus.test.Receptor; import com.yahoo.messagebus.test.SimpleMessage; import com.yahoo.messagebus.test.SimpleProtocol; import com.yahoo.messagebus.test.SimpleReply; -import junit.framework.TestCase; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/messagebus/src/test/java/com/yahoo/messagebus/routing/RetryPolicyTestCase.java b/messagebus/src/test/java/com/yahoo/messagebus/routing/RetryPolicyTestCase.java index a78b667a530..41cd0897f9e 100644 --- a/messagebus/src/test/java/com/yahoo/messagebus/routing/RetryPolicyTestCase.java +++ b/messagebus/src/test/java/com/yahoo/messagebus/routing/RetryPolicyTestCase.java @@ -2,13 +2,18 @@ package com.yahoo.messagebus.routing; import com.yahoo.messagebus.ErrorCode; -import junit.framework.TestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ -public class RetryPolicyTestCase extends TestCase { +public class RetryPolicyTestCase { + @Test public void testSimpleRetryPolicy() { RetryTransientErrorsPolicy policy = new RetryTransientErrorsPolicy(); for (int i = 0; i < 5; ++i) { @@ -29,4 +34,5 @@ public class RetryPolicyTestCase extends TestCase { } } } + } diff --git a/messagebus/src/test/java/com/yahoo/messagebus/routing/RouteParserTestCase.java b/messagebus/src/test/java/com/yahoo/messagebus/routing/RouteParserTestCase.java index fde72ded150..c2e4aee1bd8 100755 --- a/messagebus/src/test/java/com/yahoo/messagebus/routing/RouteParserTestCase.java +++ b/messagebus/src/test/java/com/yahoo/messagebus/routing/RouteParserTestCase.java @@ -1,11 +1,18 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.messagebus.routing; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + /** - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ -public class RouteParserTestCase extends junit.framework.TestCase { +public class RouteParserTestCase { + @Test public void testHopParser() { Hop hop = Hop.parse("foo"); assertNotNull(hop); @@ -64,6 +71,7 @@ public class RouteParserTestCase extends junit.framework.TestCase { "route[0].feed \"myfeed\""); } + @Test public void testHopParserErrors() { assertError(Hop.parse(""), "Failed to parse empty string."); assertError(Hop.parse("[foo"), "Unterminated '[' in '[foo'"); @@ -71,6 +79,7 @@ public class RouteParserTestCase extends junit.framework.TestCase { assertError(Hop.parse("foo bar"), "Failed to completely parse 'foo bar'."); } + @Test public void testShortRoute() { Route shortRoute = Route.parse("c"); assertNotNull(shortRoute); @@ -81,6 +90,7 @@ public class RouteParserTestCase extends junit.framework.TestCase { assertVerbatimDirective(hop.getDirective(0), "c"); } + @Test public void testShortHops() { Route shortRoute = Route.parse("a b c"); assertNotNull(shortRoute); @@ -91,6 +101,7 @@ public class RouteParserTestCase extends junit.framework.TestCase { assertVerbatimDirective(hop.getDirective(0), "a"); } + @Test public void testRouteParser() { Route route = Route.parse("foo bar/baz"); assertNotNull(route); @@ -114,6 +125,7 @@ public class RouteParserTestCase extends junit.framework.TestCase { assertVerbatimDirective(hop.getDirective(0), "default"); } + @Test public void testRouteParserErrors() { assertError(Route.parse(""), "Failed to parse empty string."); assertError(Route.parse("foo [bar"), "Unterminated '[' in '[bar'"); @@ -165,4 +177,5 @@ public class RouteParserTestCase extends junit.framework.TestCase { assertTrue(dir instanceof VerbatimDirective); assertEquals(image, ((VerbatimDirective)dir).getImage()); } + } diff --git a/messagebus/src/test/java/com/yahoo/messagebus/routing/RoutingContextTestCase.java b/messagebus/src/test/java/com/yahoo/messagebus/routing/RoutingContextTestCase.java index 0c738db4242..527896e2b44 100755 --- a/messagebus/src/test/java/com/yahoo/messagebus/routing/RoutingContextTestCase.java +++ b/messagebus/src/test/java/com/yahoo/messagebus/routing/RoutingContextTestCase.java @@ -11,30 +11,27 @@ import com.yahoo.messagebus.network.rpc.test.TestServer; import com.yahoo.messagebus.test.Receptor; import com.yahoo.messagebus.test.SimpleMessage; import com.yahoo.messagebus.test.SimpleProtocol; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; -import java.net.UnknownHostException; import java.util.Arrays; import java.util.List; /** - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ public class RoutingContextTestCase extends junit.framework.TestCase { - public static final int TIMEOUT_SECS = 120; - //////////////////////////////////////////////////////////////////////////////// - // - // Setup - // - //////////////////////////////////////////////////////////////////////////////// + public static final int TIMEOUT_SECS = 120; Slobrok slobrok; TestServer srcServer, dstServer; SourceSession srcSession; DestinationSession dstSession; - @Override - public void setUp() throws ListenFailedException, UnknownHostException { + @Before + public void setUp() throws ListenFailedException { slobrok = new Slobrok(); dstServer = new TestServer(new MessageBusParams().addProtocol(new SimpleProtocol()), new RPCNetworkParams().setIdentity(new Identity("dst")).setSlobrokConfigId(TestServer.getSlobrokConfig(slobrok))); @@ -46,7 +43,7 @@ public class RoutingContextTestCase extends junit.framework.TestCase { assertTrue(srcServer.waitSlobrok("dst/session", 1)); } - @Override + @After public void tearDown() { slobrok.stop(); dstSession.destroy(); @@ -55,12 +52,7 @@ public class RoutingContextTestCase extends junit.framework.TestCase { srcServer.destroy(); } - //////////////////////////////////////////////////////////////////////////////// - // - // Tests - // - //////////////////////////////////////////////////////////////////////////////// - + @Test public void testSingleDirective() { SimpleProtocol protocol = new SimpleProtocol(); protocol.addPolicyFactory("Custom", new CustomPolicyFactory( @@ -81,6 +73,7 @@ public class RoutingContextTestCase extends junit.framework.TestCase { } } + @Test public void testMoreDirectives() { SimpleProtocol protocol = new SimpleProtocol(); protocol.addPolicyFactory("Custom", new CustomPolicyFactory( @@ -103,6 +96,7 @@ public class RoutingContextTestCase extends junit.framework.TestCase { } } + @Test public void testRecipientsRemain() { SimpleProtocol protocol = new SimpleProtocol(); protocol.addPolicyFactory("First", new CustomPolicyFactory(true, Arrays.asList("foo/bar"), Arrays.asList("foo/[Second]"))); @@ -121,10 +115,12 @@ public class RoutingContextTestCase extends junit.framework.TestCase { } } + @Test public void testToString() { assertEquals("node : null, directive: 1, errors: [], selectOnRetry: true context: null", new RoutingContext(null, 1).toString()); } + @Test public void testConstRoute() { SimpleProtocol protocol = new SimpleProtocol(); protocol.addPolicyFactory("DocumentRouteSelector", @@ -146,12 +142,6 @@ public class RoutingContextTestCase extends junit.framework.TestCase { } } - //////////////////////////////////////////////////////////////////////////////// - // - // Utilities - // - //////////////////////////////////////////////////////////////////////////////// - private Message createMessage(String msg) { Message ret = new SimpleMessage(msg); ret.getTrace().setLevel(9); diff --git a/messagebus/src/test/java/com/yahoo/messagebus/routing/RoutingSpecTestCase.java b/messagebus/src/test/java/com/yahoo/messagebus/routing/RoutingSpecTestCase.java index 8ebbe664d8d..e7ea6346999 100755 --- a/messagebus/src/test/java/com/yahoo/messagebus/routing/RoutingSpecTestCase.java +++ b/messagebus/src/test/java/com/yahoo/messagebus/routing/RoutingSpecTestCase.java @@ -3,24 +3,23 @@ package com.yahoo.messagebus.routing; import com.yahoo.messagebus.ConfigAgent; import com.yahoo.messagebus.ConfigHandler; -import junit.framework.TestCase; +import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ -public class RoutingSpecTestCase extends TestCase { - - //////////////////////////////////////////////////////////////////////////////// - // - // Tests - // - //////////////////////////////////////////////////////////////////////////////// +public class RoutingSpecTestCase { + @Test public void testConfig() { assertConfig(new RoutingSpec()); assertConfig(new RoutingSpec().addTable(new RoutingTableSpec("mytable1"))); @@ -71,6 +70,7 @@ public class RoutingSpecTestCase extends TestCase { .addRoute(new RouteSpec("myroute1").addHop("myhop1"))).toString()); } + @Test public void testApplicationSpec() { assertApplicationSpec(Arrays.asList("foo"), Arrays.asList("foo", @@ -101,6 +101,7 @@ public class RoutingSpecTestCase extends TestCase { "*/*/*")); } + @Test public void testVeriyfOk() { assertVerifyOk(new RoutingSpec().addTable(new RoutingTableSpec("mytable") .addHop(new HopSpec("hop1", "myservice1"))), @@ -125,6 +126,7 @@ public class RoutingSpecTestCase extends TestCase { .addService("mytable", "foo/1/baz")); } + @Test public void testVerifyToggle() { assertVerifyOk(new RoutingSpec(false) .addTable(new RoutingTableSpec("mytable")) @@ -142,6 +144,7 @@ public class RoutingSpecTestCase extends TestCase { new ApplicationSpec()); } + @Test public void testVerifyFail() { // Duplicate table. assertVerifyFail(new RoutingSpec() @@ -274,12 +277,6 @@ public class RoutingSpecTestCase extends TestCase { "Selector 'bar/[baz]/cox' does not match recipient 'cox/0/bar' in hop 'hop5' in routing table 'mytable'.")); } - //////////////////////////////////////////////////////////////////////////////// - // - // Utilities - // - //////////////////////////////////////////////////////////////////////////////// - private static void assertVerifyOk(RoutingSpec routing, ApplicationSpec app) { assertVerifyFail(routing, app, new ArrayList<String>()); } @@ -333,4 +330,5 @@ public class RoutingSpecTestCase extends TestCase { this.routing = routing; } } + } diff --git a/metrics/src/test/java/com/yahoo/metrics/CountMetricTest.java b/metrics/src/test/java/com/yahoo/metrics/CountMetricTest.java index c066814b557..ef802a73c4c 100644 --- a/metrics/src/test/java/com/yahoo/metrics/CountMetricTest.java +++ b/metrics/src/test/java/com/yahoo/metrics/CountMetricTest.java @@ -1,13 +1,16 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.metrics; -import junit.framework.TestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * @author thomasg */ -public class CountMetricTest extends TestCase { +public class CountMetricTest { + @Test public void testCountMetric() { CountMetric m = new CountMetric("test", "tag", "description", null); assertEquals(false, m.used()); @@ -36,7 +39,7 @@ public class CountMetricTest extends TestCase { assertEquals("<test description=\"description\" count=\"96\"/>\n", m2.toXml(0, 2)); assertEquals("<test description=\"description\" count=\"96\" average_change_per_second=\"9.60\"/>\n", m2.toXml(10, 2)); - assertEquals(96.0, m2.getDoubleValue("value")); + assertEquals(96.0, m2.getDoubleValue("value"), 0.00000001); assertEquals(96, m2.getLongValue("value")); } diff --git a/metrics/src/test/java/com/yahoo/metrics/MetricSetTest.java b/metrics/src/test/java/com/yahoo/metrics/MetricSetTest.java index 177a2bbb993..bfe10825f4f 100644 --- a/metrics/src/test/java/com/yahoo/metrics/MetricSetTest.java +++ b/metrics/src/test/java/com/yahoo/metrics/MetricSetTest.java @@ -1,10 +1,15 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.metrics; -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; -public class MetricSetTest extends TestCase { +public class MetricSetTest { + + private final double delta = 0.000000001; class TestMetricVisitor extends MetricVisitor { String output = ""; @@ -28,8 +33,8 @@ public class MetricSetTest extends TestCase { } } - public void testNormalUsage() - { + @Test + public void testNormalUsage() { // Set up some metrics to test.. MetricSet set = new SimpleMetricSet("a", "foo", ""); SummedDoubleValueMetric v1 = new SummedDoubleValueMetric("c", "foo", "", set); @@ -111,6 +116,7 @@ public class MetricSetTest extends TestCase { } @SuppressWarnings("rawtypes") + @Test public void testSumInSet() { MetricSet ms_a = new SimpleMetricSet("a", "", "", null); MyTimer timer = new MyTimer(); @@ -151,11 +157,11 @@ public class MetricSetTest extends TestCase { ValueMetric av_2 = (ValueMetric)sms.getMetric("v2"); ValueMetric av_3 = (ValueMetric)sms.getMetric("v3"); - assertEquals(10.0, av_sum.getDoubleValue("total")); - assertEquals(4, av_sum.getLongValue("count")); - assertEquals(4.0, av_1.getDoubleValue("total")); - assertEquals(4.0, av_2.getDoubleValue("total")); - assertEquals(2.0, av_3.getDoubleValue("total")); + assertEquals(10.0, av_sum.getDoubleValue("total"), delta); + assertEquals(4, av_sum.getLongValue("count"), delta); + assertEquals(4.0, av_1.getDoubleValue("total"), delta); + assertEquals(4.0, av_2.getDoubleValue("total"), delta); + assertEquals(2.0, av_3.getDoubleValue("total"), delta); timer.timeNow = 301; manager.takeSnapshots(301); diff --git a/metrics/src/test/java/com/yahoo/metrics/SumMetricTest.java b/metrics/src/test/java/com/yahoo/metrics/SumMetricTest.java index eda3c532c19..008575af574 100644 --- a/metrics/src/test/java/com/yahoo/metrics/SumMetricTest.java +++ b/metrics/src/test/java/com/yahoo/metrics/SumMetricTest.java @@ -1,12 +1,18 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.metrics; -import junit.framework.TestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * @author thomasg */ -public class SumMetricTest extends TestCase { +public class SumMetricTest { + + private final double delta = 0.000000001; + + @Test public void testSummedCountMetric() { MetricSet parent = new SimpleMetricSet("parent", "", ""); SumMetric sum = new SumMetric("foo", "", "foodesc", parent); @@ -33,6 +39,7 @@ public class SumMetricTest extends TestCase { assertEquals(20, sum.getLongValue("value")); } + @Test public void testSummedValueMetric() { MetricSet parent = new SimpleMetricSet("parent", "", ""); SumMetric sum = new SumMetric("foo", "", "foodesc", parent); @@ -60,7 +67,7 @@ public class SumMetricTest extends TestCase { assertEquals(10, sum.getLongValue("max")); } - + @Test public void testAveragedValueMetric() { MetricSet parent = new SimpleMetricSet("parent", "", ""); SumMetric sum = new SumMetric("foo", "", "foodesc", parent); @@ -83,11 +90,12 @@ public class SumMetricTest extends TestCase { assertEquals("<foo description=\"foodesc\" average=\"5.40\" last=\"10.00\" min=\"2.00\" max=\"10.00\" count=\"5\" total=\"27.00\"/>\n", sum.toXml(0,2)); - assertEquals(5.40, sum.getDoubleValue("value")); - assertEquals(2.0, sum.getDoubleValue("min")); - assertEquals(10.0, sum.getDoubleValue("max")); + assertEquals(5.40, sum.getDoubleValue("value"), delta); + assertEquals(2.0, sum.getDoubleValue("min"), delta); + assertEquals(10.0, sum.getDoubleValue("max"), delta); } + @Test public void testMetricSet() { MetricSet parent = new SimpleMetricSet("parent", "", ""); SumMetric sum = new SumMetric("foo", "", "bar", parent); @@ -118,9 +126,8 @@ public class SumMetricTest extends TestCase { } - - public void testRemove() - { + @Test + public void testRemove() { MetricSet parent = new SimpleMetricSet("parent", "", ""); SumMetric sum = new SumMetric("foo", "", "foodesc", parent); @@ -145,6 +152,7 @@ public class SumMetricTest extends TestCase { assertEquals("<foo description=\"foodesc\" average=\"14.50\" last=\"17.00\" min=\"5.00\" max=\"10.00\" count=\"3\" total=\"43.50\"/>\n", sum.toXml(0,2)); } + @Test public void testEmpty() { SumMetric sum = new SumMetric("foo", "", "foodesc", null); assertEquals("<foo description=\"foodesc\"/>\n", sum.toXml(0,2)); diff --git a/metrics/src/test/java/com/yahoo/metrics/ValueMetricTest.java b/metrics/src/test/java/com/yahoo/metrics/ValueMetricTest.java index 1054dacdcbb..40ba70a9749 100644 --- a/metrics/src/test/java/com/yahoo/metrics/ValueMetricTest.java +++ b/metrics/src/test/java/com/yahoo/metrics/ValueMetricTest.java @@ -1,11 +1,16 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.metrics; -import junit.framework.TestCase; +import org.junit.Test; -public class ValueMetricTest extends TestCase { - public void testAveragedDoubleValueMetric() - { +import static org.junit.Assert.assertEquals; + +public class ValueMetricTest { + + private static final double delta = 0.000000001; + + @Test + public void testAveragedDoubleValueMetric() { AveragedDoubleValueMetric m = new AveragedDoubleValueMetric("test", "tag", "description", null); m.addValue(100.0); assertEquals("count=\"1\" min=\"100.00\" max=\"100.00\" last=\"100.00\" total=\"100.00\" average=\"100.00\"", m.toString()); @@ -43,13 +48,13 @@ public class ValueMetricTest extends TestCase { assertEquals("<test description=\"description\" average=\"343.33\" last=\"2000.00\" min=\"40.00\" max=\"2000.00\" count=\"9\" total=\"3090.00\"/>\n", sum.toXml(0, 2)); - assertEquals(80.0, m2.getDoubleValue("value")); - assertEquals(80.0, m2.getDoubleValue("average")); - assertEquals(40.0, m2.getDoubleValue("min")); - assertEquals(100.0, m2.getDoubleValue("max")); - assertEquals(40.0, m2.getDoubleValue("last")); - assertEquals(3.0, m2.getDoubleValue("count")); - assertEquals(240.0, m2.getDoubleValue("total")); + assertEquals(80.0, m2.getDoubleValue("value"), delta); + assertEquals(80.0, m2.getDoubleValue("average"), delta); + assertEquals(40.0, m2.getDoubleValue("min"), delta); + assertEquals(100.0, m2.getDoubleValue("max"), delta); + assertEquals(40.0, m2.getDoubleValue("last"), delta); + assertEquals(3.0, m2.getDoubleValue("count"), delta); + assertEquals(240.0, m2.getDoubleValue("total"), delta); assertEquals(80, m2.getLongValue("value")); assertEquals(80, m2.getLongValue("average")); @@ -60,20 +65,22 @@ public class ValueMetricTest extends TestCase { assertEquals(240, m2.getLongValue("total")); } + @Test public void testDoubleValueMetricNotUpdatedOnNaN() { AveragedDoubleValueMetric m = new AveragedDoubleValueMetric("test", "tag", "description", null); m.addValue(Double.NaN); assertEquals("count=\"0\" min=\"0\" max=\"0\" last=\"0\" total=\"0\" average=\"0.00\"", m.toString()); } + @Test public void testDoubleValueMetricNotUpdatedOnInfinity() { AveragedDoubleValueMetric m = new AveragedDoubleValueMetric("test", "tag", "description", null); m.addValue(Double.POSITIVE_INFINITY); assertEquals("count=\"0\" min=\"0\" max=\"0\" last=\"0\" total=\"0\" average=\"0.00\"", m.toString()); } - public void testSummedDoubleValueMetric() - { + @Test + public void testSummedDoubleValueMetric() { SummedDoubleValueMetric m = new SummedDoubleValueMetric("test", "tag", "description", null); m.addValue(100.0); assertEquals("count=\"1\" min=\"100.00\" max=\"100.00\" last=\"100.00\" total=\"100.00\" average=\"100.00\"", m.toString()); @@ -109,13 +116,13 @@ public class ValueMetricTest extends TestCase { assertEquals("<test description=\"description\" average=\"2313.33\" last=\"2440.00\" min=\"40.00\" max=\"2000.00\" count=\"7\" total=\"16193.33\"/>\n", sum.toXml(0, 2)); - assertEquals(40.0, m2.getDoubleValue("value")); - assertEquals(80.0, m2.getDoubleValue("average")); - assertEquals(40.0, m2.getDoubleValue("min")); - assertEquals(100.0, m2.getDoubleValue("max")); - assertEquals(40.0, m2.getDoubleValue("last")); - assertEquals(3.0, m2.getDoubleValue("count")); - assertEquals(240.0, m2.getDoubleValue("total")); + assertEquals(40.0, m2.getDoubleValue("value"), delta); + assertEquals(80.0, m2.getDoubleValue("average"), delta); + assertEquals(40.0, m2.getDoubleValue("min"), delta); + assertEquals(100.0, m2.getDoubleValue("max"), delta); + assertEquals(40.0, m2.getDoubleValue("last"), delta); + assertEquals(3.0, m2.getDoubleValue("count"), delta); + assertEquals(240.0, m2.getDoubleValue("total"), delta); assertEquals(40, m2.getLongValue("value")); assertEquals(80, m2.getLongValue("average")); @@ -126,12 +133,12 @@ public class ValueMetricTest extends TestCase { assertEquals(240, m2.getLongValue("total")); } - public void testAveragedLongValueMetric() - { + @Test + public void testAveragedLongValueMetric() { AveragedLongValueMetric m = new AveragedLongValueMetric("test", "tag", "description", null); - assertEquals(0l, m.getLongValue("max")); - assertEquals(0l, m.getLongValue("min")); + assertEquals(0L, m.getLongValue("max")); + assertEquals(0L, m.getLongValue("min")); m.addValue((long)100); assertEquals("count=\"1\" min=\"100\" max=\"100\" last=\"100\" total=\"100\" average=\"100.00\"", m.toString()); @@ -178,5 +185,4 @@ public class ValueMetricTest extends TestCase { assertEquals(240, m2.getLongValue("total")); } - } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/NodeRepositoryTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/NodeRepositoryTest.java index a936beac797..b33d776ac08 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/NodeRepositoryTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/NodeRepositoryTest.java @@ -18,9 +18,9 @@ import java.util.Set; import java.util.function.Predicate; import java.util.stream.Collectors; -import static junit.framework.TestCase.fail; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; /** * tests basic operation of the node repository @@ -178,4 +178,5 @@ public class NodeRepositoryTest { .map(Node::hostname) .collect(Collectors.toSet()); } + } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/DockerHostCapacityTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/DockerHostCapacityTest.java index dce9f694647..1e69b26d0e0 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/DockerHostCapacityTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/DockerHostCapacityTest.java @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.provision.provisioning; -import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.Flavor; import com.yahoo.config.provision.NodeFlavors; import com.yahoo.config.provision.NodeType; @@ -16,9 +15,9 @@ import java.util.List; import java.util.Optional; import java.util.Set; -import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author smorgrav @@ -28,8 +27,8 @@ public class DockerHostCapacityTest { private DockerHostCapacity capacity; private List<Node> nodes; private Node host1, host2, host3; - Node nodeA, nodeB, nodeC, nodeD, nodeE; - Flavor flavorDocker, flavorDocker2; + private Node nodeA, nodeB, nodeC, nodeD, nodeE; + private Flavor flavorDocker, flavorDocker2; @Before public void setup() { @@ -132,10 +131,4 @@ public class DockerHostCapacityTest { return additionalIps; } - private ApplicationId app(String tenant) { - return new ApplicationId.Builder() - .tenant(tenant) - .applicationName("test") - .instanceName("default").build(); - } } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/filter/NodeIdentifierTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/filter/NodeIdentifierTest.java index de2aaf68788..e885274c154 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/filter/NodeIdentifierTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/filter/NodeIdentifierTest.java @@ -34,14 +34,15 @@ import static com.yahoo.vespa.athenz.tls.SignatureAlgorithm.SHA256_WITH_RSA; import static java.util.Collections.emptySet; import static java.util.Collections.singleton; import static java.util.Collections.singletonList; -import static junit.framework.TestCase.assertFalse; -import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author bjorncs */ public class NodeIdentifierTest { + private static final String HOSTNAME = "myhostname"; private static final String OPENSTACK_ID = "OPENSTACK-ID"; private static final String AWS_INSTANCE_ID = "i-abcdef123456"; @@ -188,4 +189,5 @@ public class NodeIdentifierTest { b.addFlavor("docker", 1., 2., 50, Flavor.Type.DOCKER_CONTAINER).cost(1); return b.build(); } + }
\ No newline at end of file diff --git a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/model/VespaModelUtilTest.java b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/model/VespaModelUtilTest.java index 33efc2a8486..537101e6c51 100644 --- a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/model/VespaModelUtilTest.java +++ b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/model/VespaModelUtilTest.java @@ -21,15 +21,16 @@ import java.util.Optional; import static com.yahoo.vespa.orchestrator.TestUtil.makeServiceClusterSet; import static com.yahoo.vespa.orchestrator.TestUtil.makeServiceInstanceSet; -import static junit.framework.TestCase.assertFalse; -import static junit.framework.TestCase.assertTrue; -import static org.fest.assertions.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** * @author hakonhall */ public class VespaModelUtilTest { + // Cluster Controller Service Cluster private static final ClusterId CONTENT_CLUSTER_ID = new ClusterId("content-cluster-0"); @@ -174,25 +175,25 @@ public class VespaModelUtilTest { List<HostName> controllers = VespaModelUtil.getClusterControllerInstancesInOrder(application, CONTENT_CLUSTER_ID); List<HostName> expectedControllers = Arrays.asList(controller0.hostName(), controller1.hostName()); - assertThat(controllers).isEqualTo(expectedControllers); + assertEquals(expectedControllers, controllers); } @Test public void testGetControllerHostName() { HostName host = VespaModelUtil.getControllerHostName(application, CONTENT_CLUSTER_ID); - assertThat(host).isEqualTo(controller0Host); + assertEquals(controller0Host, host); } @Test public void testGetContentClusterName() { ClusterId contentClusterName = VespaModelUtil.getContentClusterName(application, distributor0.hostName()); - assertThat(CONTENT_CLUSTER_ID).isEqualTo(contentClusterName); + assertEquals(CONTENT_CLUSTER_ID, contentClusterName); } @Test public void testGetContentClusterNameForSecondaryContentCluster() { ClusterId contentClusterName = VespaModelUtil.getContentClusterName(application, secondaryDistributor0.hostName()); - assertThat(SECONDARY_CONTENT_CLUSTER_ID).isEqualTo(contentClusterName); + assertEquals(contentClusterName, SECONDARY_CONTENT_CLUSTER_ID); } @Test @@ -200,7 +201,7 @@ public class VespaModelUtilTest { Optional<ServiceInstance> service = VespaModelUtil.getStorageNodeAtHost(application, storage0Host); assertTrue(service.isPresent()); - assertThat(service.get()).isEqualTo(storage0); + assertEquals(storage0, service.get()); } @Test @@ -213,13 +214,13 @@ public class VespaModelUtilTest { @Test public void testGetClusterControllerIndex() { ConfigId configId = new ConfigId("admin/cluster-controllers/2"); - assertThat(VespaModelUtil.getClusterControllerIndex(configId)).isEqualTo(2); + assertEquals(2, VespaModelUtil.getClusterControllerIndex(configId)); } @Test public void testGetClusterControllerIndexWithStandaloneClusterController() { ConfigId configId = new ConfigId("fantasy_sports/standalone/fantasy_sports-controllers/1"); - assertThat(VespaModelUtil.getClusterControllerIndex(configId)).isEqualTo(1); + assertEquals(1, VespaModelUtil.getClusterControllerIndex(configId)); } @Test(expected = IllegalArgumentException.class) @@ -232,6 +233,7 @@ public class VespaModelUtilTest { @Test public void testGetStorageNodeIndex() { ConfigId configId = TestUtil.storageNodeConfigId(CONTENT_CLUSTER_ID.toString(), 3); - assertThat(VespaModelUtil.getStorageNodeIndex(configId)).isEqualTo(3); + assertEquals(3, VespaModelUtil.getStorageNodeIndex(configId)); } + } diff --git a/predicate-search/src/test/java/com/yahoo/search/predicate/index/IntervalPostingListTest.java b/predicate-search/src/test/java/com/yahoo/search/predicate/index/IntervalPostingListTest.java index f9f65034cc6..db1ae5b1fa2 100644 --- a/predicate-search/src/test/java/com/yahoo/search/predicate/index/IntervalPostingListTest.java +++ b/predicate-search/src/test/java/com/yahoo/search/predicate/index/IntervalPostingListTest.java @@ -6,11 +6,12 @@ import org.junit.Test; import java.util.Arrays; -import static junit.framework.TestCase.assertFalse; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; public class IntervalPostingListTest { + @Test public void requireThatPostingListCanIterate() { PredicateIntervalStore.Builder builder = new PredicateIntervalStore.Builder(); diff --git a/processing/src/test/java/com/yahoo/processing/execution/test/ExecutionContextTestCase.java b/processing/src/test/java/com/yahoo/processing/execution/test/ExecutionContextTestCase.java index 5ee1955a066..9c4d4de47dc 100644 --- a/processing/src/test/java/com/yahoo/processing/execution/test/ExecutionContextTestCase.java +++ b/processing/src/test/java/com/yahoo/processing/execution/test/ExecutionContextTestCase.java @@ -5,19 +5,26 @@ import com.yahoo.component.chain.Chain; import com.yahoo.processing.Processor; import com.yahoo.processing.execution.Execution; import com.yahoo.processing.test.ProcessorLibrary; +import org.junit.Test; import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + /** - * @author bratseth + * @author bratseth */ -public class ExecutionContextTestCase extends junit.framework.TestCase { +public class ExecutionContextTestCase { - private Chain<Processor> chain=new Chain<Processor>(new ProcessorLibrary.DataSource()); + private final Chain<Processor> chain = new Chain<Processor>(new ProcessorLibrary.DataSource()); /** Tests combined use of trace messages, context values and access log entries */ + @Test public void testtrace() { Execution execution1=Execution.createRoot(chain,2,Execution.Environment.createEmpty()); execution1.trace().setProperty("a","a1"); diff --git a/processing/src/test/java/com/yahoo/processing/request/test/ErrorMessageTestCase.java b/processing/src/test/java/com/yahoo/processing/request/test/ErrorMessageTestCase.java index 334c7afb076..70f4a7720ee 100644 --- a/processing/src/test/java/com/yahoo/processing/request/test/ErrorMessageTestCase.java +++ b/processing/src/test/java/com/yahoo/processing/request/test/ErrorMessageTestCase.java @@ -1,14 +1,16 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.processing.request.test; -import com.yahoo.processing.Request; import com.yahoo.processing.request.ErrorMessage; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + /** * @author bratseth */ -public class ErrorMessageTestCase extends junit.framework.TestCase { +public class ErrorMessageTestCase { @Test public void testToString() { @@ -44,11 +46,16 @@ public class ErrorMessageTestCase extends junit.framework.TestCase { new ErrorMessage("message")); assertEquals(new ErrorMessage("message",new Exception()), new ErrorMessage("message")); - assertFalse(new ErrorMessage("message").equals(new ErrorMessage("message","detail"))); - assertFalse(new ErrorMessage(37,"message").equals(new ErrorMessage("message"))); - assertFalse(new ErrorMessage(37,"message").equals(new ErrorMessage(38,"message"))); - assertFalse(new ErrorMessage("message","detail1").equals(new ErrorMessage("message","detail2"))); - assertFalse(new ErrorMessage("message1").equals(new ErrorMessage("message2"))); + assertNotEquals(new ErrorMessage("message"), + new ErrorMessage("message","detail")); + assertNotEquals(new ErrorMessage(37,"message"), + new ErrorMessage("message")); + assertNotEquals(new ErrorMessage(37,"message"), + new ErrorMessage(38,"message")); + assertNotEquals(new ErrorMessage("message","detail1"), + new ErrorMessage("message","detail2")); + assertNotEquals(new ErrorMessage("message1"), + new ErrorMessage("message2")); } } diff --git a/processing/src/test/java/com/yahoo/processing/request/test/RequestTestCase.java b/processing/src/test/java/com/yahoo/processing/request/test/RequestTestCase.java index 100e4f3781f..032fdd71f88 100644 --- a/processing/src/test/java/com/yahoo/processing/request/test/RequestTestCase.java +++ b/processing/src/test/java/com/yahoo/processing/request/test/RequestTestCase.java @@ -8,12 +8,17 @@ import com.yahoo.processing.request.Properties; import com.yahoo.processing.request.properties.PropertyMap; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + /** * Tests using requests * * @author bratseth */ -public class RequestTestCase extends junit.framework.TestCase { +public class RequestTestCase { + + private static final double delta = 0.0000000001; @Test public void testProperties() { @@ -33,53 +38,53 @@ public class RequestTestCase extends junit.framework.TestCase { assertEquals("default", r.properties().get(new CompoundName("c"), "default")); assertNull(r.properties().get(new CompoundName("c"))); - assertEquals("b1",r.properties().getString("b")); - assertEquals("b1",r.properties().getString("b","default")); - assertEquals("default",r.properties().getString("c","default")); - assertEquals(null,r.properties().getString("c")); - assertEquals("b1",r.properties().getString(new CompoundName("b"))); - assertEquals("b1",r.properties().getString(new CompoundName("b"),"default")); - assertEquals("default",r.properties().getString(new CompoundName("c"),"default")); - assertEquals(null,r.properties().getString(new CompoundName("c"))); + assertEquals("b1", r.properties().getString("b")); + assertEquals("b1", r.properties().getString("b","default")); + assertEquals("default", r.properties().getString("c","default")); + assertEquals(null, r.properties().getString("c")); + assertEquals("b1", r.properties().getString(new CompoundName("b"))); + assertEquals("b1", r.properties().getString(new CompoundName("b"),"default")); + assertEquals("default", r.properties().getString(new CompoundName("c"),"default")); + assertEquals(null, r.properties().getString(new CompoundName("c"))); r.properties().set("i",7); - assertEquals(7,(int)r.properties().getInteger("i")); - assertEquals(7,(int)r.properties().getInteger("i",3)); - assertEquals(3,(int)r.properties().getInteger("n",3)); + assertEquals(7, (int)r.properties().getInteger("i")); + assertEquals(7, (int)r.properties().getInteger("i",3)); + assertEquals(3, (int)r.properties().getInteger("n",3)); assertNull(r.properties().getInteger("n")); - assertEquals(7,(int)r.properties().getInteger(new CompoundName("i"))); - assertEquals(7,(int)r.properties().getInteger(new CompoundName("i"),3)); - assertEquals(3,(int)r.properties().getInteger(new CompoundName("n"),3)); + assertEquals(7, (int)r.properties().getInteger(new CompoundName("i"))); + assertEquals(7, (int)r.properties().getInteger(new CompoundName("i"),3)); + assertEquals(3, (int)r.properties().getInteger(new CompoundName("n"),3)); assertNull(r.properties().getInteger("n")); - r.properties().set(new CompoundName("l"),7); + r.properties().set(new CompoundName("l"), 7); assertEquals(7, (long) r.properties().getLong("l")); - assertEquals(7,(long)r.properties().getLong("l",3l)); - assertEquals(3,(long)r.properties().getLong("m",3l)); + assertEquals(7, (long)r.properties().getLong("l",3l)); + assertEquals(3, (long)r.properties().getLong("m",3l)); assertNull(r.properties().getInteger("m")); - assertEquals(7,(long)r.properties().getLong(new CompoundName("l"))); - assertEquals(7,(long)r.properties().getLong(new CompoundName("l"),3l)); - assertEquals(3,(long)r.properties().getLong(new CompoundName("m"),3l)); + assertEquals(7, (long)r.properties().getLong(new CompoundName("l"))); + assertEquals(7, (long)r.properties().getLong(new CompoundName("l"),3l)); + assertEquals(3, (long)r.properties().getLong(new CompoundName("m"),3l)); assertNull(r.properties().getInteger("m")); - r.properties().set("d",7.3); - assertEquals(7.3,r.properties().getDouble("d")); - assertEquals(7.3,r.properties().getDouble("d",3.4d)); - assertEquals(3.4,r.properties().getDouble("f",3.4d)); + r.properties().set("d", 7.3); + assertEquals(7.3, r.properties().getDouble("d"), delta); + assertEquals(7.3, r.properties().getDouble("d",3.4d), delta); + assertEquals(3.4, r.properties().getDouble("f",3.4d), delta); assertNull(r.properties().getDouble("f")); - assertEquals(7.3,r.properties().getDouble(new CompoundName("d"))); - assertEquals(7.3,r.properties().getDouble(new CompoundName("d"),3.4d)); - assertEquals(3.4,r.properties().getDouble(new CompoundName("f"),3.4d)); + assertEquals(7.3, r.properties().getDouble(new CompoundName("d")), delta); + assertEquals(7.3, r.properties().getDouble(new CompoundName("d"),3.4d), delta); + assertEquals(3.4, r.properties().getDouble(new CompoundName("f"),3.4d), delta); assertNull(r.properties().getDouble("f")); r.properties().set("o",true); - assertEquals(true,r.properties().getBoolean("o")); - assertEquals(true,r.properties().getBoolean("o",true)); - assertEquals(true,r.properties().getBoolean("g",true)); + assertEquals(true, r.properties().getBoolean("o")); + assertEquals(true, r.properties().getBoolean("o",true)); + assertEquals(true, r.properties().getBoolean("g",true)); assertEquals(false, r.properties().getBoolean("g")); - assertEquals(true,r.properties().getBoolean(new CompoundName("o"))); - assertEquals(true,r.properties().getBoolean(new CompoundName("o"),true)); - assertEquals(true,r.properties().getBoolean(new CompoundName("g"),true)); + assertEquals(true, r.properties().getBoolean(new CompoundName("o"))); + assertEquals(true, r.properties().getBoolean(new CompoundName("o"),true)); + assertEquals(true, r.properties().getBoolean(new CompoundName("g"),true)); assertEquals(false, r.properties().getBoolean("g")); r.properties().set(new CompoundName("x.y"), "x1.y1"); @@ -99,9 +104,8 @@ public class RequestTestCase extends junit.framework.TestCase { r.errors().add(new ErrorMessage("foo")); r.errors().add(new ErrorMessage("bar")); assertEquals(2,r.errors().size()); - assertEquals("foo",r.errors().get(0).getMessage()); - assertEquals("bar",r.errors().get(1).getMessage()); - + assertEquals("foo", r.errors().get(0).getMessage()); + assertEquals("bar", r.errors().get(1).getMessage()); } @Test diff --git a/searchlib/src/test/java/com/yahoo/searchlib/aggregation/AggregationTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/aggregation/AggregationTestCase.java index 1c0212babf8..cbd6c02cd26 100644 --- a/searchlib/src/test/java/com/yahoo/searchlib/aggregation/AggregationTestCase.java +++ b/searchlib/src/test/java/com/yahoo/searchlib/aggregation/AggregationTestCase.java @@ -9,13 +9,19 @@ import com.yahoo.vespa.objects.BufferSerializer; import com.yahoo.vespa.objects.Identifiable; import com.yahoo.vespa.objects.ObjectOperation; import com.yahoo.vespa.objects.ObjectPredicate; -import junit.framework.TestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; /** * @author baldersheim */ -public class AggregationTestCase extends TestCase { +public class AggregationTestCase { + + private static final double delta = 0.0000000001; + @Test public void testSumAggregationResult() { SumAggregationResult a = new SumAggregationResult(); a.setExpression(new AttributeNode("attributeA")); @@ -27,6 +33,7 @@ public class AggregationTestCase extends TestCase { assertEquals(b.getSum().getInteger(), 14); } + @Test public void testXorAggregationResult() { XorAggregationResult a = new XorAggregationResult(6); a.setExpression(new AttributeNode("attributeA")); @@ -39,6 +46,7 @@ public class AggregationTestCase extends TestCase { assertEquals(b.getXor(), 0); } + @Test public void testCountAggregationResult() { CountAggregationResult a = new CountAggregationResult(6); a.setExpression(new AttributeNode("attributeA")); @@ -51,6 +59,7 @@ public class AggregationTestCase extends TestCase { assertEquals(b.getCount(), 14); } + @Test public void testMinAggregationResult() { MinAggregationResult a = new MinAggregationResult(new IntegerResultNode(6)); a.setExpression(new AttributeNode("attributeA")); @@ -64,6 +73,7 @@ public class AggregationTestCase extends TestCase { assertEquals(b.getMin().getInteger(), 6); } + @Test public void testMaxAggregationResult() { MaxAggregationResult a = new MaxAggregationResult(new IntegerResultNode(6)); a.setExpression(new AttributeNode("attributeA")); @@ -77,6 +87,7 @@ public class AggregationTestCase extends TestCase { assertEquals(b.getMax().getInteger(), 7); } + @Test public void testAverageAggregationResult() { AverageAggregationResult a = new AverageAggregationResult(new FloatResultNode(72), 6); a.setExpression(new AttributeNode("attributeA")); @@ -99,6 +110,7 @@ public class AggregationTestCase extends TestCase { return new GlobalId((new DocumentId("doc:test:" + docId)).getGlobalId()); } + @Test public void testFs4HitsAggregationResult() { double rank1 = 1; double rank2 = 2; @@ -118,10 +130,10 @@ public class AggregationTestCase extends TestCase { assertEquals(a, b); a.postMerge(); assertEquals(2, a.getHits().size()); - assertEquals(2.0, a.getHits().get(0).getRank()); + assertEquals(2.0, a.getHits().get(0).getRank(), delta); a.setMaxHits(1).postMerge(); assertEquals(1, a.getHits().size()); - assertEquals(2.0, a.getHits().get(0).getRank()); + assertEquals(2.0, a.getHits().get(0).getRank(), delta); HitsAggregationResult hits = new HitsAggregationResult(3) .addHit(new FS4Hit(1, createGlobalId(3), 1)) @@ -160,6 +172,7 @@ public class AggregationTestCase extends TestCase { assertFS4Hits(request, 4, 5, 0); } + @Test public void testVdsHitsAggregationResult() { double rank1 = 1; double rank2 = 2; @@ -176,8 +189,6 @@ public class AggregationTestCase extends TestCase { assertEquals(0, a.getHits().size()); a.setExpression(new AttributeNode("attributeA")); a.addHit(new VdsHit("1", s2, rank1)); -// a.addHit(new VdsHit("5", s7, rank2)); -// assertEquals(2, a.getHits().size()); HitsAggregationResult b = (HitsAggregationResult)serializeDeserialize(a); assertEquals(a, b); @@ -218,7 +229,6 @@ public class AggregationTestCase extends TestCase { assertVdsHits(request, 4, 5, 0); } - private void assertFS4Hits(Grouping request, int firstLevel, int lastLevel, int expected) { CountFS4Hits obj = new CountFS4Hits(); request.setFirstLevel(firstLevel); @@ -255,6 +265,7 @@ public class AggregationTestCase extends TestCase { } } + @Test public void testGroup() { Group a = new Group(); a.setId(new IntegerResultNode(17)); @@ -262,6 +273,7 @@ public class AggregationTestCase extends TestCase { serializeDeserialize1(a); } + @Test public void testGrouping() { Grouping a = new Grouping(); GroupingLevel level = new GroupingLevel(); @@ -293,7 +305,6 @@ public class AggregationTestCase extends TestCase { a.getRoot().addChild(g); serializeDeserialize1(a); - Grouping foo = new Grouping(); foo.addLevel(level); int hashBefore = foo.hashCode(); @@ -320,7 +331,7 @@ public class AggregationTestCase extends TestCase { buf.flip(); Identifiable b = Identifiable.create(buf); assertEquals(a.getClass(), b.getClass()); - assertEquals(buf.getBuf().hasRemaining(), false); + assertFalse(buf.getBuf().hasRemaining()); Identifiable c = b.clone(); assertEquals(b.getClass(), c.getClass()); BufferSerializer bb = new BufferSerializer(new GrowableByteBuffer()); @@ -343,4 +354,5 @@ public class AggregationTestCase extends TestCase { assertEquals(a.getExpression().getClass(), b.getExpression().getClass()); return b; } + } diff --git a/searchlib/src/test/java/com/yahoo/searchlib/aggregation/ForceLoadTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/aggregation/ForceLoadTestCase.java index f2abc2069d7..347c38898ee 100755 --- a/searchlib/src/test/java/com/yahoo/searchlib/aggregation/ForceLoadTestCase.java +++ b/searchlib/src/test/java/com/yahoo/searchlib/aggregation/ForceLoadTestCase.java @@ -1,19 +1,22 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.searchlib.aggregation; -public class ForceLoadTestCase extends junit.framework.TestCase { +import org.junit.Test; - public ForceLoadTestCase(String name) { - super(name); - } +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class ForceLoadTestCase { + @Test public void testLoadClasses() { try { new com.yahoo.searchlib.aggregation.ForceLoad(); assertTrue(com.yahoo.searchlib.aggregation.ForceLoad.forceLoad()); } catch (com.yahoo.system.ForceLoadError e) { e.printStackTrace(); - assertTrue(false); + fail("Load failed"); } } + } diff --git a/searchlib/src/test/java/com/yahoo/searchlib/aggregation/MergeTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/aggregation/MergeTestCase.java index f94806fb00a..83b7e81a539 100755 --- a/searchlib/src/test/java/com/yahoo/searchlib/aggregation/MergeTestCase.java +++ b/searchlib/src/test/java/com/yahoo/searchlib/aggregation/MergeTestCase.java @@ -3,22 +3,32 @@ package com.yahoo.searchlib.aggregation; import com.yahoo.document.DocumentId; import com.yahoo.document.GlobalId; -import com.yahoo.searchlib.expression.*; -import junit.framework.TestCase; +import com.yahoo.searchlib.expression.AggregationRefNode; +import com.yahoo.searchlib.expression.AttributeNode; +import com.yahoo.searchlib.expression.ConstantNode; +import com.yahoo.searchlib.expression.FloatBucketResultNode; +import com.yahoo.searchlib.expression.FloatResultNode; +import com.yahoo.searchlib.expression.IntegerResultNode; +import com.yahoo.searchlib.expression.MultiplyFunctionNode; +import com.yahoo.searchlib.expression.StringResultNode; +import org.junit.Test; import java.util.Arrays; import java.util.List; +import static org.junit.Assert.assertEquals; + /** - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ -public class MergeTestCase extends TestCase { +public class MergeTestCase { private GlobalId createGlobalId(int docId) { return new GlobalId((new DocumentId("doc:test:" + docId)).getGlobalId()); } // Test merging of hits. + @Test public void testMergeHits() { Grouping request = new Grouping() .setFirstLevel(0) @@ -33,7 +43,7 @@ public class MergeTestCase extends TestCase { .addHit(new FS4Hit(10, createGlobalId(10), 10)) .addHit(new FS4Hit(5, createGlobalId(9), 9)) .addHit(new FS4Hit(6, createGlobalId(8), 8)) - .setExpression(new ConstantNode( new IntegerResultNode(0)))); + .setExpression(new ConstantNode(new IntegerResultNode(0)))); Group a = new Group() .addAggregationResult(new HitsAggregationResult() @@ -68,6 +78,7 @@ public class MergeTestCase extends TestCase { } // Test merging the sum of the values from a single attribute vector that was collected directly into the root node. + @Test public void testMergeSimpleSum() { Grouping lhs = new Grouping() .setRoot(new Group() @@ -90,6 +101,7 @@ public class MergeTestCase extends TestCase { } // Test merging of the value from a single attribute vector in level 1. + @Test public void testMergeSingleChild() { Grouping lhs = new Grouping() .setFirstLevel(0) @@ -119,6 +131,7 @@ public class MergeTestCase extends TestCase { } // Test merging of the value from a multiple attribute vectors in level 1. + @Test public void testMergeMultiChild() { Grouping lhs = new Grouping() .setFirstLevel(0) @@ -171,6 +184,7 @@ public class MergeTestCase extends TestCase { } // Verify that frozen levels are not touched during merge. + @Test public void testMergeLevels() { Grouping request = new Grouping() .addLevel(new GroupingLevel() @@ -340,6 +354,7 @@ public class MergeTestCase extends TestCase { // Verify that the number of groups for a level is pruned down to maxGroups, that the remaining groups are the // highest ranked ones, and that they are sorted by group id. + @Test public void testMergeGroups() { Grouping request = new Grouping() .addLevel(new GroupingLevel() @@ -393,6 +408,7 @@ public class MergeTestCase extends TestCase { assertMerge(request, rhs, lhs, expectAll); } + @Test public void testMergeBuckets() { Grouping lhs = new Grouping() .setRoot(new Group().setTag(0) @@ -423,6 +439,7 @@ public class MergeTestCase extends TestCase { } // Merge two trees that are ordered by an expression, and verify that the resulting order after merge is correct. + @Test public void testMergeExpressions() { Grouping a = new Grouping() .setFirstLevel(0) @@ -465,6 +482,7 @@ public class MergeTestCase extends TestCase { } // Merge two relatively complex tree structures and verify that the end result is as expected. + @Test public void testMergeTrees() { Grouping request = new Grouping() .addLevel(new GroupingLevel() @@ -732,4 +750,5 @@ public class MergeTestCase extends TestCase { assertEquals(expect.toString(), tmp.getRoot().toString()); assertEquals(expect, tmp.getRoot()); } + } diff --git a/searchlib/src/test/java/com/yahoo/searchlib/expression/ExpressionTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/expression/ExpressionTestCase.java index d76db4e8147..12a4cacaa97 100644 --- a/searchlib/src/test/java/com/yahoo/searchlib/expression/ExpressionTestCase.java +++ b/searchlib/src/test/java/com/yahoo/searchlib/expression/ExpressionTestCase.java @@ -5,16 +5,24 @@ import com.yahoo.io.GrowableByteBuffer; import com.yahoo.text.Utf8; import com.yahoo.vespa.objects.BufferSerializer; import com.yahoo.vespa.objects.Identifiable; -import junit.framework.TestCase; +import org.junit.Test; import java.nio.ByteBuffer; import java.util.Arrays; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * @author baldersheim */ -public class ExpressionTestCase extends TestCase { +public class ExpressionTestCase { + + private static final double delta = 0.00000001; + @Test public void testRangeBucketPreDefFunctionNode() { assertMultiArgFunctionNode(new RangeBucketPreDefFunctionNode(new StringBucketResultNodeVector().add(new StringBucketResultNode("10", "20")), new AttributeNode("foo"))); assertEquals(new RangeBucketPreDefFunctionNode(), new RangeBucketPreDefFunctionNode()); @@ -26,6 +34,7 @@ public class ExpressionTestCase extends TestCase { new RangeBucketPreDefFunctionNode(new StringBucketResultNodeVector().add(new StringBucketResultNode("10", "20")), new AttributeNode("bar"))); } + @Test public void testFixedWidthBucketFunctionNode() { assertMultiArgFunctionNode(new FixedWidthBucketFunctionNode()); assertEquals(new FixedWidthBucketFunctionNode(), new FixedWidthBucketFunctionNode()); @@ -37,6 +46,7 @@ public class ExpressionTestCase extends TestCase { new FixedWidthBucketFunctionNode(new IntegerResultNode(5), new AttributeNode("bar"))); } + @Test public void testIntegerBucketResultNodeVector() { assertResultNode(new IntegerBucketResultNodeVector().add(new IntegerBucketResultNode(10, 20))); assertEquals(new IntegerBucketResultNodeVector().add(new IntegerBucketResultNode(10, 20)), @@ -47,6 +57,7 @@ public class ExpressionTestCase extends TestCase { new IntegerBucketResultNodeVector().add(new IntegerBucketResultNode(11, 20))); } + @Test public void testFloatBucketResultNodeVector() { assertResultNode(new FloatBucketResultNodeVector().add(new FloatBucketResultNode(10, 20))); assertEquals(new FloatBucketResultNodeVector().add(new FloatBucketResultNode(10, 20)), @@ -57,6 +68,7 @@ public class ExpressionTestCase extends TestCase { new FloatBucketResultNodeVector().add(new FloatBucketResultNode(11, 20))); } + @Test public void testStringBucketResultNodeVector() { assertResultNode(new StringBucketResultNodeVector().add(new StringBucketResultNode("10", "20"))); assertEquals(new StringBucketResultNodeVector().add(new StringBucketResultNode("10", "20")), @@ -67,6 +79,7 @@ public class ExpressionTestCase extends TestCase { new StringBucketResultNodeVector().add(new StringBucketResultNode("11", "20"))); } + @Test public void testIntegerBucketResultNode() { assertResultNode(new IntegerBucketResultNode(10, 20)); assertEquals(new IntegerBucketResultNode(10, 20), new IntegerBucketResultNode(10, 20)); @@ -74,6 +87,7 @@ public class ExpressionTestCase extends TestCase { assertNotEquals(new IntegerBucketResultNode(10, 20), new IntegerBucketResultNode(10, 21)); } + @Test public void testFloatBucketResultNode() { assertResultNode(new FloatBucketResultNode(10.0, 20.0)); assertEquals(new FloatBucketResultNode(10.0, 20.0), new FloatBucketResultNode(10.0, 20.0)); @@ -81,6 +95,7 @@ public class ExpressionTestCase extends TestCase { assertNotEquals(new FloatBucketResultNode(10.0, 20.0), new FloatBucketResultNode(10.0, 21.0)); } + @Test public void testStringBucketResultNode() { assertResultNode(new StringBucketResultNode("10.0", "20.0")); assertEquals(new StringBucketResultNode("10.0", "20.0"), new StringBucketResultNode("10.0", "20.0")); @@ -99,6 +114,7 @@ public class ExpressionTestCase extends TestCase { new StringBucketResultNode("11.0", "19.0"), new StringBucketResultNode("11.0", "20.0")); } + @Test public void testPositiveInfinity() { PositiveInfinityResultNode inf = new PositiveInfinityResultNode(); PositiveInfinityResultNode inf2 = new PositiveInfinityResultNode(); @@ -106,6 +122,7 @@ public class ExpressionTestCase extends TestCase { assertEquals(inf, inf2); } + @Test public void testAddFunctionNode() { assertMultiArgFunctionNode(new AddFunctionNode()); assertFunctionNode(new AddFunctionNode().addArg(new ConstantNode(new IntegerResultNode(2))) @@ -119,6 +136,7 @@ public class ExpressionTestCase extends TestCase { 5, 5.0, "5.0", doubleAsRaw(5.0)); } + @Test public void testAndFunctionNode() { assertMultiArgFunctionNode(new AndFunctionNode()); assertFunctionNode(new AndFunctionNode().addArg(new ConstantNode(new IntegerResultNode(3))) @@ -126,11 +144,13 @@ public class ExpressionTestCase extends TestCase { 3, 3.0, "3", longAsRaw(3)); } + @Test public void testZCurveFunctionNode() { assertMultiArgFunctionNode( new ZCurveFunctionNode(new ConstantNode(new IntegerResultNode(7)), ZCurveFunctionNode.Dimension.Y)); } + @Test public void testTimeStampFunctionNode() { assertMultiArgFunctionNode(new TimeStampFunctionNode(new AttributeNode("testattribute"), TimeStampFunctionNode.TimePart.Hour, true)); assertEquals(new TimeStampFunctionNode(new AttributeNode("testattribute"), TimeStampFunctionNode.TimePart.Hour, true), @@ -152,11 +172,13 @@ public class ExpressionTestCase extends TestCase { false)); } + @Test public void testExpressionRefNode() { AggregationRefNode ref = new AggregationRefNode(3); assertEquals(3, ref.getIndex()); } + @Test public void testAttributeNode() { try { new AttributeNode(null); @@ -192,6 +214,7 @@ public class ExpressionTestCase extends TestCase { assertFalse(b.equals(c)); } + @Test public void testInterpolatedLookupNode() { ExpressionNode argA = new ConstantNode(new FloatResultNode(2.71828182846)); ExpressionNode argB = new ConstantNode(new FloatResultNode(3.14159265359)); @@ -236,6 +259,7 @@ public class ExpressionTestCase extends TestCase { assertFalse(a1.equals(a2)); } + @Test public void testCatFunctionNode() { assertMultiArgFunctionNode(new CatFunctionNode()); assertFunctionNode(new CatFunctionNode().addArg(new ConstantNode(new RawResultNode(asRaw('1', '2')))) @@ -243,6 +267,7 @@ public class ExpressionTestCase extends TestCase { 0, 0.0, "1234", asRaw('1', '2', '3', '4')); } + @Test public void testStrCatFunctionNode() { assertMultiArgFunctionNode(new StrCatFunctionNode()); assertFunctionNode(new StrCatFunctionNode().addArg(new ConstantNode(new StringResultNode("foo"))) @@ -250,6 +275,7 @@ public class ExpressionTestCase extends TestCase { 0, 0.0, "foobar", stringAsRaw("foobar")); } + @Test public void testDivideFunctionNode() { assertMultiArgFunctionNode(new DivideFunctionNode()); assertFunctionNode(new DivideFunctionNode().addArg(new ConstantNode(new IntegerResultNode(10))) @@ -263,6 +289,7 @@ public class ExpressionTestCase extends TestCase { 1, 0.5, "0.5", doubleAsRaw(0.5)); } + @Test public void testDocumentFieldNode() { try { new DocumentFieldNode(null); @@ -298,10 +325,11 @@ public class ExpressionTestCase extends TestCase { assertFalse(b.equals(c)); } + @Test public void testFloatResultNode() { FloatResultNode a = new FloatResultNode(7.3); assertEquals(a.getInteger(), 7); - assertEquals(a.getFloat(), 7.3); + assertEquals(a.getFloat(), 7.3, delta); assertEquals(a.getString(), "7.3"); assertEquals(a.getNumber(), new Double(7.3)); byte[] raw = a.getRaw(); @@ -313,11 +341,12 @@ public class ExpressionTestCase extends TestCase { FloatResultNode b = new FloatResultNode(7.5); assertEquals(b.getInteger(), 8); - assertEquals(b.getFloat(), 7.5); + assertEquals(b.getFloat(), 7.5, delta); assertEquals(b.getString(), "7.5"); assertEquals(b.getNumber(), new Double(7.5)); } + @Test public void testGetDocIdNamespaceSpecificFunctionNode() { GetDocIdNamespaceSpecificFunctionNode a = new GetDocIdNamespaceSpecificFunctionNode(new IntegerResultNode(7)); assertTrue(a.getResult() instanceof IntegerResultNode); @@ -340,6 +369,7 @@ public class ExpressionTestCase extends TestCase { } } + @Test public void testGetYMUMChecksumFunctionNode() { GetYMUMChecksumFunctionNode a = new GetYMUMChecksumFunctionNode(); assertTrue(a.getResult() instanceof IntegerResultNode); @@ -358,10 +388,11 @@ public class ExpressionTestCase extends TestCase { } } + @Test public void testIntegerResultNode() { IntegerResultNode a = new IntegerResultNode(7); assertEquals(a.getInteger(), 7); - assertEquals(a.getFloat(), 7.0); + assertEquals(a.getFloat(), 7.0, delta); assertEquals(a.getString(), "7"); assertEquals(a.getNumber(), new Long(7)); byte[] raw = a.getRaw(); @@ -371,6 +402,7 @@ public class ExpressionTestCase extends TestCase { compare(new IntegerResultNode(-1), new IntegerResultNode(0), new IntegerResultNode(0x80000000L)); } + @Test public void testMaxFunctionNode() { assertMultiArgFunctionNode(new MaxFunctionNode()); assertFunctionNode(new MaxFunctionNode().addArg(new ConstantNode(new IntegerResultNode(3))) @@ -381,6 +413,7 @@ public class ExpressionTestCase extends TestCase { 5, 5.0, "5.0", doubleAsRaw(5.0)); } + @Test public void testMD5BitFunctionNode() { try { new MD5BitFunctionNode(null, 64); @@ -403,6 +436,7 @@ public class ExpressionTestCase extends TestCase { assertUnaryBitFunctionNode(new MD5BitFunctionNode()); } + @Test public void testMinFunctionNode() { assertMultiArgFunctionNode(new MinFunctionNode()); assertFunctionNode(new MinFunctionNode().addArg(new ConstantNode(new IntegerResultNode(3))) @@ -413,6 +447,7 @@ public class ExpressionTestCase extends TestCase { 5, 4.9999999, "4.9999999", doubleAsRaw(4.9999999)); } + @Test public void testModuloFunctionNode() { assertMultiArgFunctionNode(new ModuloFunctionNode()); assertFunctionNode(new ModuloFunctionNode().addArg(new ConstantNode(new IntegerResultNode(13))) @@ -423,6 +458,7 @@ public class ExpressionTestCase extends TestCase { 5, 4.9999999, "4.9999999", doubleAsRaw(4.9999999)); } + @Test public void testMultiplyFunctionNode() { assertMultiArgFunctionNode(new MultiplyFunctionNode()); assertFunctionNode(new MultiplyFunctionNode().addArg(new ConstantNode(new IntegerResultNode(3))) @@ -433,6 +469,7 @@ public class ExpressionTestCase extends TestCase { 23, 22.5, "22.5", doubleAsRaw(22.5)); } + @Test public void testNegateFunctionNode() { assertMultiArgFunctionNode(new NegateFunctionNode()); assertFunctionNode(new NegateFunctionNode().addArg(new ConstantNode(new IntegerResultNode(3))), @@ -441,73 +478,80 @@ public class ExpressionTestCase extends TestCase { -3, -3.0, "-3.0", doubleAsRaw(-3.0)); } + @Test public void testSortFunctionNode() { assertMultiArgFunctionNode(new SortFunctionNode()); - } + @Test public void testReverseFunctionNode() { assertMultiArgFunctionNode(new ReverseFunctionNode()); } + @Test public void testToIntFunctionNode() { assertMultiArgFunctionNode(new ToIntFunctionNode()); assertFunctionNode(new ToIntFunctionNode().addArg(new ConstantNode(new StringResultNode("1337"))), 1337, 1337.0, "1337", longAsRaw(1337)); } + @Test public void testToFloatFunctionNode() { assertMultiArgFunctionNode(new ToFloatFunctionNode()); assertFunctionNode(new ToFloatFunctionNode().addArg(new ConstantNode(new FloatResultNode(3.14))), 3, 3.14, "3.14", doubleAsRaw(3.14)); } + @Test public void testMathFunctionNode() { assertMultiArgFunctionNode(new MathFunctionNode(MathFunctionNode.Function.LOG10)); assertFunctionNode(new MathFunctionNode(MathFunctionNode.Function.LOG10).addArg(new ConstantNode(new IntegerResultNode(100000))), 5, 5.0, "5.0", doubleAsRaw(5.0)); } + @Test public void testStrLenFunctionNode() { assertMultiArgFunctionNode(new StrLenFunctionNode()); assertFunctionNode(new StrLenFunctionNode().addArg(new ConstantNode(new StringResultNode("foo"))), 3, 3.0, "3", longAsRaw(3)); } + @Test public void testNormalizeSubjectFunctionNode() { assertMultiArgFunctionNode(new NormalizeSubjectFunctionNode()); assertFunctionNode(new NormalizeSubjectFunctionNode().addArg(new ConstantNode(new StringResultNode("Re: Your mail"))), 0, 0, "Your mail", stringAsRaw("Your mail")); } + @Test public void testNormalizeSubjectFunctionNode2() { assertMultiArgFunctionNode(new NormalizeSubjectFunctionNode()); assertFunctionNode(new NormalizeSubjectFunctionNode().addArg(new ConstantNode(new StringResultNode("Your mail"))), 0, 0, "Your mail", stringAsRaw("Your mail")); } + @Test public void testNumElemFunctionNode() { assertMultiArgFunctionNode(new NumElemFunctionNode()); assertFunctionNode(new NumElemFunctionNode().addArg(new ConstantNode(new IntegerResultNode(1337))), 1, 1.0, "1", longAsRaw(1)); } + @Test public void testToStringFunctionNode() { assertMultiArgFunctionNode(new ToStringFunctionNode()); assertFunctionNode(new ToStringFunctionNode().addArg(new ConstantNode(new IntegerResultNode(1337))), 1337, 1337.0, "1337", stringAsRaw("1337")); } + @Test public void testToRawFunctionNode() { assertMultiArgFunctionNode(new ToRawFunctionNode()); assertFunctionNode(new ToRawFunctionNode().addArg(new ConstantNode(new IntegerResultNode(1337))), 1337, 1337.0, "1337", longAsRaw(1337)); } - public void testNullResultNode() { - // TODO: Implement. - } - + @Test public void testOrFunctionNode() { assertMultiArgFunctionNode(new OrFunctionNode()); assertFunctionNode(new OrFunctionNode().addArg(new ConstantNode(new IntegerResultNode(2))) @@ -515,6 +559,7 @@ public class ExpressionTestCase extends TestCase { 6, 6.0, "6", longAsRaw(6)); } + @Test public void testDebugWaitFunctionNode() { assertFunctionNode( new DebugWaitFunctionNode(new OrFunctionNode().addArg(new ConstantNode(new IntegerResultNode(2))) @@ -543,6 +588,7 @@ public class ExpressionTestCase extends TestCase { assertTrue(end - start > 450); } + @Test public void testRawResultNode() { try { new RawResultNode(null); @@ -564,7 +610,7 @@ public class ExpressionTestCase extends TestCase { assertEquals(raw[1], '.'); assertEquals(raw[2], '4'); assertEquals(a.getInteger(), 0); - assertEquals(a.getFloat(), 0.0); + assertEquals(a.getFloat(), 0.0, delta); assertEquals(a.getString(), "7.4"); assertResultNode(a); compare(new RawResultNode(), new RawResultNode(new byte [] {'z'}), new RawResultNode(new byte [] {'z', 'z'})); @@ -647,6 +693,7 @@ public class ExpressionTestCase extends TestCase { assertEquals(0, large.compareTo(large)); } + @Test public void testStringResultNode() { try { new StringResultNode(null); @@ -662,7 +709,7 @@ public class ExpressionTestCase extends TestCase { } StringResultNode a = new StringResultNode("7.3"); assertEquals(a.getInteger(), 0); - assertEquals(a.getFloat(), 7.3); + assertEquals(a.getFloat(), 7.3, delta); assertEquals(a.getString(), "7.3"); byte[] raw = a.getRaw(); assertEquals(raw.length, 3); @@ -672,6 +719,7 @@ public class ExpressionTestCase extends TestCase { compare(new StringResultNode("a"), new StringResultNode("zz"), new PositiveInfinityResultNode()); } + @Test public void testXorBitFunctionNode() { try { new XorBitFunctionNode(null, 64); @@ -694,6 +742,7 @@ public class ExpressionTestCase extends TestCase { assertUnaryBitFunctionNode(new XorBitFunctionNode()); } + @Test public void testUcaFunctionNode() { try { new UcaFunctionNode(null, "foo"); @@ -716,6 +765,7 @@ public class ExpressionTestCase extends TestCase { assertUcaFunctionNode(new UcaFunctionNode(new ConstantNode(new IntegerResultNode(1337)), "foo", "bar")); } + @Test public void testNestedFunctions() { assertFunctionNode(new AddFunctionNode() .addArg(new MultiplyFunctionNode().addArg(new ConstantNode(new IntegerResultNode(3))) @@ -725,6 +775,7 @@ public class ExpressionTestCase extends TestCase { 14, 14.0, "14.0", doubleAsRaw(14.0)); } + @Test public void testArithmeticNodes() { ExpressionNode i1 = new ConstantNode(new IntegerResultNode(1)); ExpressionNode i2 = new ConstantNode(new IntegerResultNode(2)); @@ -761,6 +812,7 @@ public class ExpressionTestCase extends TestCase { assertTrue(add4.getResult() instanceof IntegerResultNode); } + @Test public void testArithmeticOperations() { ExpressionNode i1 = new ConstantNode(new IntegerResultNode(1793253241)); ExpressionNode i2 = new ConstantNode(new IntegerResultNode(1676521321)); @@ -860,14 +912,14 @@ public class ExpressionTestCase extends TestCase { node.prepare(); node.execute(); assertEquals(lexpected, node.getResult().getInteger()); - assertEquals(dexpected, node.getResult().getFloat()); + assertEquals(dexpected, node.getResult().getFloat(), delta); } public void assertFunctionNode(FunctionNode node, long lexpected, double dexpected, String sexpected, byte[] rexpected) { node.prepare(); node.execute(); assertEquals(lexpected, node.getResult().getInteger()); - assertEquals(dexpected, node.getResult().getFloat()); + assertEquals(dexpected, node.getResult().getFloat(), delta); assertEquals(sexpected, node.getResult().getString()); assertTrue(Arrays.equals(rexpected, node.getResult().getRaw())); } @@ -882,7 +934,7 @@ public class ExpressionTestCase extends TestCase { buf.flip(); node.deserialize(buf); assertEquals(oldInteger, node.getInteger()); - assertEquals(oldFloat, node.getFloat()); + assertEquals(oldFloat, node.getFloat(), delta); assertEquals(oldString, node.getString()); assertEquals(oldRaw.length, node.getRaw().length); @@ -891,7 +943,7 @@ public class ExpressionTestCase extends TestCase { buf.flip(); node.deserializeWithId(buf); assertEquals(oldInteger, node.getInteger()); - assertEquals(oldFloat, node.getFloat()); + assertEquals(oldFloat, node.getFloat(), delta); assertEquals(oldString, node.getString()); assertEquals(oldRaw.length, node.getRaw().length); @@ -900,7 +952,7 @@ public class ExpressionTestCase extends TestCase { buf.flip(); ResultNode obj = (ResultNode)Identifiable.create(buf); assertEquals(oldInteger, obj.getInteger()); - assertEquals(oldFloat, obj.getFloat()); + assertEquals(oldFloat, obj.getFloat(), delta); assertEquals(oldString, obj.getString()); assertEquals(oldRaw.length, obj.getRaw().length); @@ -913,7 +965,7 @@ public class ExpressionTestCase extends TestCase { buf.flip(); Identifiable created = Identifiable.create(buf); assertEquals(node, created); - assertEquals(buf.getBuf().hasRemaining(), false); + assertFalse(buf.getBuf().hasRemaining()); Identifiable cloned = created.clone(); assertEquals(node, cloned); BufferSerializer createdBuffer = new BufferSerializer(new GrowableByteBuffer()); @@ -929,4 +981,5 @@ public class ExpressionTestCase extends TestCase { } return created; } + } diff --git a/searchlib/src/test/java/com/yahoo/searchlib/expression/ForceLoadTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/expression/ForceLoadTestCase.java index a5d216ff089..fa2c9cf1b1e 100755 --- a/searchlib/src/test/java/com/yahoo/searchlib/expression/ForceLoadTestCase.java +++ b/searchlib/src/test/java/com/yahoo/searchlib/expression/ForceLoadTestCase.java @@ -1,19 +1,22 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.searchlib.expression; -public class ForceLoadTestCase extends junit.framework.TestCase { +import org.junit.Test; - public ForceLoadTestCase(String name) { - super(name); - } +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class ForceLoadTestCase { + @Test public void testLoadClasses() { try { new com.yahoo.searchlib.expression.ForceLoad(); assertTrue(com.yahoo.searchlib.expression.ForceLoad.forceLoad()); } catch (com.yahoo.system.ForceLoadError e) { e.printStackTrace(); - assertTrue(false); + fail("Load failed"); } } + } diff --git a/searchlib/src/test/java/com/yahoo/searchlib/expression/ObjectVisitorTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/expression/ObjectVisitorTestCase.java index 1d1fa8251fd..286a6a702db 100755 --- a/searchlib/src/test/java/com/yahoo/searchlib/expression/ObjectVisitorTestCase.java +++ b/searchlib/src/test/java/com/yahoo/searchlib/expression/ObjectVisitorTestCase.java @@ -2,18 +2,18 @@ package com.yahoo.searchlib.expression; import com.yahoo.vespa.objects.ObjectDumper; -import com.yahoo.searchlib.expression.FixedWidthBucketFunctionNode; -import com.yahoo.searchlib.expression.IntegerResultNode; -import com.yahoo.searchlib.expression.AttributeNode; -import junit.framework.TestCase; +import org.junit.Test; import java.util.Arrays; +import static org.junit.Assert.assertEquals; + /** - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ -public class ObjectVisitorTestCase extends TestCase { +public class ObjectVisitorTestCase { + @Test public void testObjectDumper() { assertDump("test: <NULL>\n", null); assertDump("test: 1\n", 1); @@ -58,4 +58,5 @@ public class ObjectVisitorTestCase extends TestCase { dump.visit("test", obj); assertEquals(expected, dump.toString()); } + } diff --git a/searchlib/src/test/java/com/yahoo/searchlib/ranking/features/fieldmatch/SemanticDistanceTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/ranking/features/fieldmatch/SemanticDistanceTestCase.java index 68db4867cf7..eb0e46ad6dc 100644 --- a/searchlib/src/test/java/com/yahoo/searchlib/ranking/features/fieldmatch/SemanticDistanceTestCase.java +++ b/searchlib/src/test/java/com/yahoo/searchlib/ranking/features/fieldmatch/SemanticDistanceTestCase.java @@ -1,11 +1,15 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.searchlib.ranking.features.fieldmatch; -import com.yahoo.searchlib.ranking.features.fieldmatch.FieldMatchMetricsComputer; +import org.junit.Before; +import org.junit.Test; import java.util.Set; import java.util.HashSet; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * The "semantic distance" refers to the non-continuous distance from a token * to the next token used by the string match metrics algorithm. This class @@ -14,24 +18,21 @@ import java.util.HashSet; * * @author bratseth */ -public class SemanticDistanceTestCase extends junit.framework.TestCase { +public class SemanticDistanceTestCase { FieldMatchMetricsComputer c; - public SemanticDistanceTestCase(String name) { - super(name); - } - - @Override + @Before public void setUp() { c=new FieldMatchMetricsComputer(); - StringBuilder field=new StringBuilder(); - for (int i=0; i<150; i++) + StringBuilder field = new StringBuilder(); + for (int i = 0; i < 150; i++) field.append("t" + i + " "); - c.compute("query",field.toString()); // Just to set the field value + c.compute("query", field.toString()); // Just to set the field value } /** Must be true using any semantic distance function */ + @Test public void testBothWayConversionProducesOriginalValue() { assertBothWayConversionProducesOriginalValue(50); assertBothWayConversionProducesOriginalValue(10); @@ -43,6 +44,7 @@ public class SemanticDistanceTestCase extends junit.framework.TestCase { } /** Must be true using any semantic distance function */ + @Test public void testFunctionsAreOneToOne() { assertFunctionsAreOneToOne(50); assertFunctionsAreOneToOne(10); @@ -54,52 +56,54 @@ public class SemanticDistanceTestCase extends junit.framework.TestCase { } /** Specific to this particular distance function */ + @Test public void testFunction() { - int zeroJ=50; - assertFunction(50,0,zeroJ); - assertFunction(59,9,zeroJ); - assertFunction(49,10,zeroJ); - assertFunction(40,19,zeroJ); - assertFunction(60,20,zeroJ); - assertFunction(149,109,zeroJ); - assertFunction(39,110,zeroJ); - assertFunction(0,149,zeroJ); - - zeroJ=0; - assertFunction(0,0,zeroJ); - assertFunction(10,10,zeroJ); - assertFunction(20,20,zeroJ); - assertFunction(149,149,zeroJ); - - zeroJ=5; - assertFunction(5,0,zeroJ); - assertFunction(10,5,zeroJ); - assertFunction(14,9,zeroJ); - assertFunction(4,10,zeroJ); - assertFunction(0,14,zeroJ); - assertFunction(15,15,zeroJ); - assertFunction(25,25,zeroJ); - assertFunction(149,149,zeroJ); - - zeroJ=149; - assertFunction(149,0,zeroJ); - assertFunction(140,9,zeroJ); - assertFunction(130,19,zeroJ); - assertFunction(0,149,zeroJ); - - zeroJ=145; - assertFunction(145,0,zeroJ); - assertFunction(149,4,zeroJ); - assertFunction(144,5,zeroJ); - assertFunction(140,9,zeroJ); - assertFunction(135,14,zeroJ); - assertFunction(125,24,zeroJ); - assertFunction(0,149,zeroJ); + int zeroJ = 50; + assertFunction(50,0, zeroJ); + assertFunction(59,9, zeroJ); + assertFunction(49,10, zeroJ); + assertFunction(40,19, zeroJ); + assertFunction(60,20, zeroJ); + assertFunction(149,109, zeroJ); + assertFunction(39,110, zeroJ); + assertFunction(0,149, zeroJ); + + zeroJ = 0; + assertFunction(0,0, zeroJ); + assertFunction(10,10, zeroJ); + assertFunction(20,20, zeroJ); + assertFunction(149,149, zeroJ); + + zeroJ = 5; + assertFunction(5,0, zeroJ); + assertFunction(10,5, zeroJ); + assertFunction(14,9, zeroJ); + assertFunction(4,10, zeroJ); + assertFunction(0,14, zeroJ); + assertFunction(15,15, zeroJ); + assertFunction(25,25, zeroJ); + assertFunction(149,149, zeroJ); + + zeroJ = 149; + assertFunction(149,0, zeroJ); + assertFunction(140,9, zeroJ); + assertFunction(130,19, zeroJ); + assertFunction(0,149, zeroJ); + + zeroJ = 145; + assertFunction(145,0, zeroJ); + assertFunction(149,4, zeroJ); + assertFunction(144,5, zeroJ); + assertFunction(140,9, zeroJ); + assertFunction(135,14, zeroJ); + assertFunction(125,24, zeroJ); + assertFunction(0,149, zeroJ); } /** Hits both limits at once */ + @Test public void testSmallField() { - c=new FieldMatchMetricsComputer(); + c = new FieldMatchMetricsComputer(); c.compute("query","my field value four"); // Just to set the field value assertBothWayConversionProducesOriginalValue(2); assertBothWayConversionProducesOriginalValue(0); @@ -109,33 +113,34 @@ public class SemanticDistanceTestCase extends junit.framework.TestCase { assertFunctionsAreOneToOne(3); int zeroJ=2; - assertFunction(2,0,zeroJ); - assertFunction(3,1,zeroJ); - assertFunction(1,2,zeroJ); - assertFunction(0,3,zeroJ); + assertFunction(2,0, zeroJ); + assertFunction(3,1, zeroJ); + assertFunction(1,2, zeroJ); + assertFunction(0,3, zeroJ); } private void assertBothWayConversionProducesOriginalValue(int zeroJ) { // Starting point in the middle - for (int j=0; j<c.getField().terms().size(); j++) { - int semanticDistance=c.fieldIndexToSemanticDistance(j,zeroJ); + for (int j = 0; j < c.getField().terms().size(); j++) { + int semanticDistance=c.fieldIndexToSemanticDistance(j, zeroJ); assertTrue("Using zeroJ=" + zeroJ + ": " + semanticDistance +">=0", semanticDistance >= 0); - int backConvertedJ=c.semanticDistanceToFieldIndex(semanticDistance,zeroJ); + int backConvertedJ=c.semanticDistanceToFieldIndex(semanticDistance, zeroJ); assertEquals("Using zeroJ=" + zeroJ + ": " + j + "->" + semanticDistance + "->" + backConvertedJ,j, backConvertedJ); } } private void assertFunctionsAreOneToOne(int zeroJ) { - Set<Integer> distances=new HashSet<Integer>(); - for (int j=0; j<c.getField().terms().size(); j++) { - int semanticDistance=c.fieldIndexToSemanticDistance(j,zeroJ); - assertTrue("Using zeroJ=" + zeroJ + ": " + j + "->" + semanticDistance + " is unique", ! distances.contains(semanticDistance)); + Set<Integer> distances = new HashSet<>(); + for (int j = 0; j < c.getField().terms().size(); j++) { + int semanticDistance = c.fieldIndexToSemanticDistance(j,zeroJ); + assertTrue("Using zeroJ=" + zeroJ + ": " + j + "->" + semanticDistance + " is unique", + ! distances.contains(semanticDistance)); distances.add(semanticDistance); } } - private void assertFunction(int j,int semanticDistance,int zeroJ) { - assertEquals(j + "->" + semanticDistance,semanticDistance,c.fieldIndexToSemanticDistance(j,zeroJ)); + private void assertFunction(int j,int semanticDistance, int zeroJ) { + assertEquals(j + "->" + semanticDistance,semanticDistance, c.fieldIndexToSemanticDistance(j,zeroJ)); } } diff --git a/searchlib/src/test/java/com/yahoo/searchlib/ranking/features/fieldmatch/reference/test/OptimalStringAlignmentTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/ranking/features/fieldmatch/reference/test/OptimalStringAlignmentTestCase.java index b2db0d0f805..c9b812894ba 100644 --- a/searchlib/src/test/java/com/yahoo/searchlib/ranking/features/fieldmatch/reference/test/OptimalStringAlignmentTestCase.java +++ b/searchlib/src/test/java/com/yahoo/searchlib/ranking/features/fieldmatch/reference/test/OptimalStringAlignmentTestCase.java @@ -2,20 +2,22 @@ package com.yahoo.searchlib.ranking.features.fieldmatch.reference.test; import com.yahoo.searchlib.ranking.features.fieldmatch.reference.OptimalStringAlignmentDistance; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * @author bratseth */ -public class OptimalStringAlignmentTestCase extends junit.framework.TestCase { +public class OptimalStringAlignmentTestCase { - public OptimalStringAlignmentTestCase(String name) { - super(name); - } + private final double delta = 0.0000000001; + @Test public void testEditDistance() { // Edit distance, substitution, deletion, insertion, transposition, query, field, print? - boolean print=false; + boolean print = false; assertEditDistance(0,0,0,0,0,"niels bohr","niels bohr",print); assertEditDistance(1,1,0,0,0,"niels","bohr",print); assertEditDistance(1,0,0,1,0,"niels","niels bohr",print); @@ -27,8 +29,9 @@ public class OptimalStringAlignmentTestCase extends junit.framework.TestCase { assertEditDistance(3,2,0,1,0,"niels bohr i kopenhagen","niels henrik bor i stockholm",print); } + @Test public void testEditDistanceAsRelevance() { - boolean print=false; + boolean print = false; assertEditDistance(2,0,0,2,0,"niels bohr","niels blah blah bohr",print); assertEditDistance(4,0,1,3,0,"niels bohr","bohr blah blah niels",print); // Not desired assertEditDistance(4,2,0,2,0,"niels bohr","koko blah blah bahia",print); @@ -48,11 +51,11 @@ public class OptimalStringAlignmentTestCase extends junit.framework.TestCase { System.out.println(); } - assertEquals("Substitutions",(float)substitution,e.getSubstitutions()); - assertEquals("Deletions",(float)deletion,e.getDeletions()); - assertEquals("Insertions",(float)insertion,e.getInsertions()); - assertEquals("Transpositions",(float)transposition,e.getTranspositions()); - assertEquals("Total",(float)total,e.getTotal()); + assertEquals("Substitutions",(float)substitution,e.getSubstitutions(), delta); + assertEquals("Deletions",(float)deletion,e.getDeletions(), delta); + assertEquals("Insertions",(float)insertion,e.getInsertions(), delta); + assertEquals("Transpositions",(float)transposition,e.getTranspositions(), delta); + assertEquals("Total",(float)total,e.getTotal(), delta); } } diff --git a/searchlib/src/test/java/com/yahoo/searchlib/ranking/features/fieldmatch/test/FieldMatchMetricsTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/ranking/features/fieldmatch/test/FieldMatchMetricsTestCase.java index 6f9b0f03b6b..4918ee5bdcd 100644 --- a/searchlib/src/test/java/com/yahoo/searchlib/ranking/features/fieldmatch/test/FieldMatchMetricsTestCase.java +++ b/searchlib/src/test/java/com/yahoo/searchlib/ranking/features/fieldmatch/test/FieldMatchMetricsTestCase.java @@ -8,21 +8,21 @@ import com.yahoo.searchlib.ranking.features.fieldmatch.FieldMatchMetricsComputer import com.yahoo.searchlib.ranking.features.fieldmatch.FieldMatchMetricsParameters; import com.yahoo.searchlib.ranking.features.fieldmatch.QueryTerm; import com.yahoo.searchlib.ranking.features.fieldmatch.Query; +import org.junit.Test; import java.util.List; +import static org.junit.Assert.assertEquals; + /** * Tests of calculation of all the string match metrics. * Add true as the fourth parameter to assertMetrics to see a trace of what the test is doing. * * @author bratseth */ -public class FieldMatchMetricsTestCase extends junit.framework.TestCase { - - public FieldMatchMetricsTestCase(String name) { - super(name); - } +public class FieldMatchMetricsTestCase { + @Test public void testOutOfOrder() { assertMetrics("outOfOrder:0","a","a"); assertMetrics("outOfOrder:0","a b c","a b c"); @@ -33,6 +33,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("outOfOrder:2", "a b c d e", "c x a b x x x x x e x x d"); } + @Test public void testSegments() { assertMetrics("segments:1","a","a"); assertMetrics("segments:1","a b c","a b c"); @@ -45,6 +46,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("segments:2 gaps:1","a y y b c","x x x b x x c x x x x x x x x x x x x x x x x x x x a x x"); } + @Test public void testGaps() { assertMetrics("gaps:0","a","a"); assertMetrics("gaps:0","x�a","a"); @@ -59,6 +61,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("gaps:0","y a b c","a b c x"); } + @Test public void testHead() { assertMetrics("head:0","a","a"); assertMetrics("head:0","y","a"); @@ -68,6 +71,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("head:2", "a b c", "x x c x x x x x x x x x x x x x x x a b"); } + @Test public void testTail() { assertMetrics("tail:0","a","a"); assertMetrics("tail:0","y","a"); @@ -77,6 +81,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("tail:0","a b c","x x c x x x x x x x x x x x x x x x a b"); } + @Test public void testLongestSequence() { assertMetrics("longestSequence:1","a","a"); assertMetrics("longestSequence:1","a","a b c"); @@ -89,6 +94,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("longestSequence:4 segments:1","a b c d","x x a b x x x x x x x x x x x x x x x x x c d x x a b c d"); } + @Test public void testMatches() { assertMetrics("matches:1 queryCompleteness:1 fieldCompleteness:1", "a","a"); assertMetrics("matches:3 queryCompleteness:1 fieldCompleteness:1", "a b c","a b c"); @@ -96,6 +102,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("matches:3 queryCompleteness:0.5 fieldCompleteness:0.25","a y y b c y","a x x b c x a x a b x x"); } + @Test public void testCompleteness() { assertMetrics("completeness:1 queryCompleteness:1 fieldCompleteness:1", "a","a"); assertMetrics("completeness:0 queryCompleteness:0 fieldCompleteness:0", "a","x"); @@ -109,6 +116,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("completeness:0.97 queryCompleteness:1 fieldCompleteness:0.4","a b","a b b b b"); } + @Test public void testOrderness() { assertMetrics("orderness:1", "a","a"); assertMetrics("orderness:1", "a","x"); @@ -120,6 +128,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("orderness:1", "a b","b x x x x x x x x x x x x x x x x x x x x x a"); } + @Test public void testRelatedness() { assertMetrics("relatedness:1", "a","a"); assertMetrics("relatedness:0", "a","x"); @@ -129,6 +138,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("relatedness:0.5","a y b y y y c","a b x x x x x x x x x x x x x x x x x x x x x x x c"); } + @Test public void testLongestSequenceRatio() { assertMetrics("longestSequenceRatio:1", "a","a"); assertMetrics("longestSequenceRatio:0", "a","x"); @@ -140,6 +150,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("longestSequenceRatio:0.75","a b c d","x x a b x a x c d a b c x d x"); } + @Test public void testEarliness() { assertMetrics("earliness:1", "a","a"); assertMetrics("earliness:0", "a","x"); @@ -151,6 +162,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("earliness:0.2", "a b c","x b c a x x x x a x x x x x x x a b c x x"); } + @Test public void testWeight() { assertMetrics("weight:1", "a","a"); assertMetrics("weight:0", "y","a"); @@ -216,6 +228,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { } /** Calculated the same way as weight */ + @Test public void testSignificance() { assertMetrics("significance:1", "a","a"); assertMetrics("significance:0", "a","x"); @@ -280,6 +293,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("significance:0","a%0 b%0","",0.3f); } + @Test public void testImportance() { assertMetrics("importance:0.75","a b c", "a x x b x c c c",600); assertMetrics("importance:0.85","a b!500 c","a x x b x c c c",1000); @@ -290,6 +304,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("importance:0.85","a b!500%0.5 c","a x x b x c c c",1000); } + @Test public void testOccurrence() { assertMetrics("occurrence:0","a","x"); assertMetrics("occurrence:1","a","a"); @@ -313,6 +328,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("occurrence:1", "a b","a a a a a a a a a a a b b b b b b b b b b b",false,c); // Field is too large to consider field length } + @Test public void testAbsoluteOccurrence() { assertMetrics("absoluteOccurrence:0", "a","x"); assertMetrics("absoluteOccurrence:0.01","a","a"); @@ -336,6 +352,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("absoluteOccurrence:1", "a b","a a a a a a a a a a a b b b b b b b b b b b",false,c); // Field is too large to consider field length } + @Test public void testWeightedOccurrence() { assertMetrics("weightedOccurrence:0","a!200","x"); assertMetrics("weightedOccurrence:1","a!200","a"); @@ -378,6 +395,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("weightedOccurrence:1", "a!200 b","a a a a a a a a a a a b b b b b b b b b b b",false,c); // Field is too large to consider field length } + @Test public void testWeightedAbsoluteOccurrence() { assertMetrics("weightedAbsoluteOccurrence:0", "a!200","x"); assertMetrics("weightedAbsoluteOccurrence:0.01", "a!200","a"); @@ -420,6 +438,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("weightedAbsoluteOccurrence:1", "a!200 b","a a a a a a a a a a a b b b b b b b b b b b",false,c); // Field is too large to consider field length } + @Test public void testSignificantOccurrence() { assertMetrics("significantOccurrence:0","a%0.2","x"); assertMetrics("significantOccurrence:1","a%0.2","a"); @@ -462,6 +481,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("significantOccurrence:1", "a%0.2 b","a a a a a a a a a a a b b b b b b b b b b b",false,c); // Field is too large to consider field length } + @Test public void testUnweightedProximity() { assertMetrics("unweightedProximity:1", "a","a"); assertMetrics("unweightedProximity:1", "a b c","a b c"); @@ -476,6 +496,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("unweightedProximity:0.5", "y a b c","a x x b x x c x"); } + @Test public void testReverseProximity() { assertMetrics("unweightedProximity:0.33", "a b","b a"); assertMetrics("unweightedProximity:0.62", "a b c","c a b"); @@ -485,6 +506,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("unweightedProximity:0.9275","a b c d e","a b x c d e"); } + @Test public void testProximity() { assertMetrics("absoluteProximity:0.1 proximity:1", "a b","a b"); assertMetrics("absoluteProximity:0.3 proximity:1", "a 0.3:b","a b"); @@ -509,6 +531,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { * Tests exactness (using field exactness only - nothing additional of interest to test with query exactness * as that is just another number multiplied with the term exactness) */ + @Test public void testExactness() { assertMetrics("exactness:1", "a b c","a x b x x c"); assertMetrics("exactness:0.9", "a b c","a x b:0.7 x x c"); @@ -517,12 +540,14 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("exactness:0.65", "a b c!200","a x b:0.6 x x c:0.5"); } + @Test public void testMultiSegmentProximity() { assertMetrics("absoluteProximity:0.1 proximity:1", "a b c", "a b x x x x x x x x x x x x x x x x x x x x x x c"); assertMetrics("absoluteProximity:0.05 proximity:0.5","a b c", "a x x b x x x x x x x x x x x x x x x x x x x x x x c"); assertMetrics("absoluteProximity:0.075 proximity:0.75","a b c d","a x x b x x x x x x x x x x x x x x x x x x x x x x c d"); } + @Test public void testSegmentDistance() { assertMetrics("segmentDistance:13 absoluteProximity:0.1", "a b c","a b x x x x x x x x x x c"); assertMetrics("segmentDistance:13 absoluteProximity:0.5", "a 0.5:b c","a b x x x x x x x x x x c"); @@ -534,6 +559,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("segmentDistance:25 absoluteProximity:0.1", "a b c","c x x x x x x x x x x x b x x x x x x x x x x a"); } + @Test public void testSegmentProximity() { assertMetrics("segmentProximity:1", "a","a"); assertMetrics("segmentProximity:0", "a","x"); @@ -546,6 +572,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { } /** Test cases where we choose between multiple different segmentations */ + @Test public void testSegmentSelection() { assertMetrics("segments:2 absoluteProximity:0.1 proximity:1 segmentStarts:19,41", "a b c d e","x a b x c x x x x x x x x x x x x x x a b c x x x x x x x x x e x d x c d x x x c d e"); @@ -567,12 +594,14 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("segments:1 segmentStarts:0","a b c d","a b x x x x x x x x c d x x x x x x x x x x x a b x x x x x x x x x x x c d"); } + @Test public void testMoreThanASegmentLengthOfUnmatchedQuery() { assertMetrics("absoluteProximity:0.1 proximity:1","a b y y y y y y y y y y y y y y y","a b"); assertMetrics("segments:2 absoluteProximity:0.1 proximity:1","a b c d y y y y y y y y y y y y y y y","a b x x x x x x x x x x x x x x x x x x c d"); assertMetrics("segments:2 absoluteProximity:0.1 proximity:1","a b y y y y y y y y y y y y y y y c d","a b x x x x x x x x x x x x x x x x x x c d"); } + @Test public void testQueryRepeats() { // Not really handled perfectly, but good enough assertMetrics("absoluteProximity:0.1 proximity:1 head:0 tail:0", "a a a","a"); @@ -588,6 +617,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("matches:2 fieldCompleteness:1","a b b b","a b"); } + @Test public void testZeroCases() { assertMetrics("absoluteProximity:0.1 proximity:1 matches:0 exactness:0","y","a"); assertMetrics("absoluteProximity:0.1 proximity:1 matches:0 exactness:0","a","x"); @@ -596,8 +626,8 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("absoluteProximity:0.1 proximity:1 matches:0 exactness:0","",""); } + @Test public void testExceedingIterationLimit() { - { // Segments found: a x x b and c d FieldMatchMetricsParameters p=new FieldMatchMetricsParameters(); p.setMaxAlternativeSegmentations(0); @@ -620,6 +650,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { } } + @Test public void testMatch() { // Ordered by decreasing match score per query assertMetrics("match:1", "a","a"); @@ -647,6 +678,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { assertMetrics("match:0.2927","a b!200 c","x x a x b:0.7 x x x x x x x x x x x x x x x x x x x x x x"); } + @Test public void testRepeatedMatch() { // gap==1 caused by finding two possible segments due to repeated matching assertMetrics("fieldCompleteness:1 queryCompleteness:0.6667 segments:1 earliness:1 gaps:1", @@ -654,6 +686,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { } /** Three segments - improving the score on the first should impact the last */ + @Test public void testNestedAlternatives() { assertMetrics("segmentStarts:6,19,32 proximity:1", "a b c d e f", @@ -664,6 +697,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { } /** Nice demonstration of the limitations of this algorithm: Segment end points are determined greedily */ + @Test public void testSegmentationGreedyness() { assertMetrics("match:0.3717","a b c","a x b x x x x x x x x b c"); assertMetrics("match:0.4981","a b c","a x z x x x x x x x x b c"); @@ -715,7 +749,7 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { } else { float correctValue=Float.parseFloat(correctValueString); - assertEquals(metricName, correctValue, (float)Math.round(metrics.get(metricName)*10000)/10000 ); + assertEquals(metricName, correctValue, (float)Math.round(metrics.get(metricName)*10000)/10000, 0.000000001); } } } @@ -754,4 +788,5 @@ public class FieldMatchMetricsTestCase extends junit.framework.TestCase { } return new Field(terms.build()); } + } diff --git a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/ReferenceTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/ReferenceTestCase.java index f275f95ca8e..4298beb5233 100644 --- a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/ReferenceTestCase.java +++ b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/ReferenceTestCase.java @@ -5,9 +5,9 @@ import com.yahoo.searchlib.rankingexpression.rule.NameNode; import com.yahoo.searchlib.rankingexpression.rule.ReferenceNode; import org.junit.Test; -import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author bratseth diff --git a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/ContextReuseTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/ContextReuseTestCase.java index 3d5710b81e0..3ad5c0f7316 100644 --- a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/ContextReuseTestCase.java +++ b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/ContextReuseTestCase.java @@ -6,19 +6,22 @@ import com.yahoo.searchlib.rankingexpression.RankingExpression; import com.yahoo.searchlib.rankingexpression.evaluation.ArrayContext; import com.yahoo.searchlib.rankingexpression.evaluation.ExpressionOptimizer; import com.yahoo.searchlib.rankingexpression.parser.ParseException; +import org.junit.Test; import java.io.File; import java.io.IOException; +import static org.junit.Assert.assertEquals; + /** * This tests reuse of a optimized context which is not initialized with * all values referenced in the expression. * * @author bratseth */ -public class ContextReuseTestCase extends junit.framework.TestCase { +public class ContextReuseTestCase { - private String contextString= + private String contextString = "CONCEPTTYPE = 0.0\n" + "REGEXTYPE = 0.0\n" + "POS_18 = 0.0\n" + @@ -43,6 +46,7 @@ public class ContextReuseTestCase extends junit.framework.TestCase { "EXTENDEDTYPE = 0.0\n" + "ENTITYPLACETYPE = 0.0\n"; + @Test public void testIt() throws ParseException, IOException { // Prepare RankingExpression expression=new RankingExpression(IOUtils.readFile(new File("src/test/files/s-expression.vre"))); @@ -55,7 +59,7 @@ public class ContextReuseTestCase extends junit.framework.TestCase { String[] contextValueParts = contextValueString.split("="); context.put(contextValueParts[0].trim(), Double.valueOf(contextValueParts[1].trim())); } - assertEquals(-2.3450294999999994, expression.evaluate(context).asDouble()); + assertEquals(-2.3450294999999994, expression.evaluate(context).asDouble(), 0.000000000001); } } diff --git a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/GBDTForestOptimizerTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/GBDTForestOptimizerTestCase.java index 420819a8b2a..ce78703f842 100644 --- a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/GBDTForestOptimizerTestCase.java +++ b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/GBDTForestOptimizerTestCase.java @@ -4,12 +4,17 @@ package com.yahoo.searchlib.rankingexpression.evaluation.gbdtoptimization; import com.yahoo.searchlib.rankingexpression.RankingExpression; import com.yahoo.searchlib.rankingexpression.evaluation.*; import com.yahoo.searchlib.rankingexpression.parser.ParseException; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * @author bratseth */ -public class GBDTForestOptimizerTestCase extends junit.framework.TestCase { +public class GBDTForestOptimizerTestCase { + @Test public void testForestOptimization() throws ParseException { String gbdtString = "if (LW_NEWS_SEARCHES_RATIO < 1.72971, 0.0697159, if (LW_USERS < 0.10496, if (SEARCHES < 0.0329127, 0.151257, 0.117501), if (SUGG_OVERLAP < 18.5, 0.0897622, 0.0756903))) + \n" + @@ -55,6 +60,7 @@ public class GBDTForestOptimizerTestCase extends junit.framework.TestCase { assertEqualish(result3, oResult3); } + @Test public void testForestOptimizationWithSetMembershipConditions() throws ParseException { String gbdtString = "if (MYSTRING in [\"string 1\",\"string 2\"], 0.0697159, if (LW_USERS < 0.10496, if (SEARCHES < 0.0329127, 0.151257, 0.117501), if (MYSTRING in [\"string 2\"], 0.0897622, 0.0756903))) + \n" + diff --git a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/GBDTOptimizerTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/GBDTOptimizerTestCase.java index 1cbd19b667e..4b7462505fc 100644 --- a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/GBDTOptimizerTestCase.java +++ b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/gbdtoptimization/GBDTOptimizerTestCase.java @@ -7,96 +7,105 @@ import com.yahoo.searchlib.rankingexpression.evaluation.ExpressionOptimizer; import com.yahoo.searchlib.rankingexpression.evaluation.MapContext; import com.yahoo.searchlib.rankingexpression.evaluation.OptimizationReport; import com.yahoo.searchlib.rankingexpression.parser.ParseException; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * @author bratseth */ -public class GBDTOptimizerTestCase extends junit.framework.TestCase { +public class GBDTOptimizerTestCase { + + private final double delta = 0.00000000001; + @Test public void testSimpleNodeOptimization() throws ParseException { - RankingExpression gbdt=new RankingExpression("if (a < 2, if (b < 2, 5, 6), 4) + if (a < 3, 7, 8)"); + RankingExpression gbdt = new RankingExpression("if (a < 2, if (b < 2, 5, 6), 4) + if (a < 3, 7, 8)"); // Optimized evaluation - ArrayContext arguments=new ArrayContext(gbdt); - ExpressionOptimizer optimizer=new ExpressionOptimizer(); + ArrayContext arguments = new ArrayContext(gbdt); + ExpressionOptimizer optimizer = new ExpressionOptimizer(); optimizer.getOptimizer(GBDTForestOptimizer.class).setEnabled(false); - OptimizationReport report=optimizer.optimize(gbdt,arguments); - assertEquals(2,report.getMetric("Optimized GDBT trees")); - arguments.put("a",1d); - arguments.put("b",2d); - assertEquals(13.0,gbdt.evaluate(arguments).asDouble()); + OptimizationReport report = optimizer.optimize(gbdt,arguments); + assertEquals(2, report.getMetric("Optimized GDBT trees")); + arguments.put("a", 1d); + arguments.put("b", 2d); + assertEquals(13.0, gbdt.evaluate(arguments).asDouble(), delta); } + @Test public void testNodeOptimization() throws ParseException { - String gbdtString= + String gbdtString = "if (LW_NEWS_SEARCHES_RATIO < 1.72971, 0.0697159, if (LW_USERS < 0.10496, if (SEARCHES < 0.0329127, 0.151257, 0.117501), if (SUGG_OVERLAP < 18.5, 0.0897622, 0.0756903))) + \n" + "if (LW_NEWS_SEARCHES_RATIO < 1.73156, if (NEWS_USERS < 0.0737993, -0.00481646, 0.00110018), if (LW_USERS < 0.0844616, 0.0488919, if (SUGG_OVERLAP < 32.5, 0.0136917, 9.85328E-4))) + \n" + "if (LW_NEWS_SEARCHES_RATIO < 1.74451, -0.00298257, if (LW_USERS < 0.116207, if (SEARCHES < 0.0329127, 0.0676105, 0.0340198), if (NUM_WORDS < 1.5, -8.55514E-5, 0.0112406))) + \n" + "if (LW_NEWS_SEARCHES_RATIO < 1.72995, if (NEWS_USERS < 0.0737993, -0.00407515, 0.00139088), if (LW_USERS == 0.0509035, 0.0439466, if (LW_USERS < 0.325818, 0.0187156, 0.00236949)))"; - RankingExpression gbdt=new RankingExpression(gbdtString); + RankingExpression gbdt = new RankingExpression(gbdtString); // Regular evaluation - MapContext arguments=new MapContext(); - arguments.put("LW_NEWS_SEARCHES_RATIO",1d); - arguments.put("SUGG_OVERLAP",17d); - double result1=gbdt.evaluate(arguments).asDouble(); - arguments.put("LW_NEWS_SEARCHES_RATIO",2d); - arguments.put("SUGG_OVERLAP",20d); - double result2=gbdt.evaluate(arguments).asDouble(); - arguments.put("LW_NEWS_SEARCHES_RATIO",2d); - arguments.put("SUGG_OVERLAP",40d); - double result3=gbdt.evaluate(arguments).asDouble(); + MapContext arguments = new MapContext(); + arguments.put("LW_NEWS_SEARCHES_RATIO", 1d); + arguments.put("SUGG_OVERLAP", 17d); + double result1 = gbdt.evaluate(arguments).asDouble(); + arguments.put("LW_NEWS_SEARCHES_RATIO", 2d); + arguments.put("SUGG_OVERLAP", 20d); + double result2 = gbdt.evaluate(arguments).asDouble(); + arguments.put("LW_NEWS_SEARCHES_RATIO", 2d); + arguments.put("SUGG_OVERLAP", 40d); + double result3 = gbdt.evaluate(arguments).asDouble(); // Optimized evaluation - ArrayContext fArguments=new ArrayContext(gbdt); - ExpressionOptimizer optimizer=new ExpressionOptimizer(); + ArrayContext fArguments = new ArrayContext(gbdt); + ExpressionOptimizer optimizer = new ExpressionOptimizer(); optimizer.getOptimizer(GBDTForestOptimizer.class).setEnabled(false); - OptimizationReport report=optimizer.optimize(gbdt,fArguments); - assertEquals(4,report.getMetric("Optimized GDBT trees")); - fArguments.put("LW_NEWS_SEARCHES_RATIO",1d); - fArguments.put("SUGG_OVERLAP",17d); - double oResult1=gbdt.evaluate(fArguments).asDouble(); - fArguments.put("LW_NEWS_SEARCHES_RATIO",2d); - fArguments.put("SUGG_OVERLAP",20d); - double oResult2=gbdt.evaluate(fArguments).asDouble(); - fArguments.put("LW_NEWS_SEARCHES_RATIO",2d); - fArguments.put("SUGG_OVERLAP",40d); - double oResult3=gbdt.evaluate(fArguments).asDouble(); + OptimizationReport report = optimizer.optimize(gbdt,fArguments); + assertEquals(4, report.getMetric("Optimized GDBT trees")); + fArguments.put("LW_NEWS_SEARCHES_RATIO", 1d); + fArguments.put("SUGG_OVERLAP", 17d); + double oResult1 = gbdt.evaluate(fArguments).asDouble(); + fArguments.put("LW_NEWS_SEARCHES_RATIO", 2d); + fArguments.put("SUGG_OVERLAP", 20d); + double oResult2 = gbdt.evaluate(fArguments).asDouble(); + fArguments.put("LW_NEWS_SEARCHES_RATIO", 2d); + fArguments.put("SUGG_OVERLAP", 40d); + double oResult3 = gbdt.evaluate(fArguments).asDouble(); // Assert the same results are produced - assertEquals(result1,oResult1); - assertEquals(result2,oResult2); - assertEquals(result3,oResult3); + assertEquals(result1, oResult1, delta); + assertEquals(result2, oResult2, delta); + assertEquals(result3, oResult3, delta); } + @Test public void testFeatureNamesWithDots() throws ParseException { - String gbdtString= + String gbdtString = "if (a.b < 1.72971, 0.0697159, if (a.b.c < 0.10496, if (a.c < 0.0329127, 0.151257, 0.117501), if (a < 18.5, 0.0897622, 0.0756903))) + 1"; - RankingExpression gbdt=new RankingExpression(gbdtString); + RankingExpression gbdt = new RankingExpression(gbdtString); // Regular evaluation - MapContext arguments=new MapContext(); - arguments.put("a.b",1d); - arguments.put("a.b.c",0.1d); - arguments.put("a.c",0.01d); - arguments.put("a",19d); - double result=gbdt.evaluate(arguments).asDouble(); + MapContext arguments = new MapContext(); + arguments.put("a.b", 1d); + arguments.put("a.b.c", 0.1d); + arguments.put("a.c", 0.01d); + arguments.put("a", 19d); + double result = gbdt.evaluate(arguments).asDouble(); // Optimized evaluation - ArrayContext fArguments=new ArrayContext(gbdt); - OptimizationReport report=new OptimizationReport(); - new GBDTOptimizer().optimize(gbdt,fArguments,report); - assertEquals("Optimization result is as expected:\n" + report,1,report.getMetric("Optimized GDBT trees")); - fArguments.put("a.b",1d); - fArguments.put("a.b.c",0.1d); - fArguments.put("a.c",0.01d); - fArguments.put("a",19d); - double oResult=gbdt.evaluate(fArguments).asDouble(); + ArrayContext fArguments = new ArrayContext(gbdt); + OptimizationReport report = new OptimizationReport(); + new GBDTOptimizer().optimize(gbdt, fArguments, report); + assertEquals("Optimization result is as expected:\n" + report, 1, report.getMetric("Optimized GDBT trees")); + fArguments.put("a.b", 1d); + fArguments.put("a.b.c", 0.1d); + fArguments.put("a.c", 0.01d); + fArguments.put("a", 19d); + double oResult = gbdt.evaluate(fArguments).asDouble(); // Assert the same results are produced - assertEquals(result,oResult); + assertEquals(result, oResult, delta); } + @Test public void testBug4009433() throws ParseException { RankingExpression exp = new RankingExpression("10*if(two>35,if(two>one,if(two>=670,4,8),if(two>8000,5,3)),if(two==478,90,91))"); new GBDTOptimizer().optimize(exp, new ArrayContext(exp), new OptimizationReport()); diff --git a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/integration/tensorflow/DimensionRenamerTest.java b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/integration/tensorflow/DimensionRenamerTest.java index ebcfde54c70..74b0d11f1d6 100644 --- a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/integration/tensorflow/DimensionRenamerTest.java +++ b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/integration/tensorflow/DimensionRenamerTest.java @@ -3,7 +3,7 @@ package com.yahoo.searchlib.rankingexpression.integration.tensorflow; import com.yahoo.searchlib.rankingexpression.integration.tensorflow.importer.DimensionRenamer; import org.junit.Test; -import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertTrue; public class DimensionRenamerTest { @@ -43,7 +43,6 @@ public class DimensionRenamerTest { assertTrue(secondDimensionOfXName.compareTo(firstDimensionOfWName) == 0); assertTrue(firstDimensionOfXName.compareTo(secondDimensionOfWName) < 0); assertTrue(secondDimensionOfWName.compareTo(firstDimensionOfBName) == 0); - - } + } diff --git a/searchlib/src/test/java/com/yahoo/searchlib/treenet/TreeNetParserTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/treenet/TreeNetParserTestCase.java index cd7643b9f74..5f48109d4c6 100755 --- a/searchlib/src/test/java/com/yahoo/searchlib/treenet/TreeNetParserTestCase.java +++ b/searchlib/src/test/java/com/yahoo/searchlib/treenet/TreeNetParserTestCase.java @@ -4,17 +4,24 @@ package com.yahoo.searchlib.treenet; import com.yahoo.searchlib.rankingexpression.RankingExpression; import com.yahoo.searchlib.treenet.parser.ParseException; import com.yahoo.searchlib.treenet.parser.TreeNetParser; -import junit.framework.TestCase; +import org.junit.Test; -import java.io.*; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.StringReader; + +import static org.junit.Assert.assertEquals; /** - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ -public class TreeNetParserTestCase extends TestCase { +public class TreeNetParserTestCase { private static final boolean WRITE_FILES = false; + @Test public void testRankingExpression() { for (int i = 1; i <= 8; ++i) { String inputFile = String.format("src/test/files/treenet%02d.model", i); @@ -76,4 +83,5 @@ public class TreeNetParserTestCase extends TestCase { throw new AssertionError(e); } } + } diff --git a/statistics/src/test/java/com/yahoo/statistics/CounterGroupTestCase.java b/statistics/src/test/java/com/yahoo/statistics/CounterGroupTestCase.java index 91a19605286..b452c6eb204 100644 --- a/statistics/src/test/java/com/yahoo/statistics/CounterGroupTestCase.java +++ b/statistics/src/test/java/com/yahoo/statistics/CounterGroupTestCase.java @@ -8,13 +8,18 @@ import java.util.logging.LogRecord; import java.util.logging.Logger; import com.yahoo.container.StatisticsConfig; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; /** * Test set for groups of counters. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ -public class CounterGroupTestCase extends junit.framework.TestCase { +public class CounterGroupTestCase { + private volatile boolean gotRecord = false; private class CounterGroupHandler extends Handler { @@ -40,6 +45,7 @@ public class CounterGroupTestCase extends junit.framework.TestCase { } } + @Test public void testBasic() { Logger logger = Logger.getLogger(CounterGroup.class.getName()); boolean initUseParentHandlers = logger.getUseParentHandlers(); @@ -64,6 +70,7 @@ public class CounterGroupTestCase extends junit.framework.TestCase { logger.setUseParentHandlers(initUseParentHandlers); } + @Test public void testObjectContracts() { CounterGroup c = new CounterGroup("test", Statistics.nullImplementation, false); CounterGroup c2 = new CounterGroup("test", Statistics.nullImplementation, false); @@ -77,6 +84,7 @@ public class CounterGroupTestCase extends junit.framework.TestCase { c.equals(c2)); } + @Test public void testConfigStuff() { Logger logger = Logger.getLogger(CounterGroup.class.getName()); boolean initUseParentHandlers = logger.getUseParentHandlers(); diff --git a/statistics/src/test/java/com/yahoo/statistics/CounterTestCase.java b/statistics/src/test/java/com/yahoo/statistics/CounterTestCase.java index 56258f60fc7..b33586a6428 100644 --- a/statistics/src/test/java/com/yahoo/statistics/CounterTestCase.java +++ b/statistics/src/test/java/com/yahoo/statistics/CounterTestCase.java @@ -1,20 +1,24 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.statistics; - import java.util.Arrays; import java.util.logging.Logger; import com.yahoo.container.StatisticsConfig; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; /** * Check counters work. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ -public class CounterTestCase extends junit.framework.TestCase { +public class CounterTestCase { + @Test public void testBasic() { Counter c = new Counter("test", Statistics.nullImplementation, false); c.increment(); @@ -32,6 +36,7 @@ public class CounterTestCase extends junit.framework.TestCase { assertEquals(0, c.get()); } + @Test public void testObjectContracts() { final String counterName = "test"; Counter c = new Counter(counterName, Statistics.nullImplementation, false); @@ -51,6 +56,7 @@ public class CounterTestCase extends junit.framework.TestCase { assertEquals(prefix, image.substring(0, prefix.length())); } + @Test public void testConfigStuff() { Logger logger = Logger.getLogger(Counter.class.getName()); boolean initUseParentHandlers = logger.getUseParentHandlers(); diff --git a/statistics/src/test/java/com/yahoo/statistics/HistogramTestCase.java b/statistics/src/test/java/com/yahoo/statistics/HistogramTestCase.java index 3d1edf8616b..6b970220b74 100644 --- a/statistics/src/test/java/com/yahoo/statistics/HistogramTestCase.java +++ b/statistics/src/test/java/com/yahoo/statistics/HistogramTestCase.java @@ -2,20 +2,20 @@ package com.yahoo.statistics; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** * Some low level checking of the histograms. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ -public class HistogramTestCase extends junit.framework.TestCase { - - public HistogramTestCase(String name) { - super(name); - } +public class HistogramTestCase { + @Test public void testFindBucket() { Limits l = new Limits(); double[] thresholds = {.5, 1.0, 5.0}; @@ -32,6 +32,7 @@ public class HistogramTestCase extends junit.framework.TestCase { } + @Test public void testMerge() { Limits l = new Limits(); double[] thresholds = {.5, 1.0, 5.0}; @@ -46,6 +47,7 @@ public class HistogramTestCase extends junit.framework.TestCase { assertEquals("(0) < 0.5 (3) < 1.0 (0) < 5.0 (0)", h2.toString()); } + @Test public void testMultiDimensionalMerge() { Limits l = new Limits(); double[] thresholds = {.5, 1.0, 5.0}; @@ -63,6 +65,7 @@ public class HistogramTestCase extends junit.framework.TestCase { h.toString()); } + @Test public void testEmptyHistogram() { try { new Histogram(new Limits()); diff --git a/statistics/src/test/java/com/yahoo/statistics/ValueGroupTestCase.java b/statistics/src/test/java/com/yahoo/statistics/ValueGroupTestCase.java index eabfb61acd3..b92182c3534 100644 --- a/statistics/src/test/java/com/yahoo/statistics/ValueGroupTestCase.java +++ b/statistics/src/test/java/com/yahoo/statistics/ValueGroupTestCase.java @@ -7,13 +7,19 @@ import java.util.logging.LogRecord; import java.util.logging.Logger; import com.yahoo.container.StatisticsConfig; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * Test set for groups of values. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ -public class ValueGroupTestCase extends junit.framework.TestCase { +public class ValueGroupTestCase { + private volatile boolean gotRecord = false; private class ValueGroupHandler extends Handler { @@ -39,6 +45,7 @@ public class ValueGroupTestCase extends junit.framework.TestCase { } } + @Test public void testBasic() { Logger logger = Logger.getLogger(ValueGroup.class.getName()); boolean initUseParentHandlers = logger.getUseParentHandlers(); @@ -64,6 +71,7 @@ public class ValueGroupTestCase extends junit.framework.TestCase { logger.setUseParentHandlers(initUseParentHandlers); } + @Test public void testOverlappingSubnames() { final MockStatistics manager = new MockStatistics(); ValueGroup v = new ValueGroup("jappe", manager); @@ -76,6 +84,7 @@ public class ValueGroupTestCase extends junit.framework.TestCase { assertEquals(2, manager.registerCount); } + @Test public void testObjectContracts() { ValueGroup v = new ValueGroup("test", new MockStatistics()); ValueGroup v2 = new ValueGroup("test", new MockStatistics()); diff --git a/statistics/src/test/java/com/yahoo/statistics/ValueTestCase.java b/statistics/src/test/java/com/yahoo/statistics/ValueTestCase.java index 2804442a982..5650d8125b6 100644 --- a/statistics/src/test/java/com/yahoo/statistics/ValueTestCase.java +++ b/statistics/src/test/java/com/yahoo/statistics/ValueTestCase.java @@ -9,14 +9,22 @@ import java.util.logging.Logger; import com.yahoo.container.StatisticsConfig; import static com.yahoo.container.StatisticsConfig.Values.Operations; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import com.yahoo.statistics.Value.Parameters; +import org.junit.Test; /** * Check correct statistics are generated for basic values. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ -public class ValueTestCase extends junit.framework.TestCase { +public class ValueTestCase { + + private static final double delta = 0.0000000001; private static final String NALLE = "nalle"; private static final double SECOND = 43.0d; @@ -36,6 +44,7 @@ public class ValueTestCase extends junit.framework.TestCase { } + @Test public void testMean() { Value v = new Value("thingie", Statistics.nullImplementation, new Parameters().setLogMean(true)); v.put(1.0); @@ -48,6 +57,7 @@ public class ValueTestCase extends junit.framework.TestCase { assertTrue("Value should have been reset.", 0.0d == v.getMean()); } + @Test public void testMin() { Value v = new Value("thingie", Statistics.nullImplementation, new Parameters().setLogMin(true)); v.put(2.0); @@ -59,6 +69,7 @@ public class ValueTestCase extends junit.framework.TestCase { assertTrue("Min should be -1.0", -1.0 == v.getMin()); } + @Test public void testMax() { Value v = new Value("thingie", Statistics.nullImplementation, new Parameters().setLogMax(true)); v.put(-1.0); @@ -71,6 +82,7 @@ public class ValueTestCase extends junit.framework.TestCase { assertTrue("Max should be 4.0", 4.0 == v.getMax()); } + @Test public void testHistogram() { Value v = new Value("thingie", Statistics.nullImplementation, new Parameters() .setLogHistogram(true).setHistogramId(HistogramType.REGULAR) @@ -84,6 +96,7 @@ public class ValueTestCase extends junit.framework.TestCase { " thingie (1) < 0.0 (1) < 1.0 (1) < 2.0 (2)")); } + @Test public void testCallback() { Logger logger = Logger.getLogger(Value.class.getName()); boolean initUseParentHandlers = logger.getUseParentHandlers(); @@ -91,14 +104,15 @@ public class ValueTestCase extends junit.framework.TestCase { Value v = new Value("thingie", Statistics.nullImplementation, new Parameters() .setLogRaw(true).setCallback(new TrivialCallback())); v.run(); - assertEquals(FIRST, v.get()); + assertEquals(FIRST, v.get(), delta); v.run(); - assertEquals(SECOND, v.get()); + assertEquals(SECOND, v.get(), delta); v.run(); - assertEquals(SECOND, v.get()); + assertEquals(SECOND, v.get(), delta); logger.setUseParentHandlers(initUseParentHandlers); } + @Test public void testParameter() { Value.Parameters p = new Value.Parameters().setLogInsertions(true) .setNameExtension(true).setAppendChar('_'); @@ -148,6 +162,7 @@ public class ValueTestCase extends junit.framework.TestCase { } } + @Test public void testParameterFromConfig() { Logger logger = Logger.getLogger(Value.class.getName()); boolean initUseParentHandlers = logger.getUseParentHandlers(); @@ -173,13 +188,14 @@ public class ValueTestCase extends junit.framework.TestCase { Value v = Value.buildValue(NALLE, m, null); final double x = 79.0d; v.put(x); - assertEquals(x, v.getMean()); + assertEquals(x, v.getMean(), delta); v.run(); assertEquals(true, h.gotRecord); logger.removeHandler(h); logger.setUseParentHandlers(initUseParentHandlers); } + @Test public void testReverseHistogram() { Logger logger = Logger.getLogger(Value.class.getName()); boolean initUseParentHandlers = logger.getUseParentHandlers(); @@ -209,6 +225,7 @@ public class ValueTestCase extends junit.framework.TestCase { logger.setUseParentHandlers(initUseParentHandlers); } + @Test public void testCumulativeHistogram() { Logger logger = Logger.getLogger(Value.class.getName()); boolean initUseParentHandlers = logger.getUseParentHandlers(); @@ -238,6 +255,7 @@ public class ValueTestCase extends junit.framework.TestCase { logger.setUseParentHandlers(initUseParentHandlers); } + @Test public void testObjectContracts() { final String valueName = "test"; Value v = new Value(valueName, Statistics.nullImplementation, Value.defaultParameters()); @@ -256,7 +274,6 @@ public class ValueTestCase extends junit.framework.TestCase { assertEquals(valueName, image.substring(image.length() - valueName.length())); } - public class MockStatistics implements Statistics { public StatisticsConfig config = null; public int registerCount = 0; diff --git a/vdslib/src/test/java/com/yahoo/vdslib/BucketDistributionTestCase.java b/vdslib/src/test/java/com/yahoo/vdslib/BucketDistributionTestCase.java index 0982a49bee1..5e1d811ade1 100644 --- a/vdslib/src/test/java/com/yahoo/vdslib/BucketDistributionTestCase.java +++ b/vdslib/src/test/java/com/yahoo/vdslib/BucketDistributionTestCase.java @@ -2,18 +2,22 @@ package com.yahoo.vdslib; import com.yahoo.document.BucketId; +import org.junit.Test; import java.util.Random; +import static org.junit.Assert.assertEquals; + /** - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ -public class BucketDistributionTestCase extends junit.framework.TestCase { +public class BucketDistributionTestCase { private static final int NUM_COLUMNS = 16; private static final int MIN_BUCKETBITS = 4; private static final int MAX_BUCKETBITS = 9; + @Test public void printExpected() { System.out.println(" int[][] expected = new int[][] {"); for (int numBucketBits = MIN_BUCKETBITS; numBucketBits <= MAX_BUCKETBITS; ++numBucketBits) { @@ -38,6 +42,7 @@ public class BucketDistributionTestCase extends junit.framework.TestCase { System.out.println(" };"); } + @Test public void testDistribution() { int[][] expected = new int[][] { new int[] { @@ -90,6 +95,7 @@ public class BucketDistributionTestCase extends junit.framework.TestCase { } } + @Test public void testNumBucketBits() { Random rnd = new Random(); @@ -108,4 +114,5 @@ public class BucketDistributionTestCase extends junit.framework.TestCase { assertEquals(0, bd.getColumn(new BucketId(32, (rnd.nextLong() << 16) & i))); } } + } diff --git a/vdslib/src/test/java/com/yahoo/vdslib/DocumentListTestCase.java b/vdslib/src/test/java/com/yahoo/vdslib/DocumentListTestCase.java index 62429f7c300..eaf9e576a5b 100644 --- a/vdslib/src/test/java/com/yahoo/vdslib/DocumentListTestCase.java +++ b/vdslib/src/test/java/com/yahoo/vdslib/DocumentListTestCase.java @@ -3,21 +3,23 @@ package com.yahoo.vdslib; import com.yahoo.document.*; import com.yahoo.document.datatypes.FloatFieldValue; -import com.yahoo.document.datatypes.IntegerFieldValue; import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.document.serialization.DocumentSerializer; import com.yahoo.document.serialization.DocumentSerializerFactory; import com.yahoo.document.update.FieldUpdate; +import org.junit.Test; -import java.io.EOFException; -import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.IOException; import java.util.ArrayList; import java.util.List; -public class DocumentListTestCase extends junit.framework.TestCase { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +public class DocumentListTestCase { + + @Test @SuppressWarnings("deprecation") public void testSelfSerializationAndWriteJavaFile() throws Exception { DocumentTypeManager docMan = new DocumentTypeManager(); @@ -34,7 +36,7 @@ public class DocumentListTestCase extends junit.framework.TestCase { DocumentUpdate docUp = new DocumentUpdate(docMan.getDocumentType("benchmark"), new DocumentId("userdoc:foo:99999999:4")); docUp.addFieldUpdate(FieldUpdate.createAssign(docUp.getType().getField("bodystring"), new StringFieldValue("ballooooo"))); - List<Entry> entries = new ArrayList<Entry>(); + List<Entry> entries = new ArrayList<>(); entries.add(Entry.create(put1)); entries.add(Entry.create(doc2)); entries.add(Entry.create(put3)); @@ -92,6 +94,7 @@ public class DocumentListTestCase extends junit.framework.TestCase { assertEquals(new StringFieldValue("ballooooo"),((DocumentUpdate) entry4.getDocumentOperation()).getFieldUpdate(0).getValueUpdate(0).getValue()); } + @Test public void testContains() { DocumentTypeManager manager = new DocumentTypeManager(); DocumentTypeManagerConfigurer.configure(manager, "file:src/test/files/documentmanager.cfg"); @@ -119,17 +122,17 @@ public class DocumentListTestCase extends junit.framework.TestCase { DocumentList documentList2 = DocumentList.create(entries2); - assert(documentList.containsAll(documentList2)); + assertTrue(documentList.containsAll(documentList2)); Long t = put4.getDocument().getLastModified(); put4.getDocument().setLastModified(13L); - assert(!documentList.containsAll(documentList2)); + assertTrue(!documentList.containsAll(documentList2)); put4.getDocument().setLastModified(t); assert(documentList.containsAll(documentList2)); entries.remove(2); - assert(!documentList.containsAll(documentList2)); - + assertTrue(!documentList.containsAll(documentList2)); } + } diff --git a/vdslib/src/test/java/com/yahoo/vdslib/EntryTestCase.java b/vdslib/src/test/java/com/yahoo/vdslib/EntryTestCase.java index 0f650185d69..ccce2ffcbb7 100644 --- a/vdslib/src/test/java/com/yahoo/vdslib/EntryTestCase.java +++ b/vdslib/src/test/java/com/yahoo/vdslib/EntryTestCase.java @@ -1,17 +1,20 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vdslib; -import com.yahoo.document.Document; import com.yahoo.document.DocumentPut; import com.yahoo.document.DocumentType; import com.yahoo.document.DocumentTypeManager; import com.yahoo.document.DocumentTypeManagerConfigurer; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; /** * @author banino */ -public class EntryTestCase extends junit.framework.TestCase{ +public class EntryTestCase { + @Test public void testEquals() { DocumentTypeManager manager = new DocumentTypeManager(); DocumentTypeManagerConfigurer.configure(manager, "file:src/test/files/documentmanager.cfg"); @@ -22,13 +25,13 @@ public class EntryTestCase extends junit.framework.TestCase{ Entry entry1 = Entry.create(put1); Entry entry2 = Entry.create(put1); - assert(entry1.equals(entry2)); + assertTrue(entry1.equals(entry2)); Entry entry3 = Entry.create(put2); - assert(!entry1.equals(entry3)); - + assertTrue(!entry1.equals(entry3)); } + @Test public void testHashCode() { DocumentTypeManager manager = new DocumentTypeManager(); DocumentTypeManagerConfigurer.configure(manager, "file:src/test/files/documentmanager.cfg"); @@ -39,13 +42,10 @@ public class EntryTestCase extends junit.framework.TestCase{ Entry entry1 = Entry.create(put1); Entry entry2 = Entry.create(put1); - assert(entry1.hashCode() == entry2.hashCode()); + assertTrue(entry1.hashCode() == entry2.hashCode()); Entry entry3 = Entry.create(put2); - assert(entry1.hashCode() != entry3.hashCode()); - + assertTrue(entry1.hashCode() != entry3.hashCode()); } - - } |