Skip to content

Commit 12ed555

Browse files
authored
Avoid deprecated code (that will be removed in pekko 2.0.0) (#803)
* old way to get subscriptionTimeoutSettings not accessible any more * ActorMaterializer class not accessible * deprecated Source.actorRef function removed readability import temp compile workaround Update ConnectionTestApp.scala Update ConnectionTestApp.scala * Update HttpClientExampleDocTest.java * use Materializer instead of ActorMaterializer * Update FutureDirectivesExamplesTest.java * try using attributes to get the timeout * Update HttpServerBluePrint.scala Update HttpServerBluePrint.scala
1 parent be87a99 commit 12ed555

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
lines changed

docs/src/test/java/docs/http/javadsl/HttpClientExampleDocTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
import org.apache.pekko.actor.AbstractActor;
5050
import org.apache.pekko.http.javadsl.model.HttpRequest;
5151
import org.apache.pekko.http.javadsl.model.HttpResponse;
52-
import static org.apache.pekko.pattern.PatternsCS.pipe;
52+
import static org.apache.pekko.pattern.Patterns.pipe;
5353

5454
// #single-request-in-actor-example
5555

docs/src/test/java/docs/http/javadsl/server/directives/BasicDirectivesExamplesTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
import org.apache.pekko.http.javadsl.testkit.JUnitRouteTest;
3333
import org.apache.pekko.http.javadsl.server.*;
3434
import org.apache.pekko.japi.pf.PFBuilder;
35-
import org.apache.pekko.stream.ActorMaterializer;
36-
import org.apache.pekko.stream.ActorMaterializerSettings;
35+
import org.apache.pekko.stream.Materializer;
3736
import org.apache.pekko.stream.javadsl.Sink;
3837
import org.apache.pekko.stream.javadsl.Source;
3938
import org.apache.pekko.util.ByteString;
@@ -292,8 +291,7 @@ public void testExtractLog() {
292291
@Test
293292
public void testWithMaterializer() {
294293
// #withMaterializer
295-
final ActorMaterializerSettings settings = ActorMaterializerSettings.create(system());
296-
final ActorMaterializer special = ActorMaterializer.create(settings, system(), "special");
294+
final Materializer special = Materializer.createMaterializer(system());
297295

298296
final Route sample =
299297
path(

docs/src/test/java/docs/http/javadsl/server/directives/FutureDirectivesExamplesTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.apache.pekko.testkit.javadsl.TestKit;
2828
import org.junit.Ignore;
2929
import org.junit.Test;
30-
import scala.concurrent.duration.FiniteDuration;
3130

3231
import static org.apache.pekko.http.javadsl.server.PathMatchers.*;
3332

@@ -165,8 +164,8 @@ public void testOnCompleteWithBreaker() throws InterruptedException {
165164
// import static org.apache.pekko.http.javadsl.server.PathMatchers.*;
166165

167166
final int maxFailures = 1;
168-
final FiniteDuration callTimeout = FiniteDuration.create(5, TimeUnit.SECONDS);
169-
final FiniteDuration resetTimeout = FiniteDuration.create(1, TimeUnit.SECONDS);
167+
final Duration callTimeout = Duration.ofSeconds(5);
168+
final Duration resetTimeout = Duration.ofSeconds(1);
170169
final CircuitBreaker breaker =
171170
CircuitBreaker.create(system().scheduler(), maxFailures, callTimeout, resetTimeout);
172171

http-core/src/main/scala/org/apache/pekko/http/impl/engine/server/HttpServerBluePrint.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ import pekko.http.scaladsl.model.headers.`Timeout-Access`
4545
import pekko.http.scaladsl.model._
4646
import pekko.http.impl.util.LogByteStringTools._
4747

48-
import scala.concurrent.{ ExecutionContext, Future, Promise }
49-
import scala.concurrent.duration.{ Deadline, Duration, FiniteDuration }
5048
import scala.collection.immutable
49+
import scala.concurrent.{ ExecutionContext, Future, Promise }
50+
import scala.concurrent.duration.{ Deadline, Duration, DurationLong, FiniteDuration }
5151
import scala.jdk.DurationConverters._
5252
import scala.util.Failure
5353
import scala.util.control.{ NoStackTrace, NonFatal }
@@ -721,7 +721,12 @@ private[http] object HttpServerBluePrint {
721721
})
722722

723723
private var activeTimers = 0
724-
private def timeout = materializer.settings.subscriptionTimeoutSettings.timeout
724+
private val timeout: FiniteDuration = {
725+
inheritedAttributes.get[ActorAttributes.StreamSubscriptionTimeout] match {
726+
case Some(attr) => attr.timeout
727+
case None => 5.minutes // should not happen
728+
}
729+
}
725730
private def addTimeout(s: SubscriptionTimeout): Unit = {
726731
if (activeTimers == 0) setKeepGoing(true)
727732
activeTimers += 1

http-core/src/test/scala/org/apache/pekko/http/scaladsl/TestServer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ object TestServer extends App {
4444
val settings = ActorMaterializerSettings(system)
4545
// .withSyncProcessingLimit(Int.MaxValue)
4646
.withInputBuffer(128, 128)
47-
implicit val fm: ActorMaterializer = ActorMaterializer(settings)
47+
implicit val fm: Materializer = ActorMaterializer(settings)
4848
try {
4949
val binding = Http().newServerAt("localhost", 9001).bindSync {
5050
case req @ HttpRequest(GET, Uri.Path("/"), _, _, _) =>

http-tests/src/test/scala/org/apache/pekko/http/scaladsl/server/ConnectionTestApp.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ object ConnectionTestApp {
4343

4444
val clientFlow = Http().superPool[Int]()
4545

46-
val sourceActor = {
46+
val sourceQueue = {
4747
// Our superPool expects (HttpRequest, Int) as input
4848
val source =
49-
Source.actorRef[(HttpRequest, Int)](10000, OverflowStrategy.dropNew).buffer(20000, OverflowStrategy.fail)
49+
Source.queue[(HttpRequest, Int)](10000)
50+
.buffer(20000, OverflowStrategy.fail)
5051
val sink = Sink.foreach[(Try[HttpResponse], Int)] {
5152
case (resp, id) => handleResponse(resp, id)
5253
}
@@ -55,7 +56,7 @@ object ConnectionTestApp {
5556
}
5657

5758
def sendPoolFlow(uri: Uri, id: Int): Unit = {
58-
sourceActor ! ((buildRequest(uri), id))
59+
sourceQueue.offer((buildRequest(uri), id))
5960
}
6061

6162
def sendPoolFuture(uri: Uri, id: Int): Unit = {

0 commit comments

Comments
 (0)