1 /*
   2  * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25  * @bug 6275081
  26  * @summary Rapidly alternating the number of remote objects exported
  27  * on an explicit port between zero and greater than zero (thus
  28  * causing the associated server socket to be created and closed
  29  * repeatedly) should not encounter substantial synchronous delays
  30  * because of the server socket accept loop's failure throttling
  31  * procedure (which sleeps 10 seconds after 10 rapid failures).
  32  * @author Peter Jones
  33  *
  34  * @library ../../testlibrary
  35  * @modules java.rmi/sun.rmi.registry
  36  *          java.rmi/sun.rmi.server
  37  *          java.rmi/sun.rmi.transport
  38  *          java.rmi/sun.rmi.transport.tcp
  39  * @build TestLibrary
  40  * @run main/othervm RapidExportUnexport
  41  */
  42 
  43 import java.rmi.Remote;
  44 import java.rmi.server.UnicastRemoteObject;
  45 
  46 public class RapidExportUnexport {
  47     private static final int PORT = TestLibrary.getUnusedRandomPort();
  48     private static final int REPS = 100;
  49     private static final long TIMEOUT = 60000;
  50 
  51     public static void main(String[] args) throws Exception {
  52         System.err.println("\nRegression test for bug 6275081\n");
  53 
  54         Remote impl = new Remote() { };
  55         long start = System.currentTimeMillis();
  56         for (int i = 0; i < REPS; i++) {
  57             System.err.println(i);
  58             UnicastRemoteObject.exportObject(impl, PORT);
  59             UnicastRemoteObject.unexportObject(impl, true);
  60             Thread.sleep(1);    // work around BindException (bug?)
  61         }
  62         long delta = System.currentTimeMillis() - start;
  63         System.err.println(REPS + " export/unexport operations took " +
  64                            delta + "ms");
  65         if (delta > TIMEOUT) {
  66             throw new Error("TEST FAILED: took over " + TIMEOUT + "ms");
  67         }
  68         System.err.println("TEST PASSED");
  69     }
  70 }