Skip to content

Commit

Permalink
8278961: Enable debug logging in java/net/DatagramSocket/SendDatagram…
Browse files Browse the repository at this point in the history
…ToBadAddress.java

Reviewed-by: rrich
Backport-of: c17a0122c4b5f17b85dc0bee0777b2a831debf6d
  • Loading branch information
GoeLin committed Jan 16, 2023
1 parent 044eb4e commit 127f3eb
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions test/jdk/java/net/DatagramSocket/SendDatagramToBadAddress.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -28,7 +28,7 @@
*
* @summary DatagramSocket.send should throw exception when connected
* to an invalid destination (on platforms that support it).
* @run main/othervm -Djdk.net.usePlainDatagramSocketImpl=false SendDatagramToBadAddress
* @run main/othervm -Djdk.net.usePlainDatagramSocketImpl=false SendDatagramToBadAddress -d
*/

import java.net.*;
Expand Down Expand Up @@ -70,6 +70,8 @@ public void receive (int loop, boolean expectError) throws Exception {
for (int i=0; i<loop; i++) {
try {
server.receive (pack);
print("received data from address " + pack.getAddress()
+ " port " + pack.getPort());
} catch (Exception e) {
if (expectError) {
print ("Got expected error: " + e);
Expand Down Expand Up @@ -116,12 +118,15 @@ private void test(DatagramSocket sock) throws Exception {
DatagramPacket p;
byte[] buf;
int port = serversock.getLocalPort ();
print("tests will be run against destination address " + addr + " port " + port);
final int loop = 5;
Server s = new Server (serversock);
int i;

print ("Checking send to connected address ...");
sock.connect(addr, port);
print("socket is locally bound to address " + sock.getLocalAddress()
+ " port " + sock.getLocalPort());

for (i = 0; i < loop; i++) {
try {
Expand Down Expand Up @@ -170,6 +175,8 @@ private void test(DatagramSocket sock) throws Exception {
sock.send(p);
p = new DatagramPacket(buf, buf.length, addr, port);
sock.receive (p);
print("(unexpectedly) received data from address " + p.getAddress()
+ " port " + p.getPort() + " on attempt " + i);
} catch (InterruptedIOException ex) {
print ("socket timeout");
} catch (Exception ex) {
Expand Down

1 comment on commit 127f3eb

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.