diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-04-27 13:35:40 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-04-27 13:35:40 +0200 |
commit | d12f069567a99536c84598700ad4f00048936cde (patch) | |
tree | 61f04cddb5fe535694835497620cfdeb26a82dbf /documentapi | |
parent | d83814043998817d404b922e3050ce2006e8ec19 (diff) |
Remove usage of junit.framework
Diffstat (limited to 'documentapi')
10 files changed, 144 insertions, 79 deletions
diff --git a/documentapi/src/test/java/com/yahoo/documentapi/VisitorIteratorTestCase.java b/documentapi/src/test/java/com/yahoo/documentapi/VisitorIteratorTestCase.java index bcebcc1e22d..f71b13191f9 100755 --- a/documentapi/src/test/java/com/yahoo/documentapi/VisitorIteratorTestCase.java +++ b/documentapi/src/test/java/com/yahoo/documentapi/VisitorIteratorTestCase.java @@ -2,11 +2,9 @@ package com.yahoo.documentapi; import com.yahoo.document.select.parser.ParseException; -import com.yahoo.documentapi.ProgressToken; -import com.yahoo.documentapi.VisitorIterator; -import junit.framework.TestCase; import com.yahoo.document.BucketId; import com.yahoo.document.BucketIdFactory; +import org.junit.Test; import java.util.Arrays; import java.util.Map; @@ -14,13 +12,19 @@ import java.util.Set; import java.util.TreeSet; import java.util.Vector; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * Tests for VisitorIterator and ProgressToken (kept in one test case because their * interactions are so tightly coupled) - * @author <a href="mailto:vekterli@yahoo-inc.com">Tor Brede Vekterli</a> + * + * @author vekterli */ -public class VisitorIteratorTestCase extends TestCase { +public class VisitorIteratorTestCase { + @Test public void testIterationSingleBucketUpdate() throws ParseException { BucketIdFactory idFactory = new BucketIdFactory(); ProgressToken progress = new ProgressToken(); @@ -72,6 +76,7 @@ public class VisitorIteratorTestCase extends TestCase { assertEquals(iter.getRemainingBucketCount(), 0); } + @Test public void testProgressSerializationRange() throws ParseException { int distBits = 4; @@ -256,6 +261,7 @@ public class VisitorIteratorTestCase extends TestCase { assertEquals(progress.toString(), finished.toString()); } + @Test public void testProgressSerializationExplicit() throws ParseException { int distBits = 16; @@ -409,8 +415,8 @@ public class VisitorIteratorTestCase extends TestCase { /** * Test that doing update() on a bucket several times in a row (without re-fetching * from getNext first) works - * @throws ParseException */ + @Test public void testActiveUpdate() throws ParseException { BucketIdFactory idFactory = new BucketIdFactory(); ProgressToken progress = new ProgressToken(); @@ -443,8 +449,8 @@ public class VisitorIteratorTestCase extends TestCase { /** * Test that ensures doing update(superbucket, 0) simply puts the bucket back in * pending - * @throws ParseException */ + @Test public void testNullAndSuperUpdate() throws ParseException { BucketIdFactory idFactory = new BucketIdFactory(); ProgressToken progress = new ProgressToken(); @@ -491,6 +497,7 @@ public class VisitorIteratorTestCase extends TestCase { assertEquals(progress.getActiveBucketCount(), 1); } + @Test public void testDeserializedFinishedProgress() { StringBuilder finished = new StringBuilder(); finished.append("VDS bucket progress file\n"); // legacy; no completion percentage @@ -518,6 +525,7 @@ public class VisitorIteratorTestCase extends TestCase { assertTrue(token2.isFinished()); } + @Test public void testBucketProgressFraction() { double epsilon = 0.00001; // No progress @@ -553,6 +561,7 @@ public class VisitorIteratorTestCase extends TestCase { new BucketId(0xb0000fff00000000L)), 1.0, epsilon); } + @Test public void testProgressEstimation() throws ParseException { int distBits = 4; @@ -606,6 +615,7 @@ public class VisitorIteratorTestCase extends TestCase { assertEquals(progress.percentFinished(), 100, epsilon); } + @Test public void testBucketKeyWrapperOrdering() { ProgressToken.BucketKeyWrapper bk1 = new ProgressToken.BucketKeyWrapper(0x0000000000000001L); ProgressToken.BucketKeyWrapper bk2 = new ProgressToken.BucketKeyWrapper(0x7FFFFFFFFFFFFFFFL); @@ -648,6 +658,7 @@ public class VisitorIteratorTestCase extends TestCase { assertTrue(consistentKeys); } + @Test public void testBucketKeyGeneration() { // Due to the number of objects needed to be allocated, only test for a // small set of distribution bits @@ -656,6 +667,7 @@ public class VisitorIteratorTestCase extends TestCase { } } + @Test public void testSingleBucketSplits() throws ParseException { int db = 2; BucketIdFactory idFactory = new BucketIdFactory(); @@ -716,6 +728,7 @@ public class VisitorIteratorTestCase extends TestCase { * source with no finished, active or pending buckets * @throws ParseException upon docsel parse failure (shouldn't happen) */ + @Test public void testRangeDistributionBitIncrease1NoPending() throws ParseException { int db = 2; BucketIdFactory idFactory = new BucketIdFactory(); @@ -739,6 +752,7 @@ public class VisitorIteratorTestCase extends TestCase { } } + @Test public void testRangeDistributionBitIncrease1AllBucketStates() throws ParseException { int db = 3; BucketIdFactory idFactory = new BucketIdFactory(); @@ -793,6 +807,7 @@ public class VisitorIteratorTestCase extends TestCase { // Assume correct from here on } + @Test public void testRangeDistributionIncreaseMultipleBits() throws ParseException { int db = 16; BucketIdFactory idFactory = new BucketIdFactory(); @@ -854,6 +869,7 @@ public class VisitorIteratorTestCase extends TestCase { assertEquals(iter.getNext().getSuperbucket(), new BucketId(20, 0x6000)); } + @Test public void testSingleBucketMerge() throws ParseException { int db = 2; BucketIdFactory idFactory = new BucketIdFactory(); @@ -875,6 +891,7 @@ public class VisitorIteratorTestCase extends TestCase { assertEquals(bp.getSuperbucket(), new BucketId(db, 0)); } + @Test public void testRangeDistributionBitDecrease1() throws ParseException { int db = 16; BucketIdFactory idFactory = new BucketIdFactory(); @@ -931,6 +948,7 @@ public class VisitorIteratorTestCase extends TestCase { // Test that splitting and merging from and to the same db count gives // back the initial state + @Test public void testRangeDistributionBitIncreaseDecrease() throws ParseException { int db = 16; BucketIdFactory idFactory = new BucketIdFactory(); @@ -974,6 +992,7 @@ public class VisitorIteratorTestCase extends TestCase { // Test that intermittent changes in distribution are handled properly, e.g. // changing from 11 -> 9 with X active and then before all those are flushed, // the distribution goes up to 12 + @Test public void testRangeDistributionBitChangeWithoutDone() throws ParseException { int db = 11; BucketIdFactory idFactory = new BucketIdFactory(); @@ -1042,6 +1061,7 @@ public class VisitorIteratorTestCase extends TestCase { } // Test a drop from 31->11 bits upon iteration start + @Test public void testRangeDistributionBitInitialDrop() throws ParseException { int db = 31; BucketIdFactory idFactory = new BucketIdFactory(); @@ -1084,6 +1104,7 @@ public class VisitorIteratorTestCase extends TestCase { // Similar to testRangeDistributionBitInitialDrop, but going from 1 to 11 // This tests that doing so may be done in an optimized way rather than // attempting to split enough buckets to cover the entire bucket space! + @Test public void testRangeDistributionLosslessReset() throws ParseException { int db = 1; BucketIdFactory idFactory = new BucketIdFactory(); @@ -1151,6 +1172,7 @@ public class VisitorIteratorTestCase extends TestCase { assertEquals(bp[0].getSuperbucket(), new BucketId(11, 0)); } + @Test public void testExplicitDistributionBitIncrease() throws ParseException { int distBits = 12; @@ -1176,6 +1198,7 @@ public class VisitorIteratorTestCase extends TestCase { assertEquals(p.getTotalBucketCount(), 3); } + @Test public void testExplicitDistributionBitDecrease() throws ParseException { int distBits = 20; @@ -1201,6 +1224,7 @@ public class VisitorIteratorTestCase extends TestCase { assertEquals(p.getTotalBucketCount(), 3); } + @Test public void testExplicitDistributionImportNoTruncation() throws ParseException { BucketIdFactory idFactory = new BucketIdFactory(); ProgressToken p = new ProgressToken(); @@ -1227,6 +1251,7 @@ public class VisitorIteratorTestCase extends TestCase { assertEquals(3, p2.getTotalBucketCount()); } + @Test public void testImportProgressWithOutdatedDistribution() throws ParseException { String input = "VDS bucket progress file\n" + "10\n" + @@ -1266,6 +1291,7 @@ public class VisitorIteratorTestCase extends TestCase { assertEquals(p2.getBucketCursor(), 503 << 2); } + @Test public void testImportInconsistentProgressIncrease() throws ParseException { // Bucket progress "file" that upon time of changing from 4 to 7 // distribution bits and writing the progress had an active bucket @@ -1311,6 +1337,7 @@ public class VisitorIteratorTestCase extends TestCase { assertTrue(iter.hasNext()); } + @Test public void testImportInconsistentProgressDecrease() throws ParseException { // Bucket progress "file" that upon time of changing from 4 to 7 // distribution bits and writing the progress had an active bucket @@ -1342,6 +1369,7 @@ public class VisitorIteratorTestCase extends TestCase { assertTrue(iter.hasNext()); } + @Test public void testEntireBucketSpaceCovered() throws ParseException { int db = 4; BucketIdFactory idFactory = new BucketIdFactory(); @@ -1382,6 +1410,7 @@ public class VisitorIteratorTestCase extends TestCase { assertTrue(buckets.isEmpty()); } + @Test public void testExceptionOnWrongDocumentSelection() throws ParseException { BucketIdFactory idFactory = new BucketIdFactory(); // Since we don't store the actual original document selection in the @@ -1423,6 +1452,7 @@ public class VisitorIteratorTestCase extends TestCase { assertTrue(caughtIt); } + @Test public void testIsBucketFinished() throws ParseException { BucketIdFactory idFactory = new BucketIdFactory(); ProgressToken p = new ProgressToken(); @@ -1449,6 +1479,7 @@ public class VisitorIteratorTestCase extends TestCase { // Test that altering distribution bit count sets ProgressToken as // inconsistent when there are active buckets + @Test public void testInconsistentState() throws ParseException { int db = 16; BucketIdFactory idFactory = new BucketIdFactory(); @@ -1479,6 +1510,7 @@ public class VisitorIteratorTestCase extends TestCase { assertFalse(p.isInconsistentState()); } + @Test public void testMalformedProgressFile() { boolean caughtIt = false; try { @@ -1495,6 +1527,7 @@ public class VisitorIteratorTestCase extends TestCase { assertTrue(caughtIt); } + @Test public void testFailOnTooFewLinesInFile() { boolean caughtIt = false; try { @@ -1507,6 +1540,7 @@ public class VisitorIteratorTestCase extends TestCase { assertTrue(caughtIt); } + @Test public void testUnknownFirstHeaderLine() { boolean caughtIt = false; try { @@ -1523,6 +1557,7 @@ public class VisitorIteratorTestCase extends TestCase { assertTrue(caughtIt); } + @Test public void testBinaryProgressSerialization() { String input = "VDS bucket progress file (48.828125% completed)\n" + "10\n" + @@ -1537,4 +1572,5 @@ public class VisitorIteratorTestCase extends TestCase { ProgressToken p2 = new ProgressToken(buf); assertEquals(input, p2.toString()); } - } + +} diff --git a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/loadtypes/test/LoadTypesTestCase.java b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/loadtypes/test/LoadTypesTestCase.java index d9d43ffef53..81dbb483366 100644 --- a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/loadtypes/test/LoadTypesTestCase.java +++ b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/loadtypes/test/LoadTypesTestCase.java @@ -2,12 +2,16 @@ package com.yahoo.documentapi.messagebus.loadtypes.test; import com.yahoo.documentapi.messagebus.loadtypes.LoadTypeSet; -import junit.framework.TestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * @author thomasg */ -public class LoadTypesTestCase extends TestCase { +public class LoadTypesTestCase { + + @Test public void testIdGeneration() { LoadTypeSet set = new LoadTypeSet(); set.addType("vespagrim", "VERY_HIGH"); @@ -21,4 +25,5 @@ public class LoadTypesTestCase extends TestCase { assertEquals(0xc21803d4, set.getNameMap().get("vespagrim").getId()); } + } diff --git a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/PolicyFactoryTestCase.java b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/PolicyFactoryTestCase.java index 8ad350924d2..a32d6022fef 100755 --- a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/PolicyFactoryTestCase.java +++ b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/PolicyFactoryTestCase.java @@ -16,25 +16,24 @@ import com.yahoo.messagebus.network.rpc.test.TestServer; import com.yahoo.messagebus.routing.Route; import com.yahoo.messagebus.routing.RoutingContext; import com.yahoo.messagebus.test.Receptor; -import com.yahoo.text.Utf8Array; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +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 PolicyFactoryTestCase extends TestCase { - - //////////////////////////////////////////////////////////////////////////////// - // - // Setup - // - //////////////////////////////////////////////////////////////////////////////// +public class PolicyFactoryTestCase { private Slobrok slobrok; private TestServer srv; private SourceSession src; - @Override + @Before public void setUp() throws ListenFailedException { slobrok = new Slobrok(); srv = new TestServer(new MessageBusParams().addProtocol(new DocumentProtocol(new DocumentTypeManager())), @@ -42,19 +41,14 @@ public class PolicyFactoryTestCase extends TestCase { src = srv.mb.createSourceSession(new SourceSessionParams().setReplyHandler(new Receptor())); } - @Override + @After public void tearDown() { slobrok.stop(); src.destroy(); srv.destroy(); } - //////////////////////////////////////////////////////////////////////////////// - // - // Tests - // - //////////////////////////////////////////////////////////////////////////////// - + @Test public void testFactory() { Route route = Route.parse("[MyPolicy]"); assertTrue(src.send(createMessage(), route).isAccepted()); @@ -76,12 +70,6 @@ public class PolicyFactoryTestCase extends TestCase { assertEquals(DocumentProtocol.ERROR_POLICY_FAILURE, reply.getError(0).getCode()); } - //////////////////////////////////////////////////////////////////////////////// - // - // Utilities - // - //////////////////////////////////////////////////////////////////////////////// - private static Message createMessage() { Message msg = new RemoveDocumentMessage(new DocumentId("doc:scheme:")); msg.getTrace().setLevel(9); @@ -121,4 +109,5 @@ public class PolicyFactoryTestCase extends TestCase { return null; } } + } diff --git a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/PolicyTestFrame.java b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/PolicyTestFrame.java index 5b3d85bfd76..d77f5f4e39e 100755 --- a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/PolicyTestFrame.java +++ b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/PolicyTestFrame.java @@ -21,14 +21,19 @@ import com.yahoo.messagebus.test.SimpleReply; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * This is a utility class to allow easier policy test cases. The most important reason to use this is to make sure that * each test uses a "clean" mbus and slobrok instance. * - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ @SuppressWarnings("deprecation") -public class PolicyTestFrame extends junit.framework.Assert { +public class PolicyTestFrame { private final AtomicBoolean destroyed = new AtomicBoolean(false); private String identity; @@ -383,4 +388,5 @@ public class PolicyTestFrame extends junit.framework.Assert { return ret; } } + } diff --git a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/RoutableFactoryTestCase.java b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/RoutableFactoryTestCase.java index 54334c28e70..a01787004c9 100755 --- a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/RoutableFactoryTestCase.java +++ b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/RoutableFactoryTestCase.java @@ -11,24 +11,33 @@ import com.yahoo.documentapi.messagebus.protocol.DocumentReply; import com.yahoo.documentapi.messagebus.protocol.RoutableFactories50; import com.yahoo.jrt.ListenFailedException; import com.yahoo.jrt.slobrok.server.Slobrok; -import com.yahoo.messagebus.*; +import com.yahoo.messagebus.DestinationSession; +import com.yahoo.messagebus.DestinationSessionParams; +import com.yahoo.messagebus.ErrorCode; +import com.yahoo.messagebus.Message; +import com.yahoo.messagebus.MessageBusParams; +import com.yahoo.messagebus.Reply; +import com.yahoo.messagebus.SourceSession; +import com.yahoo.messagebus.SourceSessionParams; import com.yahoo.messagebus.network.Identity; import com.yahoo.messagebus.network.rpc.RPCNetworkParams; import com.yahoo.messagebus.network.rpc.test.TestServer; import com.yahoo.messagebus.routing.Route; import com.yahoo.messagebus.test.Receptor; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; /** - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ -public class RoutableFactoryTestCase extends TestCase { - - //////////////////////////////////////////////////////////////////////////////// - // - // Setup - // - //////////////////////////////////////////////////////////////////////////////// +public class RoutableFactoryTestCase { private Slobrok slobrok; private DocumentProtocol srcProtocol, dstProtocol; @@ -36,7 +45,7 @@ public class RoutableFactoryTestCase extends TestCase { private SourceSession srcSession; private DestinationSession dstSession; - @Override + @Before public void setUp() throws ListenFailedException { slobrok = new Slobrok(); DocumentTypeManager docMan = new DocumentTypeManager(); @@ -51,7 +60,7 @@ public class RoutableFactoryTestCase extends TestCase { assertTrue(srcServer.waitSlobrok("dst/session", 1)); } - @Override + @After public void tearDown() { slobrok.stop(); dstSession.destroy(); @@ -60,12 +69,7 @@ public class RoutableFactoryTestCase extends TestCase { srcServer.destroy(); } - //////////////////////////////////////////////////////////////////////////////// - // - // Tests - // - //////////////////////////////////////////////////////////////////////////////// - + @Test public void testFactory() { Route route = Route.parse("dst/session"); @@ -126,12 +130,6 @@ public class RoutableFactoryTestCase extends TestCase { assertFalse(reply.hasErrors()); } - //////////////////////////////////////////////////////////////////////////////// - // - // Utilities - // - //////////////////////////////////////////////////////////////////////////////// - private static class MyMessageFactory extends RoutableFactories50.DocumentMessageFactory { @Override @@ -185,4 +183,5 @@ public class RoutableFactoryTestCase extends TestCase { super(TYPE); } } + } diff --git a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/storagepolicy/BasicTests.java b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/storagepolicy/BasicTests.java index 25bed1071a6..14d8818bfec 100644 --- a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/storagepolicy/BasicTests.java +++ b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/storagepolicy/BasicTests.java @@ -5,12 +5,18 @@ import com.yahoo.collections.Pair; import com.yahoo.documentapi.messagebus.protocol.WrongDistributionReply; import com.yahoo.messagebus.Reply; import com.yahoo.messagebus.routing.RoutingNode; +import org.junit.Test; import java.util.Arrays; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + public class BasicTests extends StoragePolicyTestEnvironment { /** Test that we can send a message through the policy. */ + @Test public void testNormalUsage() { setClusterNodes(new int[]{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); // First we want a wrong distribution reply, so make sure we don't try correct node on random @@ -22,6 +28,7 @@ public class BasicTests extends StoragePolicyTestEnvironment { } /** Test that we can identify newest cluster state and hang on to correct one. */ + @Test public void testRepliesWrongOrderDuringStateChange() throws Exception{ { setClusterNodes(new int[]{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); @@ -47,6 +54,7 @@ public class BasicTests extends StoragePolicyTestEnvironment { * bucket 1, which we will be using in the tests. To avoid doing this ahead of every test, we still hardcode the * values, though only one place, and have this test to verify they are correct, and make it easy to update the values. */ + @Test public void testVerifyBucketOneNodePreferenceInTenNodeDefaultCluster() { int result[] = new int[10]; setClusterNodes(new int[]{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); diff --git a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/storagepolicy/Simulator.java b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/storagepolicy/Simulator.java index 8d8fa917af4..10183471ffd 100644 --- a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/storagepolicy/Simulator.java +++ b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/storagepolicy/Simulator.java @@ -14,6 +14,9 @@ import java.util.Map; import java.util.TreeMap; import java.util.regex.Pattern; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + public abstract class Simulator extends StoragePolicyTestEnvironment { enum FailureType { diff --git a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/storagepolicy/StoragePolicyTestEnvironment.java b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/storagepolicy/StoragePolicyTestEnvironment.java index a1fc630588e..b2a137abc7d 100644 --- a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/storagepolicy/StoragePolicyTestEnvironment.java +++ b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/storagepolicy/StoragePolicyTestEnvironment.java @@ -5,7 +5,14 @@ import com.yahoo.collections.Pair; import com.yahoo.document.DocumentId; import com.yahoo.document.DocumentTypeManager; import com.yahoo.document.DocumentTypeManagerConfigurer; -import com.yahoo.documentapi.messagebus.protocol.*; +import com.yahoo.documentapi.messagebus.protocol.AsyncInitializationPolicy; +import com.yahoo.documentapi.messagebus.protocol.DocumentProtocol; +import com.yahoo.documentapi.messagebus.protocol.DocumentProtocolRoutingPolicy; +import com.yahoo.documentapi.messagebus.protocol.ExternalSlobrokPolicy; +import com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage; +import com.yahoo.documentapi.messagebus.protocol.RoutingPolicyFactory; +import com.yahoo.documentapi.messagebus.protocol.StoragePolicy; +import com.yahoo.documentapi.messagebus.protocol.WrongDistributionReply; import com.yahoo.documentapi.messagebus.protocol.test.PolicyTestFrame; import com.yahoo.messagebus.EmptyReply; import com.yahoo.messagebus.Message; @@ -16,18 +23,29 @@ import com.yahoo.messagebus.routing.RoutingNode; import com.yahoo.text.Utf8Array; import com.yahoo.vdslib.distribution.Distribution; import com.yahoo.vdslib.distribution.RandomGen; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; -import java.util.*; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public abstract class StoragePolicyTestEnvironment { -public abstract class StoragePolicyTestEnvironment extends TestCase { protected StoragePolicyTestFactory policyFactory; protected PolicyTestFrame frame; private Set<Integer> nodes; protected static int[] bucketOneNodePreference = new int[]{ 3, 5, 7, 6, 8, 0, 9, 2, 1, 4 }; protected boolean debug = true; - @Override + @Before public void setUp() throws Exception { DocumentTypeManager manager = new DocumentTypeManager(); DocumentTypeManagerConfigurer.configure(manager, "file:./test/cfg/testdoc.cfg"); @@ -40,7 +58,7 @@ public abstract class StoragePolicyTestEnvironment extends TestCase { frame.setHop(new HopSpec("test", "[storage:cluster=foo]")); } - @Override + @After public void tearDown() { frame.destroy(); } @@ -66,6 +84,7 @@ public abstract class StoragePolicyTestEnvironment extends TestCase { cluster = cluster.substring(cluster.indexOf('.') + 1); return new Pair<>(cluster, distributor); } + protected static Pair<String, Integer> getAddress(RoutingNode node) { Pair<String, String> pair = extractClusterAndIndexFromPattern(node.getRoute().getHop(0).toString()); return new Pair<>(pair.getFirst(), Integer.valueOf(pair.getSecond())); diff --git a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/test/ScheduledEventQueueTestCase.java b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/test/ScheduledEventQueueTestCase.java index 312716fc2c4..93146721136 100755 --- a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/test/ScheduledEventQueueTestCase.java +++ b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/test/ScheduledEventQueueTestCase.java @@ -3,12 +3,16 @@ package com.yahoo.documentapi.messagebus.test; import com.yahoo.documentapi.messagebus.ScheduledEventQueue; import com.yahoo.concurrent.Timer; -import junit.framework.TestCase; import org.junit.Test; import java.util.concurrent.RejectedExecutionException; -public class ScheduledEventQueueTestCase extends TestCase { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class ScheduledEventQueueTestCase { class TestTask implements Runnable { public long timestamp = 0; diff --git a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/test/ThroughputLimitQueueTestCase.java b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/test/ThroughputLimitQueueTestCase.java index 5bd3de79ce4..75e98bc895a 100644 --- a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/test/ThroughputLimitQueueTestCase.java +++ b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/test/ThroughputLimitQueueTestCase.java @@ -3,12 +3,15 @@ package com.yahoo.documentapi.messagebus.test; import com.yahoo.documentapi.ThroughputLimitQueue; import com.yahoo.concurrent.Timer; -import junit.framework.TestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * @author thomasg */ -public class ThroughputLimitQueueTestCase extends TestCase { +public class ThroughputLimitQueueTestCase { + class TestTimer implements Timer { public long milliTime = 0; @@ -17,15 +20,7 @@ public class ThroughputLimitQueueTestCase extends TestCase { } } - - public void setUp() { - - } - - public void tearDown() { - - } - + @Test public void testCapacity() { TestTimer t = new TestTimer(); t.milliTime = 10; @@ -50,4 +45,5 @@ public class ThroughputLimitQueueTestCase extends TestCase { assertEquals(20, q.capacity()); } + } |