Merge PatternsCS to Patterns (#26008)

* !act Move some Java API methods from PatternsCS to Patterns.

* Deprecate PatternCS and in favor of Patterns.
This commit is contained in:
kerr 2018-12-06 22:40:43 +08:00 committed by Patrik Nordwall
parent 4f100a1f1e
commit b7f3cbef94
16 changed files with 295 additions and 118 deletions

View file

@ -9,7 +9,7 @@ import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.pattern.PatternsCS;
import akka.pattern.Patterns;
import akka.stream.*;
import akka.stream.javadsl.*;
import akka.testkit.javadsl.TestKit;
@ -59,7 +59,7 @@ public class FlowStreamRefsDocTest extends AbstractJavaTest {
Source<String, NotUsed> logs = streamLogs(requestLogs.streamId);
CompletionStage<SourceRef<String>> logsRef = logs.runWith(StreamRefs.sourceRef(), mat);
PatternsCS.pipe(logsRef.thenApply(ref -> new LogsOffer(ref)), context().dispatcher())
Patterns.pipe(logsRef.thenApply(ref -> new LogsOffer(ref)), context().dispatcher())
.to(sender());
}
@ -111,7 +111,7 @@ public class FlowStreamRefsDocTest extends AbstractJavaTest {
Sink<String, NotUsed> sink = logsSinkFor(prepare.id);
CompletionStage<SinkRef<String>> sinkRef = StreamRefs.<String>sinkRef().to(sink).run(mat);
PatternsCS.pipe(sinkRef.thenApply(ref -> new MeasurementsSinkReady(prepare.id, ref)), context().dispatcher())
Patterns.pipe(sinkRef.thenApply(ref -> new MeasurementsSinkReady(prepare.id, ref)), context().dispatcher())
.to(sender());
})
.build();

View file

@ -20,7 +20,6 @@ import jdocs.stream.TwitterStreamQuickstartDocTest.Model.Tweet;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import scala.concurrent.duration.FiniteDuration;
import java.time.Duration;
import java.util.Arrays;
@ -33,7 +32,7 @@ import java.util.concurrent.CompletionStage;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import static akka.pattern.PatternsCS.ask;
import static akka.pattern.Patterns.ask;
import static jdocs.stream.TwitterStreamQuickstartDocTest.Model.AKKA;
import static jdocs.stream.TwitterStreamQuickstartDocTest.Model.tweets;
import static junit.framework.TestCase.assertTrue;
@ -602,7 +601,7 @@ public class IntegrationDocTest extends AbstractJavaTest {
final RunnableGraph<NotUsed> saveTweets =
akkaTweets
.mapAsync(4, tweet -> ask(database, new Save(tweet), 300))
.mapAsync(4, tweet -> ask(database, new Save(tweet), Duration.ofMillis(300L)))
.to(Sink.ignore());
//#save-tweets

View file

@ -97,7 +97,7 @@ public class StreamTestKitDocTest extends AbstractJavaTest {
final CompletionStage<List<List<Integer>>> future = sourceUnderTest
.grouped(2)
.runWith(Sink.head(), mat);
akka.pattern.PatternsCS.pipe(future, system.dispatcher()).to(probe.getRef());
akka.pattern.Patterns.pipe(future, system.dispatcher()).to(probe.getRef());
probe.expectMsg(Duration.ofSeconds(3), Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3, 4)));
//#pipeto-testprobe
}
@ -200,7 +200,7 @@ public class StreamTestKitDocTest extends AbstractJavaTest {
public void testSourceAndTestSink() throws Exception {
//#test-source-and-sink
final Flow<Integer, Integer, NotUsed> flowUnderTest = Flow.of(Integer.class)
.mapAsyncUnordered(2, sleep -> akka.pattern.PatternsCS.after(
.mapAsyncUnordered(2, sleep -> akka.pattern.Patterns.after(
Duration.ofMillis(10),
system.scheduler(),
system.dispatcher(),

View file

@ -6,13 +6,12 @@ package jdocs.stream.javadsl.cookbook;
import akka.NotUsed;
import akka.actor.*;
import akka.pattern.PatternsCS;
import akka.pattern.Patterns;
import akka.stream.*;
import akka.stream.javadsl.*;
import akka.stream.testkit.TestSubscriber;
import akka.stream.testkit.javadsl.TestSink;
import akka.testkit.javadsl.TestKit;
import akka.util.Timeout;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -83,7 +82,7 @@ public class RecipeGlobalRateLimit extends RecipeTest {
getContext().getSystem().dispatcher(),
getSelf());
}
@Override
public Receive createReceive() {
return open();
@ -150,7 +149,7 @@ public class RecipeGlobalRateLimit extends RecipeTest {
return f.mapAsync(parallelism, element -> {
final CompletionStage<Object> limiterTriggerFuture =
PatternsCS.ask(limiter, Limiter.WANT_TO_PASS, maxAllowedWait);
Patterns.ask(limiter, Limiter.WANT_TO_PASS, maxAllowedWait);
return limiterTriggerFuture.thenApplyAsync(response -> element, system.dispatcher());
});
}