1 /* 2 * @test 3 * @bug 4278121 4 * @summary Ensure that calling unbind() on an unbound name returns 5 * successfully. 6 */ 7 8 import javax.naming.*; 9 10 public class UnbindIdempotent { 11 12 public static void main(String[] args) throws Exception { 13 14 // Create registry on port 1099 if one is not already running. 15 try { 16 java.rmi.registry.LocateRegistry.createRegistry(1099); 17 } catch (java.rmi.RemoteException e) { 18 } 19 20 Context ictx = new InitialContext(); 21 Context rctx; 22 try { 23 rctx = (Context)ictx.lookup("rmi://localhost:1099"); 24 } catch (NamingException e) { 25 // Unable to set up for test. 26 return; 27 } 28 29 // Attempt to unbind a name that is not already bound. 30 try { 31 rctx.unbind("_bogus_4278121_"); 32 } catch (NameNotFoundException e) { 33 throw new Exception("Test failed: unbind() call not idempotent"); 34 } 35 } 36 } | 1 /* 2 * @test 3 * @bug 4278121 4 * @summary Ensure that calling unbind() on an unbound name returns 5 * successfully. 6 * @library ../../../../../../java/rmi/testlibrary 7 * @build TestLibrary 8 * @run main UnbindIdempotent 9 */ 10 11 import java.rmi.registry.Registry; 12 import javax.naming.*; 13 14 public class UnbindIdempotent { 15 16 public static void main(String[] args) throws Exception { 17 int registryPort = -1; 18 // Create registry if one is not already running. 19 try { 20 Registry registry = TestLibrary.createRegistryOnUnusedPort(); 21 registryPort = TestLibrary.getRegistryPort(registry); 22 } catch (java.rmi.RemoteException e) { 23 } 24 25 Context ictx = new InitialContext(); 26 Context rctx; 27 try { 28 rctx = (Context)ictx.lookup("rmi://localhost:" + Integer.toString(registryPort)); 29 } catch (NamingException e) { 30 // Unable to set up for test. 31 return; 32 } 33 34 // Attempt to unbind a name that is not already bound. 35 try { 36 rctx.unbind("_bogus_4278121_"); 37 } catch (NameNotFoundException e) { 38 throw new Exception("Test failed: unbind() call not idempotent"); 39 } 40 } 41 } |