mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-23 20:44:41 +02:00
6886108: Test case B4933582 binding to fixed port number
Reviewed-by: chegar
This commit is contained in:
parent
a4622c3ab0
commit
ef945f9722
3 changed files with 28 additions and 4 deletions
|
@ -125,9 +125,16 @@ public class B4933582 implements HttpCallback {
|
||||||
firstTime = args[0].equals ("first");
|
firstTime = args[0].equals ("first");
|
||||||
MyAuthenticator auth = new MyAuthenticator ();
|
MyAuthenticator auth = new MyAuthenticator ();
|
||||||
Authenticator.setDefault (auth);
|
Authenticator.setDefault (auth);
|
||||||
AuthCacheValue.setAuthCache (new CacheImpl());
|
CacheImpl cache;
|
||||||
try {
|
try {
|
||||||
server = new HttpServer (new B4933582(), 1, 10, 5009);
|
if (firstTime) {
|
||||||
|
server = new HttpServer (new B4933582(), 1, 10, 0);
|
||||||
|
cache = new CacheImpl (server.getLocalPort());
|
||||||
|
} else {
|
||||||
|
cache = new CacheImpl ();
|
||||||
|
server = new HttpServer(new B4933582(), 1, 10, cache.getPort());
|
||||||
|
}
|
||||||
|
AuthCacheValue.setAuthCache (cache);
|
||||||
System.out.println ("Server: listening on port: " + server.getLocalPort());
|
System.out.println ("Server: listening on port: " + server.getLocalPort());
|
||||||
client ("http://localhost:"+server.getLocalPort()+"/d1/foo.html");
|
client ("http://localhost:"+server.getLocalPort()+"/d1/foo.html");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -172,8 +179,15 @@ public class B4933582 implements HttpCallback {
|
||||||
|
|
||||||
static class CacheImpl extends AuthCacheImpl {
|
static class CacheImpl extends AuthCacheImpl {
|
||||||
HashMap map;
|
HashMap map;
|
||||||
|
int port; // need to store the port number the server is using
|
||||||
|
|
||||||
CacheImpl () throws IOException {
|
CacheImpl () throws IOException {
|
||||||
|
this (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
CacheImpl (int port) throws IOException {
|
||||||
super();
|
super();
|
||||||
|
this.port = port;
|
||||||
File src = new File ("cache.ser");
|
File src = new File ("cache.ser");
|
||||||
if (src.exists()) {
|
if (src.exists()) {
|
||||||
ObjectInputStream is = new ObjectInputStream (
|
ObjectInputStream is = new ObjectInputStream (
|
||||||
|
@ -181,6 +195,8 @@ public class B4933582 implements HttpCallback {
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
map = (HashMap)is.readObject ();
|
map = (HashMap)is.readObject ();
|
||||||
|
this.port = (Integer)is.readObject ();
|
||||||
|
System.out.println ("read port from file " + port);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
assert false;
|
assert false;
|
||||||
}
|
}
|
||||||
|
@ -192,6 +208,10 @@ public class B4933582 implements HttpCallback {
|
||||||
setMap (map);
|
setMap (map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getPort () {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
private void writeMap () {
|
private void writeMap () {
|
||||||
try {
|
try {
|
||||||
File dst = new File ("cache.ser");
|
File dst = new File ("cache.ser");
|
||||||
|
@ -203,6 +223,8 @@ public class B4933582 implements HttpCallback {
|
||||||
new FileOutputStream (dst)
|
new FileOutputStream (dst)
|
||||||
);
|
);
|
||||||
os.writeObject(map);
|
os.writeObject(map);
|
||||||
|
os.writeObject(port);
|
||||||
|
System.out.println ("wrote port " + port);
|
||||||
os.close();
|
os.close();
|
||||||
} catch (IOException e) {}
|
} catch (IOException e) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,8 @@ public class HttpTransaction {
|
||||||
if (rspheaders != null) {
|
if (rspheaders != null) {
|
||||||
buf.append (rspheaders.toString()).append("\r\n");
|
buf.append (rspheaders.toString()).append("\r\n");
|
||||||
}
|
}
|
||||||
buf.append ("Body: ").append (new String(rspbody)).append("\r\n");
|
String rbody = rspbody == null? "": new String (rspbody);
|
||||||
|
buf.append ("Body: ").append (rbody).append("\r\n");
|
||||||
return new String (buf);
|
return new String (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,8 @@ public class HttpTransaction {
|
||||||
if (rspheaders != null) {
|
if (rspheaders != null) {
|
||||||
buf.append (rspheaders.toString()).append("\r\n");
|
buf.append (rspheaders.toString()).append("\r\n");
|
||||||
}
|
}
|
||||||
buf.append ("Body: ").append (new String(rspbody)).append("\r\n");
|
String rbody = rspbody == null? "": new String (rspbody);
|
||||||
|
buf.append ("Body: ").append (rbody).append("\r\n");
|
||||||
return new String (buf);
|
return new String (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue