1 /* 2 * Copyright (c) 2016, 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 * @test 26 * @library /lib/testlibrary 27 * @modules jdk.compiler 28 * @build CacheTest CompilerUtils jdk.testlibrary.* 29 * @run testng CacheTest 30 */ 31 32 import java.io.File; 33 import java.nio.file.Files; 34 import java.nio.file.Path; 35 import java.nio.file.Paths; 36 37 import jdk.testlibrary.OutputAnalyzer; 38 import static jdk.testlibrary.ProcessTools.*; 39 40 import org.testng.annotations.BeforeTest; 41 import org.testng.annotations.Test; 42 import static org.testng.Assert.*; 43 44 45 @Test 46 public class CacheTest { 47 48 private static final String TEST_SRC = System.getProperty("test.src"); 49 50 private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); 51 private static final Path MODS_DIR = Paths.get("mods"); 52 53 private static final String TEST_MODULE = "test"; 54 private static final String MAIN_BUNDLES_MODULE = "mainbundles"; 55 56 private static final String MAIN = "test/jdk.test.Main"; 57 private static final String MAIN_CLASS = "jdk.test.Main"; 58 59 @BeforeTest 60 public void compileTestModules() throws Exception { 61 62 for (String mn : new String[] {MAIN_BUNDLES_MODULE, TEST_MODULE}) { 63 boolean compiled = 64 CompilerUtils.compile(SRC_DIR.resolve(mn), 65 MODS_DIR.resolve(mn), 66 "--module-path", MODS_DIR.toString()); 67 assertTrue(compiled, "module " + mn + " did not compile"); 68 } 69 70 Path res = Paths.get("jdk", "test", "resources", "MyResources.properties"); 71 Path dest = MODS_DIR.resolve(MAIN_BUNDLES_MODULE).resolve(res); 72 Files.createDirectories(dest.getParent()); 73 Files.copy(SRC_DIR.resolve(MAIN_BUNDLES_MODULE).resolve(res), dest); 74 } 75 76 /** 77 * Load resource bundle in cache first. Verify that the subsequent 78 * loading of ResourceBundle from another module will not get it from cache. 79 */ 80 @Test 81 public void loadCacheFirst() throws Exception { 82 assertTrue(executeTestJava("--module-path", MODS_DIR.toString(), 83 "-m", MAIN, "cache") 84 .outputTo(System.out) 85 .errorTo(System.out) 86 .getExitValue() == 0); 87 88 assertTrue(executeTestJava("--class-path", MODS_DIR.resolve(TEST_MODULE).toString(), 89 "--module-path", MODS_DIR.resolve(MAIN_BUNDLES_MODULE).toString(), 90 "--add-modules", MAIN_BUNDLES_MODULE, 91 MAIN_CLASS, "cache") 92 .outputTo(System.out) 93 .errorTo(System.out) 94 .getExitValue() == 0); 95 } 96 97 /** 98 * Load non-existent resource bundle in cache first. Verify that 99 * the subsequent loading of ResourceBundle from another module 100 * can still successfully load the bundle. 101 */ 102 @Test 103 public void loadNonExistentBundleInCache() throws Exception { 104 assertTrue(executeTestJava("--module-path", MODS_DIR.toString(), 105 "-m", MAIN) 106 .outputTo(System.out) 107 .errorTo(System.out) 108 .getExitValue() == 0); 109 110 assertTrue(executeTestJava("--class-path", MODS_DIR.resolve(TEST_MODULE).toString(), 111 "--module-path", MODS_DIR.resolve(MAIN_BUNDLES_MODULE).toString(), 112 "--add-modules", MAIN_BUNDLES_MODULE, 113 MAIN_CLASS) 114 .outputTo(System.out) 115 .errorTo(System.out) 116 .getExitValue() == 0); 117 } 118 }