--- a/jdk/test/java/rmi/activation/Activatable/inactiveGroup/InactiveGroup.java Fri Dec 13 18:08:20 2013 -0800
+++ b/jdk/test/java/rmi/activation/Activatable/inactiveGroup/InactiveGroup.java Fri Dec 20 15:10:11 2013 -0800
@@ -145,7 +145,9 @@
* activation group's process hasn't gone away.
*/
System.err.println("Ping unicast object for existence");
- for (int i = 0; i < 10; i++) {
+ // set timeout 5 seconds
+ final long stopTime = System.currentTimeMillis() + 5000;
+ while (System.currentTimeMillis() < stopTime) {
unicastObj.ping();
Thread.sleep(500);
}
--- a/jdk/test/java/rmi/reliability/juicer/ApplicationServer.java Fri Dec 13 18:08:20 2013 -0800
+++ b/jdk/test/java/rmi/reliability/juicer/ApplicationServer.java Fri Dec 20 15:10:11 2013 -0800
@@ -21,6 +21,7 @@
* questions.
*/
+import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
@@ -60,27 +61,29 @@
* On initialization, export remote objects and register
* them with server.
*/
+ @Override
public void run() {
try {
int i = 0;
/*
- * Locate apple user object in registry. The lookup will
- * occur until it is successful or fails LOOKUP_ATTEMPTS times.
+ * Locate apple user object in registry. The lookup will occur
+ * every 5 seconds until it is successful or timeout 50 seconds.
* These repeated attempts allow the ApplicationServer
* to be started before the AppleUserImpl.
*/
Exception exc = null;
- for (i = 0; i < LOOKUP_ATTEMPTS; i++) {
+ long stopTime = System.currentTimeMillis() + LOOKUP_ATTEMPTS * 10000;
+ while (System.currentTimeMillis() < stopTime) {
try {
Registry registry = LocateRegistry.getRegistry(
- registryHost, registryPort);
+ registryHost, registryPort);
user = (AppleUser) registry.lookup("AppleUser");
user.startTest();
break; //successfully obtained AppleUser
- } catch (Exception e) {
+ } catch (RemoteException | NotBoundException e) {
exc = e;
- Thread.sleep(10000); //sleep 10 seconds and try again
+ Thread.sleep(5000); //sleep 5 seconds and try again
}
}
if (user == null) {
@@ -113,9 +116,8 @@
logger.log(Level.SEVERE,
"Failed to register callbacks for " + apples[i] + ":", e);
user.reportException(e);
- return;
}
- } catch (Exception e) {
+ } catch (InterruptedException | RemoteException e) {
logger.log(Level.SEVERE, "Unexpected exception:", e);
}
}
@@ -143,17 +145,22 @@
try {
for (int i = 0; i < args.length ; i++ ) {
String arg = args[i];
- if (arg.equals("-numApples")) {
- i++;
- num = Integer.parseInt(args[i]);
- } else if (arg.equals("-registryHost")) {
- i++;
- host = args[i];
- } else if (arg.equals("-registryPort")) {
- i++;
- port = Integer.parseInt(args[i]);
- } else {
- usage();
+ switch (arg) {
+ case "-numApples":
+ i++;
+ num = Integer.parseInt(args[i]);
+ break;
+ case "-registryHost":
+ i++;
+ host = args[i];
+ break;
+ case "-registryPort":
+ i++;
+ port = Integer.parseInt(args[i]);
+ break;
+ default:
+ usage();
+ break;
}
}
--- a/jdk/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/UseCustomSocketFactory.java Fri Dec 13 18:08:20 2013 -0800
+++ b/jdk/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/UseCustomSocketFactory.java Fri Dec 20 15:10:11 2013 -0800
@@ -33,9 +33,8 @@
*/
import java.io.*;
+import java.net.MalformedURLException;
import java.rmi.*;
-import java.rmi.activation.*;
-import java.rmi.server.*;
import java.rmi.registry.*;
public class UseCustomSocketFactory {
@@ -51,7 +50,7 @@
try {
LocateRegistry.createRegistry(REGISTRY_PORT);
- } catch (Exception e) {
+ } catch (RemoteException e) {
TestLibrary.bomb("creating registry", e);
}
@@ -92,15 +91,16 @@
protocol[i]);
System.err.println("\nusing protocol: " +
- (protocol[i] == "" ? "none" : protocol[i]));
+ ("".equals(protocol[i]) ? "none" : protocol[i]));
try {
/* spawn VM for EchoServer */
serverVM.start();
/* lookup server */
- int tries = 12; // need enough tries for slow machine.
echo[i] = null;
+ // 24 seconds timeout
+ long stopTime = System.currentTimeMillis() + 24000;
do {
try {
echo[i] = (Echo) Naming.lookup("//:" + REGISTRY_PORT +
@@ -108,15 +108,14 @@
break;
} catch (NotBoundException e) {
try {
- Thread.sleep(2000);
- } catch (Exception ignore) {
+ Thread.sleep(200);
+ } catch (InterruptedException ignore) {
}
- continue;
}
- } while (--tries > 0);
+ } while (System.currentTimeMillis() < stopTime);
if (echo[i] == null)
- TestLibrary.bomb("server not bound in 12 tries", null);
+ TestLibrary.bomb("server not bound in 120 tries", null);
/* invoke remote method and print result*/
System.err.println("Bound to " + echo[i]);
@@ -135,9 +134,8 @@
serverVM.destroy();
try {
Naming.unbind("//:" + REGISTRY_PORT + "/EchoServer");
- } catch (Exception e) {
+ } catch (RemoteException | NotBoundException | MalformedURLException e) {
TestLibrary.bomb("unbinding EchoServer", e);
-
}
}
}
@@ -152,7 +150,7 @@
for (int i = 0; i < echo.length; i++) {
try {
System.err.println("\nusing protocol: " +
- (protocol[i] == "" ? "none" : protocol[i]));
+ ("".equals(protocol[i]) ? "none" : protocol[i]));
byte[] data = ("Greetings, citizen " +
System.getProperty("user.name") + "!").getBytes();
byte[] result = echo[i].echoNot(data);
--- a/jdk/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/UseCustomSocketFactory.java Fri Dec 13 18:08:20 2013 -0800
+++ b/jdk/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/UseCustomSocketFactory.java Fri Dec 20 15:10:11 2013 -0800
@@ -33,9 +33,9 @@
* @run main/othervm/policy=security.policy/timeout=120 UseCustomSocketFactory
*/
-import java.io.*;
+import java.io.IOException;
+import java.net.MalformedURLException;
import java.rmi.*;
-import java.rmi.server.*;
import java.rmi.registry.*;
public class UseCustomSocketFactory {
@@ -44,7 +44,7 @@
int registryPort = -1;
- String[] protocol = new String[] { "", "compress", "xor" };
+ String[] protocols = new String[] { "", "compress", "xor" };
System.out.println("\nRegression test for bug 4127826\n");
@@ -53,31 +53,26 @@
try {
Registry registry = TestLibrary.createRegistryOnUnusedPort();
registryPort = TestLibrary.getRegistryPort(registry);
- } catch (Exception e) {
+ } catch (RemoteException e) {
TestLibrary.bomb("creating registry", e);
}
-
- for (int i = 0; i < protocol.length; i++) {
-
+ for (String protocol : protocols) {
System.err.println("test policy: " +
- TestParams.defaultPolicy);
-
- JavaVM serverVM = new JavaVM("EchoImpl",
- "-Djava.security.policy=" +
- TestParams.defaultPolicy +
- " -Drmi.registry.port=" +
- registryPort,
- protocol[i]);
+ TestParams.defaultPolicy);
+ JavaVM serverVM = new JavaVM("EchoImpl", "-Djava.security.policy=" +
+ TestParams.defaultPolicy +
+ " -Drmi.registry.port=" +
+ registryPort, protocol);
System.err.println("\nusing protocol: " +
- (protocol[i] == "" ? "none" : protocol[i]));
-
+ ("".equals(protocol) ? "none" : protocol));
try {
/* spawn VM for EchoServer */
serverVM.start();
/* lookup server */
- int tries = 8;
Echo obj = null;
+ // 16 seconds timeout
+ long stopTime = System.currentTimeMillis() + 16000;
do {
try {
obj = (Echo) Naming.lookup("//:" + registryPort +
@@ -85,12 +80,11 @@
break;
} catch (NotBoundException e) {
try {
- Thread.sleep(2000);
- } catch (Exception ignore) {
+ Thread.sleep(200);
+ } catch (InterruptedException ignore) {
}
- continue;
}
- } while (--tries > 0);
+ } while (System.currentTimeMillis() < stopTime);
if (obj == null)
TestLibrary.bomb("server not bound in 8 tries", null);
@@ -98,21 +92,21 @@
/* invoke remote method and print result*/
System.err.println("Bound to " + obj);
byte[] data = ("Greetings, citizen " +
- System.getProperty("user.name") + "!"). getBytes();
+ System.getProperty("user.name") + "!"). getBytes();
byte[] result = obj.echoNot(data);
for (int j = 0; j < result.length; j++)
result[j] = (byte) ~result[j];
System.err.println("Result: " + new String(result));
- } catch (Exception e) {
+ } catch (IOException e) {
TestLibrary.bomb("test failed", e);
} finally {
serverVM.destroy();
try {
Naming.unbind("//:" + registryPort +
- "/EchoServer");
- } catch (Exception e) {
+ "/EchoServer");
+ } catch (RemoteException | NotBoundException | MalformedURLException e) {
TestLibrary.bomb("unbinding EchoServer", e);
}
--- a/jdk/test/java/rmi/testlibrary/ActivationLibrary.java Fri Dec 13 18:08:20 2013 -0800
+++ b/jdk/test/java/rmi/testlibrary/ActivationLibrary.java Fri Dec 20 15:10:11 2013 -0800
@@ -66,7 +66,8 @@
// We do as much as 50 deactivation trials, each separated by
// at least 100 milliseconds sleep time (max sleep time of 5 secs).
final long deactivateSleepTime = 100;
- for (int i = 0; i < 50; i ++) {
+ long stopTime = System.currentTimeMillis() + deactivateSleepTime * 50;
+ while (System.currentTimeMillis() < stopTime) {
try {
if (Activatable.inactive(id) == true) {
mesg("inactive successful");
--- a/jdk/test/java/rmi/transport/readTimeout/ReadTimeoutTest.java Fri Dec 13 18:08:20 2013 -0800
+++ b/jdk/test/java/rmi/transport/readTimeout/ReadTimeoutTest.java Fri Dec 20 15:10:11 2013 -0800
@@ -44,6 +44,8 @@
import java.rmi.server.RMISocketFactory;
import java.io.*;
import java.net.*;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
public class ReadTimeoutTest
{
@@ -86,23 +88,18 @@
InputStream stream = DoS.getInputStream();
// Read on the socket in the background
- boolean[] successful = new boolean[] { false };
- (new SomeReader(stream, successful)).start();
+ CountDownLatch done = new CountDownLatch(1);
+ (new SomeReader(stream, done)).start();
// Wait for completion
- int nretries = 4;
- while (nretries-- > 0) {
- if (successful[0])
- break;
- Thread.sleep(DELAY);
- }
-
- if (successful[0]) {
+ if (done.await(DELAY * 4, TimeUnit.SECONDS)) {
System.err.println("TEST PASSED.");
} else {
throw new Error("TEST FAILED.");
}
+ } catch (InterruptedException ie) {
+ throw new Error("Unexpected interrupt", ie);
} finally {
try {
if (DoS != null)
@@ -120,6 +117,7 @@
{
private int servport = 0;
+ @Override
public Socket createSocket(String h, int p)
throws IOException
{
@@ -130,6 +128,7 @@
* Aborts if createServerSocket(0) is called twice, because then
* it doesn't know whether to remember the first or second port.
*/
+ @Override
public ServerSocket createServerSocket(int p)
throws IOException
{
@@ -155,22 +154,23 @@
} // end class SomeFactory
protected static class SomeReader extends Thread {
- private InputStream readon;
- private boolean[] vec;
+ private final InputStream readon;
+ private final CountDownLatch done;
- public SomeReader(InputStream s, boolean[] successvec) {
+ public SomeReader(InputStream s, CountDownLatch done) {
super();
this.setDaemon(true);
this.readon = s;
- this.vec = successvec;
+ this.done = done;
}
+ @Override
public void run() {
try {
int c = this.readon.read();
if (c != -1)
throw new Error ("Server returned " + c);
- this.vec[0] = true;
+ done.countDown();
} catch (IOException e) {
e.printStackTrace();