Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/TestGCLogRotationViaJcmd.java
32281 views
/*1* Copyright (c) 2014, 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* @test TestGCLogRotationViaJcmd.java25* @bug 709032426* @summary test for gc log rotation via jcmd27* @library /testlibrary28* @run main/othervm -Xloggc:test.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=3 TestGCLogRotationViaJcmd29*30*/31import com.oracle.java.testlibrary.*;32import java.io.File;33import java.io.FilenameFilter;3435public class TestGCLogRotationViaJcmd {3637static final File currentDirectory = new File(".");38static final String LOG_FILE_NAME = "test.log";39static final int NUM_LOGS = 3;4041static FilenameFilter logFilter = new FilenameFilter() {42@Override43public boolean accept(File dir, String name) {44return name.startsWith(LOG_FILE_NAME);45}46};4748public static void main(String[] args) throws Exception {49// Grab the pid from the current java process50String pid = Integer.toString(ProcessTools.getProcessId());5152// Create a JDKToolLauncher53JDKToolLauncher jcmd = JDKToolLauncher.create("jcmd")54.addToolArg(pid)55.addToolArg("GC.rotate_log");5657for (int times = 1; times < NUM_LOGS; times++) {58// Run jcmd <pid> GC.rotate_log59ProcessBuilder pb = new ProcessBuilder(jcmd.getCommand());6061// Make sure we didn't crash62OutputAnalyzer output = new OutputAnalyzer(pb.start());63output.shouldHaveExitValue(0);64}6566// GC log check67File[] logs = currentDirectory.listFiles(logFilter);68if (logs.length != NUM_LOGS) {69throw new Error("There are only " + logs.length70+ " logs instead " + NUM_LOGS);71}7273}7475}76777879