test/java/rmi/transport/rapidExportUnexport/RapidExportUnexport.java

Print this page


   1 /*
   2  * Copyright (c) 2005, 2008, 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  * @build RapidExportUnexport

  35  * @run main/othervm RapidExportUnexport
  36  */
  37 
  38 import java.rmi.Remote;
  39 import java.rmi.server.UnicastRemoteObject;
  40 
  41 public class RapidExportUnexport {
  42 
  43     private static final int PORT = 2055;
  44 
  45     private static final int REPS = 100;
  46     private static final long TIMEOUT = 60000;
  47 
  48     public static void main(String[] args) throws Exception {
  49         System.err.println("\nRegression test for bug 6275081\n");
  50 
  51         Remote impl = new Remote() { };
  52         long start = System.currentTimeMillis();
  53         for (int i = 0; i < REPS; i++) {
  54             System.err.println(i);
  55             UnicastRemoteObject.exportObject(impl, PORT);
  56             UnicastRemoteObject.unexportObject(impl, true);
  57             Thread.sleep(1);    // work around BindException (bug?)
  58         }
  59         long delta = System.currentTimeMillis() - start;
  60         System.err.println(REPS + " export/unexport operations took " +
  61                            delta + "ms");
  62         if (delta > TIMEOUT) {
  63             throw new Error("TEST FAILED: took over " + TIMEOUT + "ms");
  64         }
   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  * @build TestLibrary RapidExportUnexport
  36  * @run main/othervm RapidExportUnexport
  37  */
  38 
  39 import java.rmi.Remote;
  40 import java.rmi.server.UnicastRemoteObject;
  41 
  42 public class RapidExportUnexport {
  43     private static final int PORT = TestLibrary.getUnusedRandomPort();


  44     private static final int REPS = 100;
  45     private static final long TIMEOUT = 60000;
  46 
  47     public static void main(String[] args) throws Exception {
  48         System.err.println("\nRegression test for bug 6275081\n");
  49 
  50         Remote impl = new Remote() { };
  51         long start = System.currentTimeMillis();
  52         for (int i = 0; i < REPS; i++) {
  53             System.err.println(i);
  54             UnicastRemoteObject.exportObject(impl, PORT);
  55             UnicastRemoteObject.unexportObject(impl, true);
  56             Thread.sleep(1);    // work around BindException (bug?)
  57         }
  58         long delta = System.currentTimeMillis() - start;
  59         System.err.println(REPS + " export/unexport operations took " +
  60                            delta + "ms");
  61         if (delta > TIMEOUT) {
  62             throw new Error("TEST FAILED: took over " + TIMEOUT + "ms");
  63         }