parent
174c725ef8
commit
f568d4d4f9
8 changed files with 48 additions and 38 deletions
|
|
@ -22,6 +22,8 @@ import akka.testkit.EventFilter;
|
|||
import akka.testkit.TestEvent;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static akka.japi.Util.immutableSeq;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import scala.concurrent.Await;
|
||||
|
||||
// #testkit
|
||||
|
|
@ -182,14 +184,14 @@ public class FaultHandlingTest extends AbstractJavaTest {
|
|||
|
||||
// #resume
|
||||
child.tell(42, ActorRef.noSender());
|
||||
assert Await.result(ask(child, "get", 5000), timeout).equals(42);
|
||||
assertEquals(42, Await.result(ask(child, "get", 5000), timeout));
|
||||
child.tell(new ArithmeticException(), ActorRef.noSender());
|
||||
assert Await.result(ask(child, "get", 5000), timeout).equals(42);
|
||||
assertEquals(42, Await.result(ask(child, "get", 5000), timeout));
|
||||
// #resume
|
||||
|
||||
// #restart
|
||||
child.tell(new NullPointerException(), ActorRef.noSender());
|
||||
assert Await.result(ask(child, "get", 5000), timeout).equals(0);
|
||||
assertEquals(0, Await.result(ask(child, "get", 5000), timeout));
|
||||
// #restart
|
||||
|
||||
// #stop
|
||||
|
|
@ -202,7 +204,7 @@ public class FaultHandlingTest extends AbstractJavaTest {
|
|||
// #escalate-kill
|
||||
child = (ActorRef) Await.result(ask(supervisor, Props.create(Child.class), 5000), timeout);
|
||||
probe.watch(child);
|
||||
assert Await.result(ask(child, "get", 5000), timeout).equals(0);
|
||||
assertEquals(0, Await.result(ask(child, "get", 5000), timeout));
|
||||
child.tell(new Exception(), ActorRef.noSender());
|
||||
probe.expectMsgClass(Terminated.class);
|
||||
// #escalate-kill
|
||||
|
|
@ -212,9 +214,9 @@ public class FaultHandlingTest extends AbstractJavaTest {
|
|||
supervisor = system.actorOf(superprops);
|
||||
child = (ActorRef) Await.result(ask(supervisor, Props.create(Child.class), 5000), timeout);
|
||||
child.tell(23, ActorRef.noSender());
|
||||
assert Await.result(ask(child, "get", 5000), timeout).equals(23);
|
||||
assertEquals(23, Await.result(ask(child, "get", 5000), timeout));
|
||||
child.tell(new Exception(), ActorRef.noSender());
|
||||
assert Await.result(ask(child, "get", 5000), timeout).equals(0);
|
||||
assertEquals(0, Await.result(ask(child, "get", 5000), timeout));
|
||||
// #escalate-restart
|
||||
// #testkit
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ package jdocs.duration;
|
|||
// #import
|
||||
import scala.concurrent.duration.Duration;
|
||||
import scala.concurrent.duration.Deadline;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
// #import
|
||||
|
||||
class Java {
|
||||
|
|
@ -15,8 +17,8 @@ class Java {
|
|||
final Duration fivesec = Duration.create(5, "seconds");
|
||||
final Duration threemillis = Duration.create("3 millis");
|
||||
final Duration diff = fivesec.minus(threemillis);
|
||||
assert diff.lt(fivesec);
|
||||
assert Duration.Zero().lt(Duration.Inf());
|
||||
assertTrue(diff.lt(fivesec));
|
||||
assertTrue(Duration.Zero().lt(Duration.Inf()));
|
||||
// #dsl
|
||||
// #deadline
|
||||
final Deadline deadline = Duration.create(10, "seconds").fromNow();
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ import akka.io.Tcp.WritingResumed;
|
|||
import akka.io.TcpMessage;
|
||||
import akka.util.ByteString;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
// #echo-handler
|
||||
public class EchoHandler extends AbstractActor {
|
||||
|
||||
|
|
@ -36,7 +39,7 @@ public class EchoHandler extends AbstractActor {
|
|||
private long transferred;
|
||||
private int storageOffset = 0;
|
||||
private long stored = 0;
|
||||
private Queue<ByteString> storage = new LinkedList<ByteString>();
|
||||
private Queue<ByteString> storage = new LinkedList<>();
|
||||
|
||||
private boolean suspended = false;
|
||||
|
||||
|
|
@ -220,8 +223,8 @@ public class EchoHandler extends AbstractActor {
|
|||
}
|
||||
|
||||
protected void acknowledge(int ack) {
|
||||
assert ack == storageOffset;
|
||||
assert !storage.isEmpty();
|
||||
assertEquals(storageOffset, ack);
|
||||
assertFalse(storage.isEmpty());
|
||||
|
||||
final ByteString acked = storage.remove();
|
||||
stored -= acked.size();
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@ import akka.util.ByteString;
|
|||
|
||||
import akka.testkit.AkkaSpec;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class IODocTest extends AbstractJavaTest {
|
||||
|
||||
public
|
||||
|
|
@ -186,12 +189,12 @@ public class IODocTest extends AbstractJavaTest {
|
|||
|
||||
final Connected c1 = expectMsgClass(Connected.class);
|
||||
final Connected c2 = expectMsgClass(Connected.class);
|
||||
assert c1.localAddress().equals(c2.remoteAddress());
|
||||
assert c2.localAddress().equals(c1.remoteAddress());
|
||||
assertTrue(c1.localAddress().equals(c2.remoteAddress()));
|
||||
assertTrue(c2.localAddress().equals(c1.remoteAddress()));
|
||||
|
||||
client.tell(ByteString.fromString("hello"), getRef());
|
||||
final ByteString reply = expectMsgClass(ByteString.class);
|
||||
assert reply.utf8String().equals("hello");
|
||||
assertEquals("hello", reply.utf8String());
|
||||
|
||||
watch(client);
|
||||
client.tell("close", getRef());
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import jdocs.AbstractJavaTest;
|
|||
import akka.testkit.javadsl.TestKit;
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import akka.actor.*;
|
||||
import akka.japi.Pair;
|
||||
|
|
@ -54,7 +55,7 @@ public class StreamTestKitDocTest extends AbstractJavaTest {
|
|||
final CompletionStage<Integer> future =
|
||||
Source.from(Arrays.asList(1, 2, 3, 4)).runWith(sinkUnderTest, system);
|
||||
final Integer result = future.toCompletableFuture().get(3, TimeUnit.SECONDS);
|
||||
assert (result == 20);
|
||||
assertEquals(20, result.intValue());
|
||||
// #strict-collection
|
||||
}
|
||||
|
||||
|
|
@ -66,7 +67,7 @@ public class StreamTestKitDocTest extends AbstractJavaTest {
|
|||
final CompletionStage<List<Integer>> future =
|
||||
sourceUnderTest.take(10).runWith(Sink.seq(), system);
|
||||
final List<Integer> result = future.toCompletableFuture().get(3, TimeUnit.SECONDS);
|
||||
assertEquals(result, Collections.nCopies(10, 2));
|
||||
assertEquals(Collections.nCopies(10, 2), result);
|
||||
// #grouped-infinite
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +82,7 @@ public class StreamTestKitDocTest extends AbstractJavaTest {
|
|||
.via(flowUnderTest)
|
||||
.runWith(Sink.fold(0, (agg, next) -> agg + next), system);
|
||||
final Integer result = future.toCompletableFuture().get(3, TimeUnit.SECONDS);
|
||||
assert (result == 10);
|
||||
assertEquals(10, result.intValue());
|
||||
// #folded-stream
|
||||
}
|
||||
|
||||
|
|
@ -151,7 +152,7 @@ public class StreamTestKitDocTest extends AbstractJavaTest {
|
|||
ref.tell(Done.getInstance(), ActorRef.noSender());
|
||||
|
||||
final String result = future.toCompletableFuture().get(1, TimeUnit.SECONDS);
|
||||
assertEquals(result, "123");
|
||||
assertEquals("123", result);
|
||||
// #source-actorref
|
||||
}
|
||||
|
||||
|
|
@ -192,13 +193,10 @@ public class StreamTestKitDocTest extends AbstractJavaTest {
|
|||
final CompletionStage<Integer> future = probeAndCompletionStage.second();
|
||||
probe.sendError(new Exception("boom"));
|
||||
|
||||
try {
|
||||
future.toCompletableFuture().get(3, TimeUnit.SECONDS);
|
||||
assert false;
|
||||
} catch (ExecutionException ee) {
|
||||
final Throwable exception = ee.getCause();
|
||||
assertEquals(exception.getMessage(), "boom");
|
||||
}
|
||||
ExecutionException exception =
|
||||
Assert.assertThrows(
|
||||
ExecutionException.class, () -> future.toCompletableFuture().get(3, TimeUnit.SECONDS));
|
||||
assertEquals("boom", exception.getCause().getMessage());
|
||||
// #injecting-failure
|
||||
}
|
||||
|
||||
|
|
@ -232,7 +230,7 @@ public class StreamTestKitDocTest extends AbstractJavaTest {
|
|||
|
||||
pub.sendError(new Exception("Power surge in the linear subroutine C-47!"));
|
||||
final Throwable ex = sub.expectError();
|
||||
assert (ex.getMessage().contains("C-47"));
|
||||
assertTrue(ex.getMessage().contains("C-47"));
|
||||
// #test-source-and-sink
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue