1 /* 2 * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 import java.io.File; 26 import java.nio.file.Path; 27 import java.util.Map; 28 import jdk.test.lib.StringArrayUtils; 29 import jdk.test.lib.artifacts.Artifact; 30 import jdk.test.lib.artifacts.ArtifactResolver; 31 import jdk.test.lib.cds.CDSAppTester; 32 import jdk.test.lib.process.OutputAnalyzer; 33 34 /* 35 * @test id=static 36 * @key external-dep 37 * @requires vm.cds 38 * @summary run MicronautFirstApp with the classic static archive workflow 39 * @library /test/lib 40 * @run driver/timeout=120 MicronautFirstApp STATIC 41 */ 42 43 /* 44 * @test id=dynamic 45 * @key external-dep 46 * @requires vm.cds 47 * @summary run MicronautFirstApp with the classic dynamic archive workflow 48 * @library /test/lib 49 * @run driver/timeout=120 MicronautFirstApp DYNAMIC 50 */ 51 52 /* 53 * @test id=leyden 54 * @key external-dep 55 * @requires vm.cds 56 * @requires vm.cds.write.archived.java.heap 57 * @summary un MicronautFirstApp with the Leyden workflow 58 * @library /test/lib 59 * @run driver/timeout=120 MicronautFirstApp LEYDEN 60 */ 61 62 /* 63 * @test id=leyden_old 64 * @key external-dep 65 * @requires vm.cds 66 * @requires vm.cds.write.archived.java.heap 67 * @summary un MicronautFirstApp with the "OLD" Leyden workflow 68 * @library /test/lib 69 * @run driver/timeout=120 MicronautFirstApp LEYDEN_OLD 70 */ 71 72 // Test CDS with the example program in https://guides.micronaut.io/latest/creating-your-first-micronaut-app-maven-java.html 73 // 74 // NOTE: if you have not set up an artifactory, you can create micronaut-first-app-1.0.0.zip 75 // 76 // - Make a clone of https://github.com/openjdk/leyden/tree/premain 77 // - Change to the directory test/hotspot/jtreg/premain/micronaut-first-app 78 // - Edit the Makefile and ../lib/DemoSupport.gmk as necessary 79 // - Run the command "make artifact" 80 // 81 // Then, you can add the following to your jtreg command-line to run the test cases in this directory: 82 // -vmoption:-Djdk.test.lib.artifacts.micronaut-first-app=/my/repo/test/hotspot/jtreg/premain/micronaut-first-app/download/target/ 83 84 @Artifact(organization = "io.micronaut", name = "micronaut-first-app", revision = "1.0.0", extension = "zip") 85 public class MicronautFirstApp { 86 public static void main(String args[]) throws Exception { 87 String cp = getArtifact(); 88 MicronautFirstAppTester tester = new MicronautFirstAppTester(cp); 89 tester.run(args); 90 System.out.println(cp); 91 } 92 93 private static String getArtifact() throws Exception { 94 Map<String, Path> artifacts = ArtifactResolver.resolve(MicronautFirstApp.class); 95 Path path = artifacts.get("io.micronaut.micronaut-first-app-1.0.0"); 96 return path.toString() + File.separator + "default-0.1.jar"; 97 } 98 99 static class MicronautFirstAppTester extends CDSAppTester { 100 String cp; 101 102 MicronautFirstAppTester(String cp) { 103 super("MicronautFirstApp"); 104 this.cp = cp; 105 } 106 107 @Override 108 public String[] vmArgs(RunMode runMode) { 109 return new String[] { 110 "-DautoQuit=true", 111 "-Dmicronaut.server.port=0", // use system-assigned port 112 113 // This program may run very slowly in debug builds if VerifyDependencies is enabled. 114 "-XX:+IgnoreUnrecognizedVMOptions", "-XX:-VerifyDependencies", 115 }; 116 } 117 118 @Override 119 public String classpath(RunMode runMode) { 120 return cp; 121 } 122 123 @Override 124 public String[] appCommandLine(RunMode runMode) { 125 String cmdLine[] = new String[] { 126 "example.micronaut.Application", 127 }; 128 129 if (runMode.isProductionRun()) { 130 cmdLine = StringArrayUtils.concat("-Xlog:scc=error", cmdLine); 131 } 132 return cmdLine; 133 } 134 135 @Override 136 public void checkExecution(OutputAnalyzer out, RunMode runMode) { 137 if (!runMode.isStaticDump()) { 138 out.shouldContain("Booted and returned in "); 139 } 140 } 141 } 142 }