-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Select right IP address based on Java preferences. (akka#22336)
* Change priority of DNS resolved addresses based on java.net.preferIPv6Addresses property. akka#22330 * Include test specs for IPv6 resolver selection. akka#22330 * Use Java system properties to retrieve the IPv6 preference. akka#22330 (cherry picked from commit 6406c0e)
- Loading branch information
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package akka.io | ||
|
||
import java.net.{ Inet4Address, Inet6Address, InetAddress } | ||
|
||
import scala.collection.immutable.Seq | ||
import org.scalatest.{ BeforeAndAfterAll, Matchers, WordSpec } | ||
|
||
class DnsSpec extends WordSpec with BeforeAndAfterAll with Matchers { | ||
|
||
val ip4Address = InetAddress.getByAddress("localhost", Array[Byte](127, 0, 0, 1)) match { | ||
case address: Inet4Address ⇒ address | ||
} | ||
val ipv6Address = InetAddress.getByAddress("localhost", Array[Byte](0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)) match { | ||
case address: Inet6Address ⇒ address | ||
} | ||
|
||
var temporaryValue: Option[String] = None | ||
|
||
override def beforeAll() = { | ||
temporaryValue = sys.props.get("java.net.preferIPv6Addresses") | ||
} | ||
|
||
override def afterAll() = temporaryValue match { | ||
case Some(value) ⇒ sys.props.put("java.net.preferIPv6Addresses", value) | ||
case _ ⇒ sys.props.remove("java.net.preferIPv6Addresses") | ||
} | ||
|
||
"Dns" should { | ||
"resolve to a IPv6 address if it is the preferred network stack" in { | ||
sys.props.put("java.net.preferIPv6Addresses", true.toString) | ||
Dns.Resolved("test", Seq(ip4Address), Seq(ipv6Address)).addr should ===(ipv6Address) | ||
} | ||
"resolve to a IPv4 address if IPv6 is not the preferred network stack" in { | ||
sys.props.remove("java.net.preferIPv6Addresses") | ||
Dns.Resolved("test", Seq(ip4Address), Seq(ipv6Address)).addr should ===(ip4Address) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters