avoid infinite blocking in TcpConnectionSpec #21375
* use socket timeout * additional cleanup of socket utils
This commit is contained in:
parent
72925ba392
commit
4f013a3d1e
8 changed files with 42 additions and 79 deletions
|
|
@ -9,6 +9,8 @@ import akka.actor.ActorSystem;
|
|||
import akka.actor.Props;
|
||||
import akka.io.Udp;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import akka.testkit.SocketUtil;
|
||||
|
||||
import docs.AbstractJavaTest;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
|
@ -62,7 +64,7 @@ public class JavaUdpMulticastTest extends AbstractJavaTest {
|
|||
groupBuilder.append(randomAddress.subSequence(i * 4, i * 4 + 4));
|
||||
}
|
||||
final String group = groupBuilder.toString();
|
||||
final Integer port = TestUtils.temporaryUdpIpv6Port(ipv6Iface);
|
||||
final Integer port = SocketUtil.temporaryUdpIpv6Port(ipv6Iface);
|
||||
final String msg = "ohi";
|
||||
final ActorRef sink = getRef();
|
||||
final String iface = ipv6Iface.getName();
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import docs.AbstractJavaTest;
|
|||
import docs.stream.SilenceSystemOut;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import docs.util.SocketUtils;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
|
@ -24,6 +23,7 @@ import akka.stream.javadsl.*;
|
|||
import akka.stream.javadsl.Tcp.*;
|
||||
import akka.stream.stage.*;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import akka.testkit.SocketUtil;
|
||||
import akka.testkit.TestProbe;
|
||||
import akka.util.ByteString;
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ public class StreamTcpDocTest extends AbstractJavaTest {
|
|||
}
|
||||
{
|
||||
|
||||
final InetSocketAddress localhost = SocketUtils.temporaryServerAddress();
|
||||
final InetSocketAddress localhost = SocketUtil.temporaryServerAddress("127.0.0.1", false);
|
||||
final Source<IncomingConnection, CompletionStage<ServerBinding>> connections =
|
||||
Tcp.get(system).bind(localhost.getHostName(), localhost.getPort()); // TODO getHostString in Java7
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ public class StreamTcpDocTest extends AbstractJavaTest {
|
|||
@Test
|
||||
public void actuallyWorkingClientServerApp() {
|
||||
|
||||
final InetSocketAddress localhost = SocketUtils.temporaryServerAddress();
|
||||
final InetSocketAddress localhost = SocketUtil.temporaryServerAddress("127.0.0.1", false);
|
||||
|
||||
final TestProbe serverProbe = new TestProbe(system);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2015-2016 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.util;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
|
||||
public class SocketUtils {
|
||||
|
||||
public static InetSocketAddress temporaryServerAddress(String hostname) {
|
||||
try {
|
||||
ServerSocket socket = ServerSocketChannel.open().socket();
|
||||
socket.bind(new InetSocketAddress(hostname, 0));
|
||||
InetSocketAddress address = new InetSocketAddress(hostname, socket.getLocalPort());
|
||||
socket.close();
|
||||
return address;
|
||||
}
|
||||
catch (IOException io) {
|
||||
throw new RuntimeException(io);
|
||||
}
|
||||
}
|
||||
|
||||
public static InetSocketAddress temporaryServerAddress() {
|
||||
return temporaryServerAddress("127.0.0.1");
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue