summaryrefslogtreecommitdiffstats
path: root/messagebus
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-08-11 23:29:08 +0200
committerGitHub <noreply@github.com>2020-08-11 23:29:08 +0200
commit5858a6cdae398b95360c5d031e56037799930895 (patch)
tree737668034aeebf3146b0e2d9229157101c116672 /messagebus
parenta9775442179fd17067cd351051d803920c0d74fc (diff)
Revert "Reduce the use of hamcrest when normal assertEquals/assertTrue does a…"
Diffstat (limited to 'messagebus')
-rw-r--r--messagebus/pom.xml6
-rw-r--r--messagebus/src/test/java/com/yahoo/messagebus/network/local/LocalNetworkTest.java70
2 files changed, 35 insertions, 41 deletions
diff --git a/messagebus/pom.xml b/messagebus/pom.xml
index 9bd123ad6bd..358ce7cc63f 100644
--- a/messagebus/pom.xml
+++ b/messagebus/pom.xml
@@ -20,6 +20,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <version>1.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>com.yahoo.vespa</groupId>
<artifactId>vespajlib</artifactId>
<version>${project.version}</version>
diff --git a/messagebus/src/test/java/com/yahoo/messagebus/network/local/LocalNetworkTest.java b/messagebus/src/test/java/com/yahoo/messagebus/network/local/LocalNetworkTest.java
index aec38e7d157..e2706a66671 100644
--- a/messagebus/src/test/java/com/yahoo/messagebus/network/local/LocalNetworkTest.java
+++ b/messagebus/src/test/java/com/yahoo/messagebus/network/local/LocalNetworkTest.java
@@ -2,23 +2,7 @@
package com.yahoo.messagebus.network.local;
import com.yahoo.concurrent.SystemTimer;
-import com.yahoo.messagebus.DestinationSession;
-import com.yahoo.messagebus.DestinationSessionParams;
-import com.yahoo.messagebus.EmptyReply;
-import com.yahoo.messagebus.ErrorCode;
-import com.yahoo.messagebus.IntermediateSession;
-import com.yahoo.messagebus.IntermediateSessionParams;
-import com.yahoo.messagebus.Message;
-import com.yahoo.messagebus.MessageBus;
-import com.yahoo.messagebus.MessageBusParams;
-import com.yahoo.messagebus.MessageHandler;
-import com.yahoo.messagebus.Reply;
-import com.yahoo.messagebus.ReplyHandler;
-import com.yahoo.messagebus.Result;
-import com.yahoo.messagebus.SourceSession;
-import com.yahoo.messagebus.SourceSessionParams;
-import com.yahoo.messagebus.StaticThrottlePolicy;
-import com.yahoo.messagebus.ThrottlePolicy;
+import com.yahoo.messagebus.*;
import com.yahoo.messagebus.routing.Hop;
import com.yahoo.messagebus.routing.Route;
import com.yahoo.messagebus.test.SimpleMessage;
@@ -30,8 +14,12 @@ import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.number.OrderingComparison.lessThan;
+import static org.hamcrest.number.OrderingComparison.greaterThanOrEqualTo;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/**
@@ -55,28 +43,28 @@ public class LocalNetworkTest {
Message msg = new SimpleMessage("foo");
msg.setRoute(new Route().addHop(Hop.parse(intermediate.getConnectionSpec()))
.addHop(Hop.parse(destination.getConnectionSpec())));
- assertTrue(source.send(msg).isAccepted());
+ assertThat(source.send(msg).isAccepted(), is(true));
msg = serverB.messages.poll(60, TimeUnit.SECONDS);
- assertTrue(msg instanceof SimpleMessage);
- assertEquals("foo", ((SimpleMessage)msg).getValue());
+ assertThat(msg, instanceOf(SimpleMessage.class));
+ assertThat(((SimpleMessage)msg).getValue(), is("foo"));
intermediate.forward(msg);
msg = serverC.messages.poll(60, TimeUnit.SECONDS);
- assertTrue(msg instanceof SimpleMessage);
- assertEquals("foo", ((SimpleMessage)msg).getValue());
+ assertThat(msg, instanceOf(SimpleMessage.class));
+ assertThat(((SimpleMessage)msg).getValue(), is("foo"));
Reply reply = new SimpleReply("bar");
reply.swapState(msg);
destination.reply(reply);
reply = serverB.replies.poll(60, TimeUnit.SECONDS);
- assertTrue(reply instanceof SimpleReply);
- assertEquals("bar", ((SimpleReply)reply).getValue());
+ assertThat(reply, instanceOf(SimpleReply.class));
+ assertThat(((SimpleReply)reply).getValue(), is("bar"));
intermediate.forward(reply);
reply = serverA.replies.poll(60, TimeUnit.SECONDS);
- assertTrue(reply instanceof SimpleReply);
- assertEquals("bar", ((SimpleReply)reply).getValue());
+ assertThat(reply, instanceOf(SimpleReply.class));
+ assertThat(((SimpleReply)reply).getValue(), is("bar"));
serverA.mbus.destroy();
serverB.mbus.destroy();
@@ -89,9 +77,9 @@ public class LocalNetworkTest {
final SourceSession source = server.newSourceSession();
final Message msg = new SimpleMessage("foo").setRoute(Route.parse("bar"));
- assertTrue(source.send(msg).isAccepted());
+ assertThat(source.send(msg).isAccepted(), is(true));
final Reply reply = server.replies.poll(60, TimeUnit.SECONDS);
- assertTrue(reply instanceof EmptyReply);
+ assertThat(reply, instanceOf(EmptyReply.class));
server.mbus.destroy();
}
@@ -112,7 +100,7 @@ public class LocalNetworkTest {
Message msg = new SimpleMessage("foo");
msg.setRoute(new Route().addHop(Hop.parse(intermediate.getConnectionSpec()))
.addHop(Hop.parse(destination.getConnectionSpec())));
- assertTrue(source.sendBlocking(msg).isAccepted());
+ assertThat(source.sendBlocking(msg).isAccepted(), is(true));
long start = SystemTimer.INSTANCE.milliTime();
Message msg2 = new SimpleMessage("foo2");
msg2.setRoute(new Route().addHop(Hop.parse(intermediate.getConnectionSpec()))
@@ -120,28 +108,28 @@ public class LocalNetworkTest {
long TIMEOUT = 1000;
msg2.setTimeRemaining(TIMEOUT);
Result res = source.sendBlocking(msg2);
- assertFalse(res.isAccepted());
+ assertThat(res.isAccepted(), is(false));
assertEquals(ErrorCode.TIMEOUT, res.getError().getCode());
assertTrue(res.getError().getMessage().endsWith("Timed out in sendQ"));
long end = SystemTimer.INSTANCE.milliTime();
- assertTrue(end >= start+TIMEOUT);
- assertTrue(end < start+5*TIMEOUT);
+ assertThat(end, greaterThanOrEqualTo(start+TIMEOUT));
+ assertThat(end, lessThan(start+5*TIMEOUT));
msg = serverB.messages.poll(60, TimeUnit.SECONDS);
- assertTrue(msg instanceof SimpleMessage);
- assertEquals("foo", ((SimpleMessage)msg).getValue());
+ assertThat(msg, instanceOf(SimpleMessage.class));
+ assertThat(((SimpleMessage)msg).getValue(), is("foo"));
intermediate.forward(msg);
msg = serverC.messages.poll(60, TimeUnit.SECONDS);
- assertTrue(msg instanceof SimpleMessage);
- assertEquals("foo", ((SimpleMessage)msg).getValue());
+ assertThat(msg, instanceOf(SimpleMessage.class));
+ assertThat(((SimpleMessage)msg).getValue(), is("foo"));
Reply reply = new SimpleReply("bar");
reply.swapState(msg);
destination.reply(reply);
reply = serverB.replies.poll(60, TimeUnit.SECONDS);
- assertTrue(reply instanceof SimpleReply);
- assertEquals("bar", ((SimpleReply)reply).getValue());
+ assertThat(reply, instanceOf(SimpleReply.class));
+ assertThat(((SimpleReply)reply).getValue(), is("bar"));
intermediate.forward(reply);
reply = serverA.replies.poll(60, TimeUnit.SECONDS);
@@ -149,8 +137,8 @@ public class LocalNetworkTest {
assertTrue(reply.getError(0).getMessage().endsWith("Timed out in sendQ"));
reply = serverA.replies.poll(60, TimeUnit.SECONDS);
- assertTrue(reply instanceof SimpleReply);
- assertEquals("bar", ((SimpleReply)reply).getValue());
+ assertThat(reply, instanceOf(SimpleReply.class));
+ assertThat(((SimpleReply)reply).getValue(), is("bar"));
serverA.mbus.destroy();
serverB.mbus.destroy();