169N/A/*
5266N/A * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* @test
0N/A * @bug 4285878
0N/A * @summary When the "java.rmi.dgc.leaseValue" system property is set to a
0N/A * value much lower than its default (10 minutes), then the server-side
0N/A * user-visible detection of DGC lease expiration-- in the form of
0N/A * Unreferenced.unreferenced() invocations and possibly even local garbage
0N/A * collection (including weak reference notification, finalization, etc.)--
0N/A * may be delayed longer than expected. While this is not a spec violation
0N/A * (because there are no timeliness guarantees for any of these garbage
0N/A * collection-related events), the user might expect that an unreferenced()
0N/A * invocation for an object whose last client has terminated abnorally
0N/A * should occur on relatively the same time order as the lease value
0N/A * granted.
0N/A * @author Peter Jones
0N/A *
0N/A * @library ../../../testlibrary
5551N/A * @build TestLibrary JavaVM LeaseCheckInterval_Stub SelfTerminator
0N/A * @run main/othervm LeaseCheckInterval
0N/A */
0N/A
0N/Aimport java.rmi.Remote;
0N/Aimport java.rmi.RemoteException;
0N/Aimport java.rmi.registry.LocateRegistry;
0N/Aimport java.rmi.registry.Registry;
0N/Aimport java.rmi.server.UnicastRemoteObject;
0N/Aimport java.rmi.server.Unreferenced;
0N/A
0N/Apublic class LeaseCheckInterval implements Remote, Unreferenced {
0N/A
0N/A public static final String BINDING = "LeaseCheckInterval";
0N/A private static final long LEASE_VALUE = 10000;
0N/A private static final long TIMEOUT = 20000;
0N/A
0N/A private Object lock = new Object();
0N/A private boolean unreferencedInvoked = false;
0N/A
0N/A public void unreferenced() {
169N/A System.err.println("unreferenced() method invoked");
169N/A synchronized (lock) {
169N/A unreferencedInvoked = true;
169N/A lock.notify();
169N/A }
0N/A }
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A
169N/A System.err.println("\nRegression test for bug 4285878\n");
0N/A
169N/A /*
169N/A * Set the duration of leases granted to a very small value, so that
169N/A * we can test if expirations are detected in a roughly comparable
169N/A * time.
169N/A */
169N/A System.setProperty("java.rmi.dgc.leaseValue",
169N/A String.valueOf(LEASE_VALUE));
0N/A
169N/A LeaseCheckInterval obj = new LeaseCheckInterval();
0N/A
169N/A try {
169N/A UnicastRemoteObject.exportObject(obj);
169N/A System.err.println("exported remote object");
0N/A
5266N/A int registryPort = TestLibrary.getUnusedRandomPort();
169N/A Registry localRegistry =
5266N/A LocateRegistry.createRegistry(registryPort);
169N/A System.err.println("created local registry");
0N/A
169N/A localRegistry.bind(BINDING, obj);
169N/A System.err.println("bound remote object in local registry");
0N/A
169N/A synchronized (obj.lock) {
169N/A System.err.println("starting remote client VM...");
5266N/A (new JavaVM("SelfTerminator", "-Drmi.registry.port=" +
5266N/A registryPort, "")).start();
0N/A
169N/A System.err.println("waiting for unreferenced() callback...");
169N/A obj.lock.wait(TIMEOUT);
0N/A
169N/A if (obj.unreferencedInvoked) {
169N/A System.err.println("TEST PASSED: " +
169N/A "unreferenced() invoked in timely fashion");
169N/A } else {
169N/A throw new RuntimeException(
169N/A "TEST FAILED: unreferenced() not invoked after " +
169N/A ((double) TIMEOUT / 1000.0) + " seconds");
169N/A }
169N/A }
0N/A
169N/A } catch (Exception e) {
169N/A if (e instanceof RuntimeException) {
169N/A throw (RuntimeException) e;
169N/A } else {
169N/A throw new RuntimeException(
169N/A "TEST FAILED: unexpected exception: " + e.toString());
169N/A }
169N/A } finally {
169N/A /*
169N/A * When all is said and done, try to unexport the remote object
169N/A * so that the VM has a chance to exit.
169N/A */
169N/A try {
169N/A UnicastRemoteObject.unexportObject(obj, true);
169N/A } catch (RemoteException e) {
169N/A }
169N/A }
0N/A }
0N/A}