/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 6935563 7044870
* @summary Test that Selector does not select an unconnected DatagramChannel when
* ICMP port unreachable received
*/
public class SelectWhenRefused {
// datagram sent to this address should be refused
try {
dc.configureBlocking(false);
/* Test 1: not connected so ICMP port unreachable should not be received */
if (n > 0) {
// BindException will be thrown if another service is using
// our expected refuser port, cannot run just exit.
throw new RuntimeException("Unexpected wakeup");
}
/* Test 2: connected so ICMP port unreachable may be received */
try {
if (n > 0) {
try {
throw new RuntimeException("Unexpected datagram received");
} catch (PortUnreachableException pue) {
// expected
}
}
} finally {
dc.disconnect();
}
/* Test 3: not connected so ICMP port unreachable should not be received */
if (n > 0) {
throw new RuntimeException("Unexpected wakeup after disconnect");
}
} catch(BindException e) {
// Do nothing, some other test has used this port
} finally {
}
}
throws IOException
{
}
}