< prev index next >

test/jdk/java/lang/ClassLoader/loadLibraryUnload/LoadLibraryUnloadTest.java

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
   * Copyright (c) 2021, BELLSOFT. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
--- 1,7 ---
  /*
!  * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
   * Copyright (c) 2021, BELLSOFT. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as

*** 36,35 ***
   * @build LoadLibraryUnload p.Class1
   * @run main/othervm/native LoadLibraryUnloadTest
   */
  
  import jdk.test.lib.Asserts;
- import jdk.test.lib.JDKToolFinder;
  import jdk.test.lib.process.OutputAnalyzer;
  
! import java.lang.ProcessBuilder;
- import java.lang.Process;
- import java.io.File;
- import java.util.*;
  
  public class LoadLibraryUnloadTest {
  
      private static String testClassPath = System.getProperty("test.classes");
      private static String testLibraryPath = System.getProperty("test.nativepath");
  
-     private static Process runJavaCommand(String... command) throws Throwable {
-         String java = JDKToolFinder.getJDKTool("java");
-         List<String> commands = new ArrayList<>();
-         Collections.addAll(commands, java);
-         Collections.addAll(commands, command);
-         System.out.println("COMMAND: " + String.join(" ", commands));
-         return new ProcessBuilder(commands.toArray(new String[0]))
-                 .redirectErrorStream(true)
-                 .directory(new File(testClassPath))
-                 .start();
-     }
- 
      private final static long countLines(OutputAnalyzer output, String string) {
          return output.asLines()
                       .stream()
                       .filter(s -> s.contains(string))
                       .count();
--- 36,19 ---
   * @build LoadLibraryUnload p.Class1
   * @run main/othervm/native LoadLibraryUnloadTest
   */
  
  import jdk.test.lib.Asserts;
  import jdk.test.lib.process.OutputAnalyzer;
  
! import static jdk.test.lib.process.ProcessTools.*;
  
  public class LoadLibraryUnloadTest {
  
      private static String testClassPath = System.getProperty("test.classes");
      private static String testLibraryPath = System.getProperty("test.nativepath");
  
      private final static long countLines(OutputAnalyzer output, String string) {
          return output.asLines()
                       .stream()
                       .filter(s -> s.contains(string))
                       .count();

*** 76,16 ***
                .forEach(s -> System.out.println(s));
      }
  
      public static void main(String[] args) throws Throwable {
  
!         Process process = runJavaCommand(
                  "-Dtest.classes=" + testClassPath,
                  "-Djava.library.path=" + testLibraryPath,
!                 "LoadLibraryUnload");
- 
-         OutputAnalyzer outputAnalyzer = new OutputAnalyzer(process);
          dump(outputAnalyzer);
  
          Asserts.assertTrue(
                  countLines(outputAnalyzer, "Native library loaded from Class1.") == 2,
                  "Native library expected to be loaded in 2 threads.");
--- 60,14 ---
                .forEach(s -> System.out.println(s));
      }
  
      public static void main(String[] args) throws Throwable {
  
!         OutputAnalyzer outputAnalyzer = executeCommand(createTestJavaProcessBuilder(
                  "-Dtest.classes=" + testClassPath,
                  "-Djava.library.path=" + testLibraryPath,
!                 "LoadLibraryUnload"));
          dump(outputAnalyzer);
  
          Asserts.assertTrue(
                  countLines(outputAnalyzer, "Native library loaded from Class1.") == 2,
                  "Native library expected to be loaded in 2 threads.");
< prev index next >