Skip to content

Commit

Permalink
Formatting java codes with sbt-java-formatter.
Browse files Browse the repository at this point in the history
  • Loading branch information
He-Pin committed Jan 11, 2019
1 parent 2750000 commit 998c5a9
Show file tree
Hide file tree
Showing 401 changed files with 20,061 additions and 17,761 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

public class ActorTestKitTest extends JUnitSuite {

@ClassRule
public static TestKitJunitResource testKit = new TestKitJunitResource();
@ClassRule public static TestKitJunitResource testKit = new TestKitJunitResource();

@Test
public void systemNameShouldComeFromTestClassViaJunitResource() {
Expand Down Expand Up @@ -51,10 +50,12 @@ public void systemNameShouldComeFromGivenClassName() {
@Test
public void testKitShouldSpawnActor() throws Exception {
final CompletableFuture<Done> started = new CompletableFuture<>();
testKit.spawn(Behaviors.setup((context) -> {
started.complete(done());
return Behaviors.same();
}));
testKit.spawn(
Behaviors.setup(
(context) -> {
started.complete(done());
return Behaviors.same();
}));
started.get(3, TimeUnit.SECONDS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@

public class BehaviorTestKitTest extends JUnitSuite {

public interface Command {
}
public interface Command {}

public static class SpawnWatchAndUnWatch implements Command {
private final String name;
Expand Down Expand Up @@ -123,72 +122,102 @@ public Log(String what) {
}
}

public interface Action {
}
public interface Action {}

private static Behavior<Action> childInitial = Behaviors.ignore();

private static Props props = Props.empty().withDispatcherFromConfig("cat");

private static Behavior<Command> behavior = Behaviors.receive(Command.class)
.onMessage(SpawnChildren.class, (context, message) -> {
IntStream.range(0, message.numberOfChildren).forEach(i -> {
context.spawn(childInitial, "child" + i);
});
return Behaviors.same();
})
.onMessage(SpawnChildrenAnonymous.class, (context, message) -> {
IntStream.range(0, message.numberOfChildren).forEach(i -> {
context.spawnAnonymous(childInitial);
});
return Behaviors.same();
})
.onMessage(SpawnChildrenWithProps.class, (context, message) -> {
IntStream.range(0, message.numberOfChildren).forEach(i -> {
context.spawn(childInitial, "child" + i, message.props);
});
return Behaviors.same();
})
.onMessage(SpawnChildrenAnonymousWithProps.class, (context, message) -> {
IntStream.range(0, message.numberOfChildren).forEach(i -> {
context.spawnAnonymous(childInitial, message.props);
});
return Behaviors.same();
})
.onMessage(CreateMessageAdapter.class, (context, message) -> {
context.messageAdapter(message.clazz, message.f);
return Behaviors.same();
})
.onMessage(SpawnWatchAndUnWatch.class, (context, message) -> {
ActorRef<Action> c = context.spawn(childInitial, message.name);
context.watch(c);
context.unwatch(c);
return Behaviors.same();
})
.onMessage(SpawnAndWatchWith.class, (context, message) -> {
ActorRef<Action> c = context.spawn(childInitial, message.name);
context.watchWith(c, message);
return Behaviors.same();
})
.onMessage(SpawnSession.class, (context, message) -> {
ActorRef<String> session = context.spawnAnonymous(Behaviors.receiveMessage( m -> {
message.sessionHandler.tell(m);
return Behaviors.same();
}));
message.replyTo.tell(session);
return Behaviors.same();
})
.onMessage(KillSession.class, (context, message) -> {
context.stop(message.session);
message.replyTo.tell(Done.getInstance());
return Behaviors.same();
})
.onMessage(Log.class, (context, message) -> {
context.getLog().info(message.what);
return Behaviors.same();
})
.build();

private static Behavior<Command> behavior =
Behaviors.receive(Command.class)
.onMessage(
SpawnChildren.class,
(context, message) -> {
IntStream.range(0, message.numberOfChildren)
.forEach(
i -> {
context.spawn(childInitial, "child" + i);
});
return Behaviors.same();
})
.onMessage(
SpawnChildrenAnonymous.class,
(context, message) -> {
IntStream.range(0, message.numberOfChildren)
.forEach(
i -> {
context.spawnAnonymous(childInitial);
});
return Behaviors.same();
})
.onMessage(
SpawnChildrenWithProps.class,
(context, message) -> {
IntStream.range(0, message.numberOfChildren)
.forEach(
i -> {
context.spawn(childInitial, "child" + i, message.props);
});
return Behaviors.same();
})
.onMessage(
SpawnChildrenAnonymousWithProps.class,
(context, message) -> {
IntStream.range(0, message.numberOfChildren)
.forEach(
i -> {
context.spawnAnonymous(childInitial, message.props);
});
return Behaviors.same();
})
.onMessage(
CreateMessageAdapter.class,
(context, message) -> {
context.messageAdapter(message.clazz, message.f);
return Behaviors.same();
})
.onMessage(
SpawnWatchAndUnWatch.class,
(context, message) -> {
ActorRef<Action> c = context.spawn(childInitial, message.name);
context.watch(c);
context.unwatch(c);
return Behaviors.same();
})
.onMessage(
SpawnAndWatchWith.class,
(context, message) -> {
ActorRef<Action> c = context.spawn(childInitial, message.name);
context.watchWith(c, message);
return Behaviors.same();
})
.onMessage(
SpawnSession.class,
(context, message) -> {
ActorRef<String> session =
context.spawnAnonymous(
Behaviors.receiveMessage(
m -> {
message.sessionHandler.tell(m);
return Behaviors.same();
}));
message.replyTo.tell(session);
return Behaviors.same();
})
.onMessage(
KillSession.class,
(context, message) -> {
context.stop(message.session);
message.replyTo.tell(Done.getInstance());
return Behaviors.same();
})
.onMessage(
Log.class,
(context, message) -> {
context.getLog().info(message.what);
return Behaviors.same();
})
.build();

@Test
public void allowAssertionsOnEffectType() {
Expand Down Expand Up @@ -240,18 +269,18 @@ public void returnEffectsThatHaveTakenPlace() {

@Test
@Ignore("Not supported for Java API")
public void allowAssertionsUsingPartialFunctions() {
}
public void allowAssertionsUsingPartialFunctions() {}

@Test
public void spawnChildrenWithNoProps() {
BehaviorTestKit<Command> test = BehaviorTestKit.create(behavior);
test.run(new SpawnChildren(2));
List<Effect> allEffects = test.getAllEffects();
assertEquals(
Arrays.asList(Effects.spawned(childInitial, "child0"), Effects.spawned(childInitial, "child1", Props.empty())),
allEffects
);
Arrays.asList(
Effects.spawned(childInitial, "child0"),
Effects.spawned(childInitial, "child1", Props.empty())),
allEffects);
}

@Test
Expand All @@ -267,9 +296,10 @@ public void spawnAnonChildrenWithNoProps() {
test.run(new SpawnChildrenAnonymous(2));
List<Effect> allEffects = test.getAllEffects();
assertEquals(
Arrays.asList(Effects.spawnedAnonymous(childInitial), Effects.spawnedAnonymous(childInitial, Props.empty())),
allEffects
);
Arrays.asList(
Effects.spawnedAnonymous(childInitial),
Effects.spawnedAnonymous(childInitial, Props.empty())),
allEffects);
}

@Test
Expand Down Expand Up @@ -330,5 +360,4 @@ public void allowRetrievingAndKilling() {
assertEquals(Collections.singletonList(Done.getInstance()), d.getAllReceived());
test.expectEffectClass(Effect.Stopped.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@

public class TestProbeTest extends JUnitSuite {

@ClassRule
public static TestKitJunitResource testKit = new TestKitJunitResource();
@ClassRule public static TestKitJunitResource testKit = new TestKitJunitResource();

@Test
public void testReceiveOne() {
TestProbe<EventT> probe = TestProbe.create(testKit.system());

List<EventT> eventsT = akka.japi.Util.javaArrayList(TestProbeSpec.eventsT(10));

eventsT.forEach(e->{
probe.getRef().tell(e);
assertEquals(probe.receiveOne(), e);
});
eventsT.forEach(
e -> {
probe.getRef().tell(e);
assertEquals(probe.receiveOne(), e);
});

probe.expectNoMessage();
}
Expand All @@ -41,10 +41,11 @@ public void testReceiveOneMaxDuration() {

List<EventT> eventsT = akka.japi.Util.javaArrayList(TestProbeSpec.eventsT(2));

eventsT.forEach(e->{
probe.getRef().tell(e);
assertEquals(probe.receiveOne(Duration.ofMillis(100)), e);
});
eventsT.forEach(
e -> {
probe.getRef().tell(e);
assertEquals(probe.receiveOne(Duration.ofMillis(100)), e);
});

probe.expectNoMessage();
}
Expand All @@ -58,19 +59,25 @@ public void testReceiveOneFailOnTimeout() {
@Test
public void testAwaitAssert() {
TestProbe<String> probe = TestProbe.create(testKit.system());
probe.awaitAssert(() -> {
// ... something ...
return null;
});
probe.awaitAssert(Duration.ofSeconds(3), () -> {
// ... something ...
return null;
});
probe.awaitAssert(
() -> {
// ... something ...
return null;
});
probe.awaitAssert(
Duration.ofSeconds(3),
() -> {
// ... something ...
return null;
});
String awaitAssertResult =
probe.awaitAssert(Duration.ofSeconds(3), Duration.ofMillis(100), () -> {
// ... something ...
return "some result";
});
probe.awaitAssert(
Duration.ofSeconds(3),
Duration.ofMillis(100),
() -> {
// ... something ...
return "some result";
});
assertEquals("some result", awaitAssertResult);
}

Expand All @@ -90,22 +97,28 @@ public void testFish() {
probe.getRef().tell("one");
probe.getRef().tell("one");
probe.getRef().tell("two");
List<String> results = probe.fishForMessage(Duration.ofSeconds(3), "hint", message -> {
if (message.equals("one")) return FishingOutcomes.continueAndIgnore();
else if (message.equals("two")) return FishingOutcomes.complete();
else return FishingOutcomes.fail("error");
});
List<String> results =
probe.fishForMessage(
Duration.ofSeconds(3),
"hint",
message -> {
if (message.equals("one")) return FishingOutcomes.continueAndIgnore();
else if (message.equals("two")) return FishingOutcomes.complete();
else return FishingOutcomes.fail("error");
});
assertEquals(Arrays.asList("two"), results);
}

@Test
public void testWithin() {
TestProbe<String> probe = TestProbe.create(testKit.system());
String withinResult = probe.within(Duration.ofSeconds(3), () -> {
// ... something ...
return "result";
});
String withinResult =
probe.within(
Duration.ofSeconds(3),
() -> {
// ... something ...
return "result";
});
assertEquals("result", withinResult);
}

}
Loading

0 comments on commit 998c5a9

Please sign in to comment.