< prev index next >

test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/UseCustomSocketFactory.java

Print this page




  26  * @key intermittent
  27  * @summary synopsis: cannot use socket factories with Activatable objects
  28  * @author Ann Wollrath
  29  *
  30  * @library ../../../../testlibrary
  31  * @modules java.rmi/sun.rmi.registry
  32  *          java.rmi/sun.rmi.server
  33  *          java.rmi/sun.rmi.transport
  34  *          java.rmi/sun.rmi.transport.tcp
  35  *          java.base/sun.nio.ch
  36  * @build TestLibrary Echo EchoImpl EchoImpl_Stub RMIDSelectorProvider
  37  * @run main/othervm/policy=security.policy/timeout=360 UseCustomSocketFactory
  38  */
  39 
  40 import java.io.*;
  41 import java.net.MalformedURLException;
  42 import java.rmi.*;
  43 import java.rmi.registry.*;
  44 
  45 public class UseCustomSocketFactory {
  46     static final int REGISTRY_PORT = TestLibrary.getUnusedRandomPort();
  47 
  48     static String[] protocol = new String[] { "", "compress", "xor" };
  49 
  50     public static void main(String[] args) {
  51 
  52         System.out.println("\nRegression test for bug 4115696\n");
  53 
  54         TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
  55 
  56         try {
  57             LocateRegistry.createRegistry(REGISTRY_PORT);

  58         } catch (RemoteException e) {
  59             TestLibrary.bomb("creating registry", e);
  60         }
  61 
  62         RMID rmid = null;
  63 
  64         try {
  65             rmid = RMID.createRMIDOnEphemeralPort();
  66             rmid.addArguments(new String[] {
  67                 "-C-Djava.security.policy=" +
  68                     TestParams.defaultGroupPolicy +
  69                     " -C-Djava.security.manager=java.rmi.RMISecurityManager "});
  70             rmid.start();
  71 
  72             Echo[] echo = spawnAndTest(rmid.getPort());
  73             reactivateAndTest(echo);
  74         } catch (IOException e) {
  75             TestLibrary.bomb("creating rmid", e);
  76         } finally {
  77             if (rmid != null)
  78                 rmid.destroy();
  79         }
  80     }
  81 
  82     private static Echo[] spawnAndTest(int rmidPort) {
  83 
  84         System.err.println("\nCreate Test-->");
  85 
  86         Echo[] echo = new Echo[protocol.length];
  87 
  88         for (int i = 0; i < protocol.length; i++) {
  89             JavaVM serverVM = new JavaVM("EchoImpl",
  90                                          "-Djava.security.policy=" +
  91                                          TestParams.defaultPolicy +
  92                                          " -Drmi.registry.port=" +
  93                                          REGISTRY_PORT +
  94                                          " -Djava.rmi.activation.port=" +
  95                                          rmidPort,
  96                                          protocol[i]);
  97 
  98             System.err.println("\nusing protocol: " +
  99                     ("".equals(protocol[i]) ? "none" : protocol[i]));
 100 
 101             try {
 102                 /* spawn VM for EchoServer */
 103                 serverVM.start();
 104 
 105                 /* lookup server */
 106                 echo[i] = null;
 107                 // 24 seconds timeout
 108                 long stopTime = System.currentTimeMillis() + 24000;
 109                 do {
 110                     try {
 111                         echo[i] = (Echo) Naming.lookup("//:" + REGISTRY_PORT +
 112                                                        "/EchoServer");
 113                         break;
 114                     } catch (NotBoundException e) {
 115                         try {
 116                             Thread.sleep(200);
 117                         } catch (InterruptedException ignore) {
 118                         }
 119                     }
 120                 } while (System.currentTimeMillis() < stopTime);
 121 
 122                 if (echo[i] == null)
 123                     TestLibrary.bomb("server not bound in 120 tries", null);
 124 
 125                 /* invoke remote method and print result*/
 126                 System.err.println("Bound to " + echo[i]);
 127                 byte[] data = ("Greetings, citizen " +
 128                                System.getProperty("user.name") + "!"). getBytes();
 129                 byte[] result = echo[i].echoNot(data);
 130                 for (int j = 0; j < result.length; j++)
 131                     result[j] = (byte) ~result[j];
 132                 System.err.println("Result: " + new String(result));
 133                 echo[i].shutdown();
 134 
 135             } catch (Exception e) {
 136                 TestLibrary.bomb("test failed", e);
 137 
 138             } finally {
 139                 serverVM.destroy();
 140                 try {
 141                     Naming.unbind("//:" + REGISTRY_PORT + "/EchoServer");
 142                 } catch (RemoteException | NotBoundException | MalformedURLException e) {
 143                     TestLibrary.bomb("unbinding EchoServer", e);
 144                 }
 145             }
 146         }
 147         return echo;
 148     }
 149 
 150 
 151     private static void reactivateAndTest(Echo[] echo) {
 152 
 153         System.err.println("\nReactivate Test-->");
 154 
 155         for (int i = 0; i < echo.length; i++) {
 156             try {
 157                 System.err.println("\nusing protocol: " +
 158                            ("".equals(protocol[i]) ? "none" : protocol[i]));
 159                 byte[] data = ("Greetings, citizen " +
 160                                System.getProperty("user.name") + "!").getBytes();
 161                 byte[] result = echo[i].echoNot(data);


  26  * @key intermittent
  27  * @summary synopsis: cannot use socket factories with Activatable objects
  28  * @author Ann Wollrath
  29  *
  30  * @library ../../../../testlibrary
  31  * @modules java.rmi/sun.rmi.registry
  32  *          java.rmi/sun.rmi.server
  33  *          java.rmi/sun.rmi.transport
  34  *          java.rmi/sun.rmi.transport.tcp
  35  *          java.base/sun.nio.ch
  36  * @build TestLibrary Echo EchoImpl EchoImpl_Stub RMIDSelectorProvider
  37  * @run main/othervm/policy=security.policy/timeout=360 UseCustomSocketFactory
  38  */
  39 
  40 import java.io.*;
  41 import java.net.MalformedURLException;
  42 import java.rmi.*;
  43 import java.rmi.registry.*;
  44 
  45 public class UseCustomSocketFactory {
  46     static int registryPort = -1;
  47 
  48     static String[] protocol = new String[] { "", "compress", "xor" };
  49 
  50     public static void main(String[] args) {
  51 
  52         System.out.println("\nRegression test for bug 4115696\n");
  53 
  54         TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
  55 
  56         try {
  57             Registry reg = LocateRegistry.createRegistry(0);
  58             registryPort = TestLibrary.getRegistryPort(reg);
  59         } catch (RemoteException e) {
  60             TestLibrary.bomb("creating registry", e);
  61         }
  62 
  63         RMID rmid = null;
  64 
  65         try {
  66             rmid = RMID.createRMIDOnEphemeralPort();
  67             rmid.addArguments(new String[] {
  68                 "-C-Djava.security.policy=" +
  69                     TestParams.defaultGroupPolicy +
  70                     " -C-Djava.security.manager=java.rmi.RMISecurityManager "});
  71             rmid.start();
  72 
  73             Echo[] echo = spawnAndTest(rmid.getPort());
  74             reactivateAndTest(echo);
  75         } catch (IOException e) {
  76             TestLibrary.bomb("creating rmid", e);
  77         } finally {
  78             if (rmid != null)
  79                 rmid.destroy();
  80         }
  81     }
  82 
  83     private static Echo[] spawnAndTest(int rmidPort) {
  84 
  85         System.err.println("\nCreate Test-->");
  86 
  87         Echo[] echo = new Echo[protocol.length];
  88 
  89         for (int i = 0; i < protocol.length; i++) {
  90             JavaVM serverVM = new JavaVM("EchoImpl",
  91                                          "-Djava.security.policy=" +
  92                                          TestParams.defaultPolicy +
  93                                          " -Drmi.registry.port=" +
  94                                          registryPort +
  95                                          " -Djava.rmi.activation.port=" +
  96                                          rmidPort,
  97                                          protocol[i]);
  98 
  99             System.err.println("\nusing protocol: " +
 100                     ("".equals(protocol[i]) ? "none" : protocol[i]));
 101 
 102             try {
 103                 /* spawn VM for EchoServer */
 104                 serverVM.start();
 105 
 106                 /* lookup server */
 107                 echo[i] = null;
 108                 // 24 seconds timeout
 109                 long stopTime = System.currentTimeMillis() + 24000;
 110                 do {
 111                     try {
 112                         echo[i] = (Echo) Naming.lookup("//:" + registryPort +
 113                                                        "/EchoServer");
 114                         break;
 115                     } catch (NotBoundException e) {
 116                         try {
 117                             Thread.sleep(200);
 118                         } catch (InterruptedException ignore) {
 119                         }
 120                     }
 121                 } while (System.currentTimeMillis() < stopTime);
 122 
 123                 if (echo[i] == null)
 124                     TestLibrary.bomb("server not bound in 120 tries", null);
 125 
 126                 /* invoke remote method and print result*/
 127                 System.err.println("Bound to " + echo[i]);
 128                 byte[] data = ("Greetings, citizen " +
 129                                System.getProperty("user.name") + "!"). getBytes();
 130                 byte[] result = echo[i].echoNot(data);
 131                 for (int j = 0; j < result.length; j++)
 132                     result[j] = (byte) ~result[j];
 133                 System.err.println("Result: " + new String(result));
 134                 echo[i].shutdown();
 135 
 136             } catch (Exception e) {
 137                 TestLibrary.bomb("test failed", e);
 138 
 139             } finally {
 140                 serverVM.destroy();
 141                 try {
 142                     Naming.unbind("//:" + registryPort + "/EchoServer");
 143                 } catch (RemoteException | NotBoundException | MalformedURLException e) {
 144                     TestLibrary.bomb("unbinding EchoServer", e);
 145                 }
 146             }
 147         }
 148         return echo;
 149     }
 150 
 151 
 152     private static void reactivateAndTest(Echo[] echo) {
 153 
 154         System.err.println("\nReactivate Test-->");
 155 
 156         for (int i = 0; i < echo.length; i++) {
 157             try {
 158                 System.err.println("\nusing protocol: " +
 159                            ("".equals(protocol[i]) ? "none" : protocol[i]));
 160                 byte[] data = ("Greetings, citizen " +
 161                                System.getProperty("user.name") + "!").getBytes();
 162                 byte[] result = echo[i].echoNot(data);
< prev index next >