On Fri, 18 Dec 2020 14:59:06 GMT, Andy Herrick <herr...@openjdk.org> wrote:

> I have had problems with test infrastructure fixing the workDir based on test 
> class and method, and then getting IOExceptions as various PackageTest's try 
> to write the same content to the same work dir

I don't think we need changes to test infrastructure to run PackageTest 
instances concurrently.

This is how to create input for jpackage: 
final Path inputDir = TKit.workDir().resolve("input");
HelloApp.createBundle(JavaAppDesc.parse("hellp.jar:Hello"), inputDir);

This is the function to initialize PackegTest instance that will use hello.jar 
initialized above to build a package and write output in unique directory 
inside of test work directory:
private PackageTest initTest(Path inputDir, bool useToolProvider) {
    // Just in case if TKit.createTempDirectory is not reliable enough to be 
executed concurrently
    final Path outputDir;
    synchronized (this) {
        outputDir = TKit.createTempDirectory("output");
    }
    return new PackageTest()
        .addInitializer(cmd -> {
            cmd.useToolProvider(useToolProvider);
            cmd.setArgumentValue("--input", inoutDir);
            cmd.setArgumentValue("--main-class", "Hello");
            cmd.setArgumentValue("--dest", outputDir);
        });
}

Glue it all together:
@Test
@Parameter("true")
@Parameter("false")
public void testIt(bool useToolProvider) {
    final Path inputDir = TKit.workDir().resolve("input");
    HelloApp.createBundle(JavaAppDesc.parse("hellp.jar:Hello"), inputDir);

   final int TEST_COUNT = 5;
    List<Runnable> tasks = new ArrayList<>();
    for (int i = 0; i != TEST_COUNT; i++) {
        tests.push(ThrowingRunnable.toRunnable(() -> initTest(inputDir, 
useToolProvider).run(PackageTest.Action.CREATE)));
    }

    ExecutorService exec = Executors.newCachedThreadPool();
    tasks.stream().forEach(exec::execute);
    exec.shutdown();
}

-------------

PR: https://git.openjdk.java.net/jdk/pull/1829

Reply via email to