8130394: DatagramChannel tests need to be hardended to ignore stray datagrams
The patch updates tests to ignore stray datagrams, or at least print more information to ease troubleshooting. Reviewed-by: rriggs
This commit is contained in:
parent
13a6fbe6c0
commit
ea58ca6a25
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 2015, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4503641
|
||||
* @bug 4503641 8130394
|
||||
* @summary Check that DatagramChannel.receive returns a new SocketAddress
|
||||
* when it receives a packet from the same source address but
|
||||
* different endpoint.
|
||||
@ -63,6 +63,7 @@ public class ReceiveISA {
|
||||
SocketAddress sa[] = new SocketAddress[3];
|
||||
for (int i=0; i<3; i++) {
|
||||
sa[i] = dc3.receive(rb);
|
||||
System.out.println("received "+ sa[i] );
|
||||
rb.clear();
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2015, 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
|
||||
@ -22,20 +22,24 @@
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 4669040
|
||||
* @bug 4669040 8130394
|
||||
* @summary Test DatagramChannel subsequent receives with no datagram ready
|
||||
* @author Mike McCloskey
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.nio.*;
|
||||
import java.nio.channels.*;
|
||||
import java.nio.charset.*;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.channels.DatagramChannel;
|
||||
|
||||
public class Sender {
|
||||
|
||||
static PrintStream log = System.err;
|
||||
static volatile SocketAddress clientISA = null;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
test();
|
||||
@ -81,6 +85,7 @@ public class Sender {
|
||||
InetAddress address = InetAddress.getLocalHost();
|
||||
InetSocketAddress isa = new InetSocketAddress(address, port);
|
||||
dc.connect(isa);
|
||||
clientISA = dc.getLocalAddress();
|
||||
dc.write(bb);
|
||||
} catch (Exception ex) {
|
||||
e = ex;
|
||||
@ -118,13 +123,20 @@ public class Sender {
|
||||
public void run() {
|
||||
SocketAddress sa = null;
|
||||
|
||||
|
||||
try {
|
||||
ByteBuffer bb = ByteBuffer.allocateDirect(12);
|
||||
bb.clear();
|
||||
// Get the one valid datagram
|
||||
dc.configureBlocking(false);
|
||||
while (sa == null)
|
||||
while (sa == null) {
|
||||
sa = dc.receive(bb);
|
||||
if (sa != null && clientISA != null && !clientISA.equals(sa)) {
|
||||
log.println("Ignore a possible stray diagram from " + sa);
|
||||
sa = null;
|
||||
}
|
||||
}
|
||||
showBuffer("Received:", bb);
|
||||
sa = null;
|
||||
for (int i=0; i<100; i++) {
|
||||
bb.clear();
|
||||
|
Loading…
x
Reference in New Issue
Block a user