jdk/test/com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 13256 5886d7607acd
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * @bug 4278121
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * @summary Ensure that calling unbind() on an unbound name returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 *      successfully.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
import javax.naming.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
public class UnbindIdempotent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
        // Create registry on port 1099 if one is not already running.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
            java.rmi.registry.LocateRegistry.createRegistry(1099);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
        } catch (java.rmi.RemoteException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
        Context ictx = new InitialContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
        Context rctx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
            rctx = (Context)ictx.lookup("rmi://localhost:1099");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
        } catch (NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
            // Unable to set up for test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
        // Attempt to unbind a name that is not already bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
            rctx.unbind("_bogus_4278121_");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
        } catch (NameNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
            throw new Exception("Test failed:  unbind() call not idempotent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
}