test/java/rmi/registry/multipleRegistries/MultipleRegistries.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 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 4267864
  26  * @summary Can't run multiple registries in the same VM
  27  * @author Ann Wollrath
  28  *


  29  * @build MultipleRegistries
  30  * @run main/othervm/timeout=240 MultipleRegistries
  31  */
  32 
  33 import java.rmi.Remote;
  34 import java.rmi.RemoteException;
  35 import java.rmi.registry.LocateRegistry;
  36 import java.rmi.registry.Registry;
  37 import java.rmi.server.UnicastRemoteObject;
  38 
  39 public class MultipleRegistries implements RemoteInterface {
  40 
  41     private static final String NAME = "MultipleRegistries";
  42 
  43     public Object passObject(Object obj) {
  44         return obj;
  45     }
  46 
  47     public static void main(String[] args) throws Exception {
  48 
  49         RemoteInterface server = null;
  50         RemoteInterface proxy = null;
  51 
  52         try {
  53             System.err.println("export object");
  54             server = new MultipleRegistries();
  55             proxy =
  56                 (RemoteInterface) UnicastRemoteObject.exportObject(server, 0);
  57 
  58             System.err.println("proxy = " + proxy);
  59 
  60             System.err.println("export registries");
  61             Registry registryImpl1 = LocateRegistry.createRegistry(2030);
  62             Registry registryImpl2 = LocateRegistry.createRegistry(2040);
  63 

  64             System.err.println("bind remote object in registries");
  65             Registry registry1 = LocateRegistry.getRegistry(2030);
  66             Registry registry2 = LocateRegistry.getRegistry(2040);
  67 
  68             registry1.bind(NAME, proxy);
  69             registry2.bind(NAME, proxy);
  70 
  71             System.err.println("lookup remote object in registries");
  72 
  73             RemoteInterface remote1 = (RemoteInterface) registry1.lookup(NAME);
  74             RemoteInterface remote2 = (RemoteInterface) registry2.lookup(NAME);
  75 
  76             System.err.println("invoke methods on remote objects");
  77             remote1.passObject(remote1);
  78             remote2.passObject(remote2);
  79 
  80             System.err.println("TEST PASSED");
  81 
  82         } finally {
  83             if (proxy != null) {
  84                 UnicastRemoteObject.unexportObject(server, true);
  85             }
  86         }
   1 /*
   2  * Copyright (c) 2003, 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 4267864
  26  * @summary Can't run multiple registries in the same VM
  27  * @author Ann Wollrath
  28  *
  29  * @library ../../testlibrary
  30  * @build TestLibrary
  31  * @build MultipleRegistries
  32  * @run main/othervm/timeout=240 MultipleRegistries
  33  */
  34 
  35 import java.rmi.Remote;
  36 import java.rmi.RemoteException;
  37 import java.rmi.registry.LocateRegistry;
  38 import java.rmi.registry.Registry;
  39 import java.rmi.server.UnicastRemoteObject;
  40 
  41 public class MultipleRegistries implements RemoteInterface {
  42 
  43     private static final String NAME = "MultipleRegistries";
  44 
  45     public Object passObject(Object obj) {
  46         return obj;
  47     }
  48 
  49     public static void main(String[] args) throws Exception {
  50 
  51         RemoteInterface server = null;
  52         RemoteInterface proxy = null;
  53 
  54         try {
  55             System.err.println("export object");
  56             server = new MultipleRegistries();
  57             proxy =
  58                 (RemoteInterface) UnicastRemoteObject.exportObject(server, 0);
  59 
  60             System.err.println("proxy = " + proxy);
  61 
  62             System.err.println("export registries");
  63             Registry registryImpl1 = TestLibrary.createRegistryOnUnusedPort();
  64             int port1 = TestLibrary.getRegistryPort(registryImpl1);
  65             Registry registryImpl2 = TestLibrary.createRegistryOnUnusedPort();
  66             int port2 = TestLibrary.getRegistryPort(registryImpl2);
  67             System.err.println("bind remote object in registries");
  68             Registry registry1 = LocateRegistry.getRegistry(port1);
  69             Registry registry2 = LocateRegistry.getRegistry(port2);
  70 
  71             registry1.bind(NAME, proxy);
  72             registry2.bind(NAME, proxy);
  73 
  74             System.err.println("lookup remote object in registries");
  75 
  76             RemoteInterface remote1 = (RemoteInterface) registry1.lookup(NAME);
  77             RemoteInterface remote2 = (RemoteInterface) registry2.lookup(NAME);
  78 
  79             System.err.println("invoke methods on remote objects");
  80             remote1.passObject(remote1);
  81             remote2.passObject(remote2);
  82 
  83             System.err.println("TEST PASSED");
  84 
  85         } finally {
  86             if (proxy != null) {
  87                 UnicastRemoteObject.unexportObject(server, true);
  88             }
  89         }