--- a/jdk/test/java/rmi/dgc/retryDirtyCalls/RetryDirtyCalls.java Tue Apr 01 15:14:53 2008 -0700
+++ b/jdk/test/java/rmi/dgc/retryDirtyCalls/RetryDirtyCalls.java Tue Apr 01 15:41:23 2008 -0700
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -55,108 +55,108 @@
* Return this object. The need for this method is explained below.
*/
public Self getSelf() {
- return this;
+ return this;
}
public void unreferenced() {
- synchronized (this) {
- unreferenced = true;
- notifyAll();
- }
+ synchronized (this) {
+ unreferenced = true;
+ notifyAll();
+ }
}
public static void main(String[] args) {
- System.err.println("\nRegression test for bug 4268258\n");
+ System.err.println("\nRegression test for bug 4268258\n");
- /*
- * Set properties to tweak DGC behavior so that this test will execute
- * quickly: set the granted lease duration to 10 seconds, the interval
- * that leases are checked to 3 seconds.
- */
- System.setProperty("java.rmi.dgc.leaseValue", "10000");
- System.setProperty("sun.rmi.dgc.checkInterval", "3000");
+ /*
+ * Set properties to tweak DGC behavior so that this test will execute
+ * quickly: set the granted lease duration to 10 seconds, the interval
+ * that leases are checked to 3 seconds.
+ */
+ System.setProperty("java.rmi.dgc.leaseValue", "10000");
+ System.setProperty("sun.rmi.dgc.checkInterval", "3000");
- /*
- * Make idle connections time out almost instantly (0.1 seconds) so
- * that the DGC implementation will have to make a new connection for
- * each dirty call, thus going through the socket factory, where we
- * can easily cause the operation to fail.
- */
- System.setProperty("sun.rmi.transport.connectionTimeout", "100");
+ /*
+ * Make idle connections time out almost instantly (0.1 seconds) so
+ * that the DGC implementation will have to make a new connection for
+ * each dirty call, thus going through the socket factory, where we
+ * can easily cause the operation to fail.
+ */
+ System.setProperty("sun.rmi.transport.connectionTimeout", "100");
- RetryDirtyCalls impl = new RetryDirtyCalls();
+ RetryDirtyCalls impl = new RetryDirtyCalls();
- try {
- TestSF sf = new TestSF();
- RMISocketFactory.setSocketFactory(sf);
+ try {
+ TestSF sf = new TestSF();
+ RMISocketFactory.setSocketFactory(sf);
- /*
- * The stub returned by UnicastRemoteObject.exportObject() does
- * not participate in DGC, but it does allow us to invoke a method
- * on the remote object through RMI. Therefore, we invoke the
- * getSelf() method through RMI, which returns an equivalent stub
- * that does participate in DGC.
- */
- Self stub = (Self) UnicastRemoteObject.exportObject(impl);
- Self dgcStub = stub.getSelf();
- stub = null; // in case 4114579 has been fixed
+ /*
+ * The stub returned by UnicastRemoteObject.exportObject() does
+ * not participate in DGC, but it does allow us to invoke a method
+ * on the remote object through RMI. Therefore, we invoke the
+ * getSelf() method through RMI, which returns an equivalent stub
+ * that does participate in DGC.
+ */
+ Self stub = (Self) UnicastRemoteObject.exportObject(impl);
+ Self dgcStub = stub.getSelf();
+ stub = null; // in case 4114579 has been fixed
- /*
- * Set the socket factory to cause 3 connections attempts in a row
- * to fail before allowing a connection to succeed, expecting the
- * client-side DGC implementation to make at least four attempts.
- */
- final int FLAKE_FACTOR = 3;
- sf.setFlakeFactor(FLAKE_FACTOR);
+ /*
+ * Set the socket factory to cause 3 connections attempts in a row
+ * to fail before allowing a connection to succeed, expecting the
+ * client-side DGC implementation to make at least four attempts.
+ */
+ final int FLAKE_FACTOR = 3;
+ sf.setFlakeFactor(FLAKE_FACTOR);
- long deadline = System.currentTimeMillis() + TIMEOUT;
- boolean unreferenced;
+ long deadline = System.currentTimeMillis() + TIMEOUT;
+ boolean unreferenced;
- synchronized (impl) {
- while (!(unreferenced = impl.unreferenced)) {
- long timeToWait = deadline - System.currentTimeMillis();
- if (timeToWait > 0) {
- impl.wait(timeToWait);
- } else {
- break;
- }
- }
- }
+ synchronized (impl) {
+ while (!(unreferenced = impl.unreferenced)) {
+ long timeToWait = deadline - System.currentTimeMillis();
+ if (timeToWait > 0) {
+ impl.wait(timeToWait);
+ } else {
+ break;
+ }
+ }
+ }
- if (unreferenced) {
- throw new RuntimeException("remote object unreferenced");
- }
+ if (unreferenced) {
+ throw new RuntimeException("remote object unreferenced");
+ }
- int createCount = sf.getCreateCount();
- if (createCount == 0) {
- throw new RuntimeException("test socket factory never used");
- } else if (createCount < (FLAKE_FACTOR + 3)) {
- /*
- * The unreferenced method was not invoked for some reason,
- * but the dirty calls were clearly not retried well enough.
- */
- throw new RuntimeException(
- "test failed because dirty calls not retried enough, " +
- "but remote object not unreferenced");
- }
+ int createCount = sf.getCreateCount();
+ if (createCount == 0) {
+ throw new RuntimeException("test socket factory never used");
+ } else if (createCount < (FLAKE_FACTOR + 3)) {
+ /*
+ * The unreferenced method was not invoked for some reason,
+ * but the dirty calls were clearly not retried well enough.
+ */
+ throw new RuntimeException(
+ "test failed because dirty calls not retried enough, " +
+ "but remote object not unreferenced");
+ }
- System.err.println(
- "TEST PASSED: remote object not unreferenced");
+ System.err.println(
+ "TEST PASSED: remote object not unreferenced");
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException("TEST FAILED: " + e.toString());
- } finally {
- /*
- * When all is said and done, try to unexport the remote object
- * so that the VM has a chance to exit.
- */
- try {
- UnicastRemoteObject.unexportObject(impl, true);
- } catch (Exception e) {
- }
- }
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException("TEST FAILED: " + e.toString());
+ } finally {
+ /*
+ * When all is said and done, try to unexport the remote object
+ * so that the VM has a chance to exit.
+ */
+ try {
+ UnicastRemoteObject.unexportObject(impl, true);
+ } catch (Exception e) {
+ }
+ }
}
}
@@ -169,30 +169,30 @@
private int createCount = 0;
public synchronized void setFlakeFactor(int newFlakeFactor) {
- flakeFactor = newFlakeFactor;
+ flakeFactor = newFlakeFactor;
}
public synchronized int getCreateCount() {
- return createCount;
+ return createCount;
}
public synchronized Socket createSocket(String host, int port)
- throws IOException
+ throws IOException
{
- createCount++;
+ createCount++;
- if (++flakeState > flakeFactor) {
- flakeState = 0;
- }
+ if (++flakeState > flakeFactor) {
+ flakeState = 0;
+ }
- if (flakeState == 0) {
- return new Socket(host, port);
- } else {
- throw new IOException("random network failure");
- }
+ if (flakeState == 0) {
+ return new Socket(host, port);
+ } else {
+ throw new IOException("random network failure");
+ }
}
public ServerSocket createServerSocket(int port) throws IOException {
- return new ServerSocket(port);
+ return new ServerSocket(port);
}
}