Merge "Rearrange deps in JavaLibrary.mk"
diff --git a/luni/src/test/java/libcore/java/net/ConcurrentCloseTest.java b/luni/src/test/java/libcore/java/net/ConcurrentCloseTest.java
index 4309c6f..5ac436e 100644
--- a/luni/src/test/java/libcore/java/net/ConcurrentCloseTest.java
+++ b/luni/src/test/java/libcore/java/net/ConcurrentCloseTest.java
@@ -19,24 +19,28 @@
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
+import java.net.UnknownHostException;
import java.nio.channels.AsynchronousCloseException;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
-import tests.net.StuckServer;
/**
* Test that Socket.close called on another thread interrupts a thread that's blocked doing
* network I/O.
*/
public class ConcurrentCloseTest extends junit.framework.TestCase {
+ private static final InetSocketAddress UNREACHABLE_ADDRESS
+ = new InetSocketAddress("192.0.2.0", 80); // RFC 6666
+
public void test_accept() throws Exception {
ServerSocket ss = new ServerSocket(0);
new Killer(ss).start();
@@ -50,43 +54,36 @@
}
public void test_connect() throws Exception {
- StuckServer ss = new StuckServer(false);
Socket s = new Socket();
new Killer(s).start();
try {
System.err.println("connect...");
- s.connect(ss.getLocalSocketAddress());
+ s.connect(UNREACHABLE_ADDRESS);
fail("connect returned: " + s + "!");
} catch (SocketException expected) {
assertEquals("Socket closed", expected.getMessage());
- } finally {
- ss.close();
}
}
public void test_connect_timeout() throws Exception {
- StuckServer ss = new StuckServer(false);
Socket s = new Socket();
new Killer(s).start();
try {
System.err.println("connect (with timeout)...");
- s.connect(ss.getLocalSocketAddress(), 3600 * 1000);
+ s.connect(UNREACHABLE_ADDRESS, 3600 * 1000);
fail("connect returned: " + s + "!");
} catch (SocketException expected) {
assertEquals("Socket closed", expected.getMessage());
- } finally {
- ss.close();
}
}
public void test_connect_nonBlocking() throws Exception {
- StuckServer ss = new StuckServer(false);
SocketChannel s = SocketChannel.open();
new Killer(s.socket()).start();
try {
System.err.println("connect (non-blocking)...");
s.configureBlocking(false);
- s.connect(ss.getLocalSocketAddress());
+ s.connect(UNREACHABLE_ADDRESS);
while (!s.finishConnect()) {
// Spin like a mad thing!
}
@@ -98,8 +95,6 @@
} catch (ClosedChannelException alsoOkay) {
// For now, I'm assuming that we're happy as long as we get any reasonable exception.
// It may be that we're supposed to guarantee only one or the other.
- } finally {
- ss.close();
}
}
diff --git a/luni/src/test/java/libcore/java/net/DatagramSocketTest.java b/luni/src/test/java/libcore/java/net/DatagramSocketTest.java
index b38a4bb..fabed97 100644
--- a/luni/src/test/java/libcore/java/net/DatagramSocketTest.java
+++ b/luni/src/test/java/libcore/java/net/DatagramSocketTest.java
@@ -198,4 +198,25 @@
f.setAccessible(true);
f.set(impl, null);
}
+
+ public void testAddressSameIfUnchanged() throws Exception {
+ try (DatagramSocket ds = new DatagramSocket();
+ DatagramSocket srcDs = new DatagramSocket()) {
+ ds.setSoTimeout(1000);
+ srcDs.connect(ds.getLocalSocketAddress());
+ srcDs.send(new DatagramPacket(new byte[16], 16));
+ srcDs.send(new DatagramPacket(new byte[16], 16));
+
+ DatagramPacket p = new DatagramPacket(new byte[16], 16);
+ ds.receive(p);
+ InetAddress packetAddr = p.getAddress();
+
+ // This time the packet should have the same address as source address, and it's address
+ // should remain the same object.
+ ds.receive(p);
+ InetAddress newPacketAddr = p.getAddress();
+ assertTrue(packetAddr.isLoopbackAddress());
+ assertSame(packetAddr, newPacketAddr);
+ }
+ }
}
diff --git a/luni/src/test/java/libcore/java/net/OldSocketTest.java b/luni/src/test/java/libcore/java/net/OldSocketTest.java
index c0db1f4..d627f2f 100644
--- a/luni/src/test/java/libcore/java/net/OldSocketTest.java
+++ b/luni/src/test/java/libcore/java/net/OldSocketTest.java
@@ -38,11 +38,13 @@
import java.nio.channels.SocketChannel;
import java.security.Permission;
import libcore.junit.util.ResourceLeakageDetector.DisableResourceLeakageDetection;
-import tests.net.StuckServer;
import tests.support.Support_Configuration;
public class OldSocketTest extends OldSocketTestCase {
+ private static final InetSocketAddress UNREACHABLE_ADDRESS
+ = new InetSocketAddress("192.0.2.0", 0); // RFC 6666
+
ServerSocket ss;
Socket s;
@@ -910,7 +912,7 @@
byte[] theBytes = { 0, 0, 0, 0 };
SocketAddress theAddress = new InetSocketAddress(InetAddress.getLocalHost(), 0);
SocketAddress nonConnectableAddress = new InetSocketAddress(InetAddress.getByAddress(theBytes), 0);
- SocketAddress nonReachableAddress = new InetSocketAddress(StuckServer.UNREACHABLE_ADDRESS, 0);
+ SocketAddress nonReachableAddress = UNREACHABLE_ADDRESS;
SocketAddress invalidType = new mySocketAddress();
Socket theSocket = null;
@@ -1067,7 +1069,7 @@
byte[] theBytes = { 0, 0, 0, 0 };
SocketAddress theAddress = new InetSocketAddress(InetAddress.getLocalHost(), 0);
SocketAddress nonConnectableAddress = new InetSocketAddress(InetAddress.getByAddress(theBytes), 0);
- SocketAddress nonReachableAddress = new InetSocketAddress(StuckServer.UNREACHABLE_ADDRESS, 0);
+ SocketAddress nonReachableAddress = UNREACHABLE_ADDRESS;
SocketAddress invalidType = new mySocketAddress();
try (Socket theSocket = new Socket()) {
@@ -1294,8 +1296,7 @@
}
// now try to set options while we are connecting
- SocketAddress nonReachableAddress =
- new InetSocketAddress(StuckServer.UNREACHABLE_ADDRESS, 0);
+ SocketAddress nonReachableAddress = UNREACHABLE_ADDRESS;
try (Socket theSocket = new Socket()) {
SocketConnector connector = new SocketConnector(5000, theSocket, nonReachableAddress);
connector.start();
diff --git a/luni/src/test/java/libcore/java/nio/channels/SelectorTest.java b/luni/src/test/java/libcore/java/nio/channels/SelectorTest.java
index 3a21e00..e891119 100644
--- a/luni/src/test/java/libcore/java/nio/channels/SelectorTest.java
+++ b/luni/src/test/java/libcore/java/nio/channels/SelectorTest.java
@@ -29,7 +29,6 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
-import tests.net.StuckServer;
public class SelectorTest extends TestCase {
public void testNonBlockingConnect_immediate() throws Exception {
@@ -53,24 +52,6 @@
}
}
- public void testNonBlockingConnect_slow() throws Exception {
- // Test the case where we have to wait for the connection.
- Selector selector = Selector.open();
- StuckServer ss = new StuckServer(true);
- try {
- SocketChannel sc = SocketChannel.open();
- sc.configureBlocking(false);
- sc.connect(ss.getLocalSocketAddress());
- SelectionKey key = sc.register(selector, SelectionKey.OP_CONNECT);
- assertEquals(1, selector.select());
- assertEquals(SelectionKey.OP_CONNECT, key.readyOps());
- sc.finishConnect();
- } finally {
- selector.close();
- ss.close();
- }
- }
-
// http://code.google.com/p/android/issues/detail?id=15388
public void testInterrupted() throws IOException {
Selector selector = Selector.open();
diff --git a/luni/src/test/java/libcore/javax/crypto/spec/AlgorithmParametersTestPBES2.java b/luni/src/test/java/libcore/javax/crypto/spec/AlgorithmParametersTestPBES2.java
index 168940f..b94b72f 100644
--- a/luni/src/test/java/libcore/javax/crypto/spec/AlgorithmParametersTestPBES2.java
+++ b/luni/src/test/java/libcore/javax/crypto/spec/AlgorithmParametersTestPBES2.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License
*/
-package javax.crypto.spec;
+package libcore.javax.crypto.spec;
import java.security.AlgorithmParameters;
import java.security.Key;
@@ -23,6 +23,9 @@
import javax.crypto.Cipher;
import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.PBEKeySpec;
+import javax.crypto.spec.PBEParameterSpec;
public class AlgorithmParametersTestPBES2 extends TestCase {
diff --git a/support/src/test/java/tests/net/StuckServer.java b/support/src/test/java/tests/net/StuckServer.java
deleted file mode 100644
index d6b038b..0000000
--- a/support/src/test/java/tests/net/StuckServer.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.net;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-
-/**
- * A test ServerSocket that you can't connect to --- connects will time out.
- */
-public final class StuckServer {
- private static final boolean DEBUG = false;
-
- // RFC 5737 implies this network -- "test net 1" -- will be unreachable.
- // (There are two other networks to try if we have trouble with this one.)
- // We've had trouble with 10.* in the past (because test labs running CTS often use
- // net 10!) but hopefully this network will be better.
- public static final InetAddress UNREACHABLE_ADDRESS;
- static {
- try {
- UNREACHABLE_ADDRESS = InetAddress.getByAddress(new byte[] { (byte) 192, 0, 2, 0 });
- } catch (UnknownHostException ex) {
- throw new AssertionError(ex);
- }
- }
-
- private ServerSocket serverSocket;
- private InetSocketAddress address;
- private ArrayList<Socket> clients = new ArrayList<Socket>();
-
- public StuckServer(boolean useBacklog) throws IOException {
- // Set a backlog and use it up so that we can expect the
- // connection to time out. According to Stevens
- // 4.5 "listen function", Linux adds 3 to the specified
- // backlog, so we need to connect 4 times before it will hang.
- // The trouble with this is that it won't hang forever.
- // After 10s or so, the kernel allows a couple more connections.
- // This mode is ony useful if you actually want to continue eventually; we use it to
- // test non-blocking connects, for example, where you want to test every part of the code.
- if (useBacklog) {
- this.serverSocket = new ServerSocket(0, 1);
- this.address = (InetSocketAddress) serverSocket.getLocalSocketAddress();
- if (DEBUG) {
- System.err.println("StuckServer: " + serverSocket);
- }
- for (int i = 0; i < 4; ++i) {
- Socket client = new Socket(serverSocket.getInetAddress(), serverSocket.getLocalPort());
- clients.add(client);
- if (DEBUG) {
- System.err.println("StuckServer client " + i + " - " + client);
- }
- }
- } else {
- // In general, though, you don't want to rely on listen(2) backlog. http://b/6971145.
- this.address = new InetSocketAddress(UNREACHABLE_ADDRESS, 80);
- }
- }
-
- public InetSocketAddress getLocalSocketAddress() {
- return address;
- }
-
- public int getLocalPort() {
- return address.getPort();
- }
-
- public void close() throws IOException {
- if (serverSocket != null) {
- serverSocket.close();
- }
- for (Socket client : clients) {
- client.close();
- }
- }
-}