Skip to content

Commit

Permalink
Merge pull request akka#22967 from 2m/wip-not-bound-address-2m
Browse files Browse the repository at this point in the history
akka#22889 Use port 0 for address which is supposed to never be bound
  • Loading branch information
2m authored Jun 8, 2017
2 parents d0c0d91 + e630541 commit f20aea6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 51 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import akka.stream.javadsl.Tcp.*;
import akka.japi.function.*;
import akka.testkit.AkkaSpec;
import akka.stream.testkit.TestUtils;
import akka.testkit.SocketUtil;
import akka.util.ByteString;
import akka.testkit.AkkaJUnitActorSystemResource;

Expand Down Expand Up @@ -57,7 +57,7 @@ public void apply(IncomingConnection conn) {

@Test
public void mustWorkInHappyCase() throws Exception {
final InetSocketAddress serverAddress = TestUtils.temporaryServerAddress("127.0.0.1", false);
final InetSocketAddress serverAddress = SocketUtil.temporaryServerAddress("127.0.0.1", false);
final Source<IncomingConnection, CompletionStage<ServerBinding>> binding = Tcp.get(system)
.bind(serverAddress.getHostString(), serverAddress.getPort());

Expand All @@ -83,7 +83,7 @@ public ByteString apply(ByteString acc, ByteString elem) {

@Test
public void mustReportServerBindFailure() throws Exception {
final InetSocketAddress serverAddress = TestUtils.temporaryServerAddress("127.0.0.1", false);
final InetSocketAddress serverAddress = SocketUtil.temporaryServerAddress("127.0.0.1", false);
final Source<IncomingConnection, CompletionStage<ServerBinding>> binding = Tcp.get(system)
.bind(serverAddress.getHostString(), serverAddress.getPort());

Expand All @@ -110,8 +110,7 @@ public void mustReportServerBindFailure() throws Exception {

@Test
public void mustReportClientConnectFailure() throws Throwable {
final InetSocketAddress serverAddress = TestUtils.temporaryServerAddress(
"127.0.0.1", false);
final InetSocketAddress serverAddress = SocketUtil.notBoundServerAddress();
try {
try {
Source.from(testInput)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import akka.testkit.{ TestKitBase, TestProbe }
import akka.util.ByteString
import java.net.InetSocketAddress
import scala.collection.immutable.Queue
import akka.stream.testkit.TestUtils.temporaryServerAddress
import akka.testkit.SocketUtil.temporaryServerAddress

import scala.concurrent.duration._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import akka.io.Tcp._
import akka.stream._
import akka.stream.scaladsl.Tcp.{ IncomingConnection, ServerBinding }
import akka.stream.scaladsl.{ Flow, _ }
import akka.stream.testkit.TestUtils.temporaryServerAddress
import akka.stream.testkit.Utils._
import akka.stream.testkit._
import akka.testkit.{ EventFilter, TestKit, TestLatch, TestProbe }
import akka.testkit.SocketUtil.temporaryServerAddress
import akka.util.ByteString
import akka.{ Done, NotUsed }
import com.typesafe.config.ConfigFactory
Expand Down
2 changes: 2 additions & 0 deletions akka-testkit/src/main/scala/akka/testkit/SocketUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ object SocketUtil {
port
}

def notBoundServerAddress(address: String): InetSocketAddress = new InetSocketAddress(address, 0)
def notBoundServerAddress(): InetSocketAddress = notBoundServerAddress("127.0.0.1")
}

0 comments on commit f20aea6

Please sign in to comment.