< prev index next >

test/hotspot/jtreg/runtime/cds/ServiceLoaderTest.java

Print this page


  84 
  85     static void mismatch(int i, String s1, String s2) {
  86         System.out.println("Mismatched line: " + i);
  87         System.out.println("cds on : " + s1);
  88         System.out.println("cds off: " + s2);
  89         throw new RuntimeException("Mismatched line " + i + ": \"" + s1 + "\" vs \"" + s2 + "\"");
  90     }
  91 }
  92 
  93 class ServiceLoaderApp {
  94     public static void main(String args[]) throws Exception {
  95         doTest(ToolProvider.class);
  96         doTest(InitialContextFactory.class);
  97     }
  98 
  99     static void doTest(Class c) throws Exception {
 100         System.out.println("============================================================");
 101         System.out.println("Testing : " + c.getName());
 102         System.out.println("============================================================");
 103 
 104         dump("default",         ServiceLoader.load(c));
 105         dump("null loader",     ServiceLoader.load(c, null));
 106         dump("platform loader", ServiceLoader.load(c, ServiceLoaderApp.class.getClassLoader().getParent()));
 107         dump("system loader",   ServiceLoader.load(c, ServiceLoaderApp.class.getClassLoader()));
 108     }
 109 
 110     static void dump(String testCase, ServiceLoader loader) throws Exception {
 111         System.out.println("[TEST CASE] " + testCase);
 112         System.out.println("[svcloader] " + asString(loader));
 113         Iterator it = loader.iterator();
 114         ArrayList<String> list = new ArrayList<>();
 115         while (it.hasNext()) {
 116             list.add(asString(it.next().toString()));
 117         }
 118         Collections.sort(list);
 119         for (String s : list) {
 120             System.out.println(s);
 121         }
 122     }
 123 
 124     static String asString(Object o) {
 125         String s = o.toString();
 126         int n = s.indexOf("@");
 127         if (n >= 0) {
 128             s = s.substring(0, n);
 129         }
 130         return s;


  84 
  85     static void mismatch(int i, String s1, String s2) {
  86         System.out.println("Mismatched line: " + i);
  87         System.out.println("cds on : " + s1);
  88         System.out.println("cds off: " + s2);
  89         throw new RuntimeException("Mismatched line " + i + ": \"" + s1 + "\" vs \"" + s2 + "\"");
  90     }
  91 }
  92 
  93 class ServiceLoaderApp {
  94     public static void main(String args[]) throws Exception {
  95         doTest(ToolProvider.class);
  96         doTest(InitialContextFactory.class);
  97     }
  98 
  99     static void doTest(Class c) throws Exception {
 100         System.out.println("============================================================");
 101         System.out.println("Testing : " + c.getName());
 102         System.out.println("============================================================");
 103 
 104         print_loader("default",         ServiceLoader.load(c));
 105         print_loader("null loader",     ServiceLoader.load(c, null));
 106         print_loader("platform loader", ServiceLoader.load(c, ServiceLoaderApp.class.getClassLoader().getParent()));
 107         print_loader("system loader",   ServiceLoader.load(c, ServiceLoaderApp.class.getClassLoader()));
 108     }
 109 
 110     static void print_loader(String testCase, ServiceLoader loader) throws Exception {
 111         System.out.println("[TEST CASE] " + testCase);
 112         System.out.println("[svcloader] " + asString(loader));
 113         Iterator it = loader.iterator();
 114         ArrayList<String> list = new ArrayList<>();
 115         while (it.hasNext()) {
 116             list.add(asString(it.next().toString()));
 117         }
 118         Collections.sort(list);
 119         for (String s : list) {
 120             System.out.println(s);
 121         }
 122     }
 123 
 124     static String asString(Object o) {
 125         String s = o.toString();
 126         int n = s.indexOf("@");
 127         if (n >= 0) {
 128             s = s.substring(0, n);
 129         }
 130         return s;
< prev index next >