Formatting java codes with sbt-java-formatter.
This commit is contained in:
parent
27500001ea
commit
998c5a9285
401 changed files with 19750 additions and 17450 deletions
|
|
@ -19,13 +19,13 @@ import org.junit.Test;
|
|||
public class ParentChildTest extends AbstractJavaTest {
|
||||
@ClassRule
|
||||
public static AkkaJUnitActorSystemResource actorSystemResource =
|
||||
new AkkaJUnitActorSystemResource("TestKitDocTest",
|
||||
ConfigFactory.parseString("akka.loggers = [akka.testkit.TestEventListener]"));
|
||||
|
||||
new AkkaJUnitActorSystemResource(
|
||||
"TestKitDocTest",
|
||||
ConfigFactory.parseString("akka.loggers = [akka.testkit.TestEventListener]"));
|
||||
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
|
||||
//#test-example
|
||||
// #test-example
|
||||
static class Parent extends AbstractActor {
|
||||
final ActorRef child = getContext().actorOf(Props.create(Child.class), "child");
|
||||
boolean ponged = false;
|
||||
|
|
@ -33,9 +33,9 @@ public class ParentChildTest extends AbstractJavaTest {
|
|||
@Override
|
||||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.matchEquals("pingit", message -> child.tell("ping", getSelf()))
|
||||
.matchEquals("pong", message -> ponged = true)
|
||||
.build();
|
||||
.matchEquals("pingit", message -> child.tell("ping", getSelf()))
|
||||
.matchEquals("pong", message -> ponged = true)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -43,16 +43,18 @@ public class ParentChildTest extends AbstractJavaTest {
|
|||
@Override
|
||||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.matchEquals("ping", message -> {
|
||||
getContext().getParent().tell("pong", getSelf());
|
||||
})
|
||||
.build();
|
||||
.matchEquals(
|
||||
"ping",
|
||||
message -> {
|
||||
getContext().getParent().tell("pong", getSelf());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
}
|
||||
//#test-example
|
||||
// #test-example
|
||||
|
||||
static
|
||||
//#test-dependentchild
|
||||
// #test-dependentchild
|
||||
class DependentChild extends AbstractActor {
|
||||
private final ActorRef parent;
|
||||
|
||||
|
|
@ -63,17 +65,18 @@ public class ParentChildTest extends AbstractJavaTest {
|
|||
@Override
|
||||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.matchEquals("ping", message -> parent.tell("pong", getSelf()))
|
||||
.build();
|
||||
.matchEquals("ping", message -> parent.tell("pong", getSelf()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
//#test-dependentchild
|
||||
// #test-dependentchild
|
||||
|
||||
static
|
||||
//#test-dependentparent
|
||||
// #test-dependentparent
|
||||
class DependentParent extends AbstractActor {
|
||||
final ActorRef child;
|
||||
final ActorRef probe;
|
||||
|
||||
public DependentParent(Props childProps, ActorRef probe) {
|
||||
child = getContext().actorOf(childProps, "child");
|
||||
this.probe = probe;
|
||||
|
|
@ -82,33 +85,32 @@ public class ParentChildTest extends AbstractJavaTest {
|
|||
@Override
|
||||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.matchEquals("pingit", message -> child.tell("ping", getSelf()))
|
||||
.matchEquals("pong", message -> probe.tell("ponged", getSelf()))
|
||||
.build();
|
||||
.matchEquals("pingit", message -> child.tell("ping", getSelf()))
|
||||
.matchEquals("pong", message -> probe.tell("ponged", getSelf()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
//#test-dependentparent
|
||||
// #test-dependentparent
|
||||
|
||||
static
|
||||
//#test-dependentparent-generic
|
||||
// #test-dependentparent-generic
|
||||
class GenericDependentParent extends AbstractActor {
|
||||
final ActorRef child;
|
||||
boolean ponged = false;
|
||||
|
||||
public GenericDependentParent(Function<ActorRefFactory, ActorRef> childMaker)
|
||||
throws Exception {
|
||||
public GenericDependentParent(Function<ActorRefFactory, ActorRef> childMaker) throws Exception {
|
||||
child = childMaker.apply(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.matchEquals("pingit", message -> child.tell("ping", getSelf()))
|
||||
.matchEquals("pong", message -> ponged = true)
|
||||
.build();
|
||||
.matchEquals("pingit", message -> child.tell("ping", getSelf()))
|
||||
.matchEquals("pong", message -> ponged = true)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
//#test-dependentparent-generic
|
||||
// #test-dependentparent-generic
|
||||
|
||||
@Test
|
||||
public void testingWithoutParent() {
|
||||
|
|
@ -122,34 +124,34 @@ public class ParentChildTest extends AbstractJavaTest {
|
|||
public void testingWithCustomProps() {
|
||||
final TestProbe probe = new TestProbe(system);
|
||||
final Props childProps = Props.create(MockedChild.class);
|
||||
final ActorRef parent = system.actorOf(Props.create(DependentParent.class, childProps, probe.ref()));
|
||||
final ActorRef parent =
|
||||
system.actorOf(Props.create(DependentParent.class, childProps, probe.ref()));
|
||||
|
||||
probe.send(parent, "pingit");
|
||||
|
||||
probe.expectMsg("ponged");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testingWithChildProbe() throws Exception {
|
||||
final TestProbe probe = new TestProbe(system);
|
||||
//#child-maker-test
|
||||
// #child-maker-test
|
||||
Function<ActorRefFactory, ActorRef> maker = param -> probe.ref();
|
||||
ActorRef parent = system.actorOf(Props.create(GenericDependentParent.class, maker));
|
||||
//#child-maker-test
|
||||
// #child-maker-test
|
||||
probe.send(parent, "pingit");
|
||||
probe.expectMsg("ping");
|
||||
}
|
||||
|
||||
public void exampleProdActorFactoryFunction() throws Exception {
|
||||
//#child-maker-prod
|
||||
// #child-maker-prod
|
||||
Function<ActorRefFactory, ActorRef> maker = f -> f.actorOf(Props.create(Child.class));
|
||||
ActorRef parent = system.actorOf(Props.create(GenericDependentParent.class, maker));
|
||||
//#child-maker-prod
|
||||
// #child-maker-prod
|
||||
}
|
||||
|
||||
static
|
||||
//#test-fabricated-parent-creator
|
||||
// #test-fabricated-parent-creator
|
||||
class FabricatedParentCreator implements Creator<Actor> {
|
||||
private final TestProbe proxy;
|
||||
|
||||
|
|
@ -157,49 +159,49 @@ public class ParentChildTest extends AbstractJavaTest {
|
|||
this.proxy = proxy;
|
||||
}
|
||||
|
||||
@Override public Actor create() throws Exception {
|
||||
@Override
|
||||
public Actor create() throws Exception {
|
||||
return new AbstractActor() {
|
||||
final ActorRef child = getContext().actorOf(Props.create(Child.class), "child");
|
||||
|
||||
@Override
|
||||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.matchAny(message -> {
|
||||
if (getSender().equals(child)) {
|
||||
proxy.ref().forward(message, getContext());
|
||||
} else {
|
||||
child.forward(message, getContext());
|
||||
}
|
||||
})
|
||||
.build();
|
||||
|
||||
.matchAny(
|
||||
message -> {
|
||||
if (getSender().equals(child)) {
|
||||
proxy.ref().forward(message, getContext());
|
||||
} else {
|
||||
child.forward(message, getContext());
|
||||
}
|
||||
})
|
||||
.build();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
//#test-fabricated-parent-creator
|
||||
// #test-fabricated-parent-creator
|
||||
|
||||
@Test
|
||||
public void testProbeParentTest() throws Exception {
|
||||
//#test-TestProbe-parent
|
||||
// #test-TestProbe-parent
|
||||
TestKit parent = new TestKit(system);
|
||||
ActorRef child = parent.childActorOf(Props.create(Child.class));
|
||||
|
||||
|
||||
parent.send(child, "ping");
|
||||
parent.expectMsgEquals("pong");
|
||||
//#test-TestProbe-parent
|
||||
// #test-TestProbe-parent
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void fabricatedParentTestsItsChildResponses() throws Exception {
|
||||
// didn't put final on these in order to make the parent fit in one line in the html docs
|
||||
//#test-fabricated-parent
|
||||
// #test-fabricated-parent
|
||||
TestProbe proxy = new TestProbe(system);
|
||||
ActorRef parent = system.actorOf(Props.create(Actor.class, new FabricatedParentCreator(proxy)));
|
||||
|
||||
proxy.send(parent, "ping");
|
||||
proxy.expectMsg("pong");
|
||||
//#test-fabricated-parent
|
||||
// #test-fabricated-parent
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue