Path: blob/master/test/hotspot/jtreg/serviceability/attach/RemovingUnixDomainSocketTest.java
41149 views
/*1* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 822519326* @requires os.family != "windows"27* @library /test/lib28* @run main RemovingUnixDomainSocketTest29*/3031import java.io.File;32import java.io.IOException;33import java.nio.file.Path;34import java.util.concurrent.TimeUnit;3536import jdk.test.lib.Utils;37import jdk.test.lib.apps.LingeredApp;38import jdk.test.lib.JDKToolLauncher;39import jdk.test.lib.process.OutputAnalyzer;40import jdk.test.lib.process.ProcessTools;4142public class RemovingUnixDomainSocketTest {4344// timeout (in seconds)45private static final long timeout = Utils.adjustTimeout(60);4647private static void runJCmd(long pid) throws InterruptedException, IOException {48JDKToolLauncher jcmd = JDKToolLauncher.createUsingTestJDK("jcmd");49jcmd.addVMArgs(Utils.getFilteredTestJavaOpts("-showversion"));50jcmd.addToolArg(Long.toString(pid));51jcmd.addToolArg("VM.version");5253ProcessBuilder pb = new ProcessBuilder(jcmd.getCommand());54Process jcmdProc = pb.start();5556OutputAnalyzer out = new OutputAnalyzer(jcmdProc);5758if (!jcmdProc.waitFor(timeout, TimeUnit.SECONDS)) {59log("jcmd is still running after " + timeout + " seconds, terminating...");60jcmdProc.destroy();61jcmdProc.waitFor();62}6364log("jcmd stdout: [" + out.getStdout() + "];\n" +65"jcmd stderr: [" + out.getStderr() + "]\n" +66"jcmd exitValue = " + out.getExitValue());6768out.shouldHaveExitValue(0);69out.stderrShouldBeEmptyIgnoreDeprecatedWarnings();70}7172public static void main(String... args) throws Exception {73LingeredApp app = null;74try {75app = LingeredApp.startApp();7677// Access to Attach Listener78runJCmd(app.getPid());7980// Remove unix domain socket file81File sockFile = Path.of(System.getProperty("java.io.tmpdir"),82".java_pid" + app.getPid())83.toFile();84log("Remove " + sockFile.toString());85sockFile.delete();8687// Access to Attach Listener again88runJCmd(app.getPid());89} finally {90LingeredApp.stopApp(app);91}92}9394static void log(Object s) {95System.out.println(String.valueOf(s));96}97}9899100