< prev index next >

test/hotspot/jtreg/serviceability/logging/TestLogRotation.java

Print this page
rev 58959 : [mq]: 8243568


  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 TestLogRotation.java
  26  * @summary test flags for log rotation
  27  * @library /test/lib
  28  * @modules java.base/jdk.internal.misc
  29  *          java.management
  30  * @run main/othervm/timeout=600 TestLogRotation
  31  *
  32  */
  33 import jdk.test.lib.process.ProcessTools;
  34 import java.io.File;
  35 import java.io.FilenameFilter;
  36 import java.util.ArrayList;
  37 import java.util.Arrays;
  38 
  39 class GCLoggingGenerator {
  40 
  41     public static void main(String[] args) throws Exception {
  42 
  43         long sizeOfLog = Long.parseLong(args[0]);
  44         long lines = sizeOfLog / 70;
  45         // full.GC generates ad least 1-line which is not shorter then 70 chars
  46         // for some GC 2 shorter lines are generated
  47         for (long i = 0; i < lines; i++) {
  48             System.gc();
  49         }
  50     }


  61             return name.startsWith(logFileName);
  62         }
  63     };
  64 
  65     public static void cleanLogs() {
  66         for (File log : currentDirectory.listFiles(logFilter)) {
  67             if (!log.delete()) {
  68                 throw new Error("Unable to delete " + log.getAbsolutePath());
  69             }
  70         }
  71     }
  72 
  73     public static void runTest(int numberOfFiles) throws Exception {
  74 
  75         ArrayList<String> args = new ArrayList();
  76         String[] logOpts = new String[]{
  77             "-cp", System.getProperty("java.class.path"),
  78             "-Xlog:gc=debug:" + logFileName + "::filesize=" + logFileSizeK + "k,filecount=" + numberOfFiles,
  79             "-XX:-DisableExplicitGC", // to ensure that System.gc() works
  80             "-Xmx128M"};
  81         // System.getProperty("test.java.opts") is '' if no options is set
  82         // need to skip such empty
  83         String[] externalVMopts = System.getProperty("test.java.opts").length() == 0
  84                 ? new String[0]
  85                 : System.getProperty("test.java.opts").split(" ");
  86         args.addAll(Arrays.asList(externalVMopts));
  87         args.addAll(Arrays.asList(logOpts));
  88         args.add(GCLoggingGenerator.class.getName());
  89         args.add(String.valueOf(numberOfFiles * logFileSizeK * 1024));
  90         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args.toArray(new String[0]));
  91         pb.redirectErrorStream(true);
  92         pb.redirectOutput(new File(GCLoggingGenerator.class.getName() + ".log"));
  93         Process process = pb.start();
  94         int result = process.waitFor();
  95         if (result != 0) {
  96             throw new Error("Unexpected exit code = " + result);
  97         }
  98         File[] logs = currentDirectory.listFiles(logFilter);
  99         int smallFilesNumber = 0;
 100         for (File log : logs) {
 101             if (log.length() < logFileSizeK * 1024) {
 102                 smallFilesNumber++;
 103             }
 104         }
 105         // Expect one more log file since the number-of-files doesn't include the active log file
 106         int expectedNumberOfFiles = numberOfFiles + 1;
 107         if (logs.length != expectedNumberOfFiles) {
 108             throw new Error("There are " + logs.length + " logs instead of the expected " + expectedNumberOfFiles);
 109         }
 110         if (smallFilesNumber > 1) {


  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 TestLogRotation.java
  26  * @summary test flags for log rotation
  27  * @library /test/lib
  28  * @modules java.base/jdk.internal.misc
  29  *          java.management
  30  * @run driver/timeout=600 TestLogRotation
  31  *
  32  */
  33 import jdk.test.lib.process.ProcessTools;
  34 import java.io.File;
  35 import java.io.FilenameFilter;
  36 import java.util.ArrayList;
  37 import java.util.Arrays;
  38 
  39 class GCLoggingGenerator {
  40 
  41     public static void main(String[] args) throws Exception {
  42 
  43         long sizeOfLog = Long.parseLong(args[0]);
  44         long lines = sizeOfLog / 70;
  45         // full.GC generates ad least 1-line which is not shorter then 70 chars
  46         // for some GC 2 shorter lines are generated
  47         for (long i = 0; i < lines; i++) {
  48             System.gc();
  49         }
  50     }


  61             return name.startsWith(logFileName);
  62         }
  63     };
  64 
  65     public static void cleanLogs() {
  66         for (File log : currentDirectory.listFiles(logFilter)) {
  67             if (!log.delete()) {
  68                 throw new Error("Unable to delete " + log.getAbsolutePath());
  69             }
  70         }
  71     }
  72 
  73     public static void runTest(int numberOfFiles) throws Exception {
  74 
  75         ArrayList<String> args = new ArrayList();
  76         String[] logOpts = new String[]{
  77             "-cp", System.getProperty("java.class.path"),
  78             "-Xlog:gc=debug:" + logFileName + "::filesize=" + logFileSizeK + "k,filecount=" + numberOfFiles,
  79             "-XX:-DisableExplicitGC", // to ensure that System.gc() works
  80             "-Xmx128M"};






  81         args.addAll(Arrays.asList(logOpts));
  82         args.add(GCLoggingGenerator.class.getName());
  83         args.add(String.valueOf(numberOfFiles * logFileSizeK * 1024));
  84         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, args.toArray(String[]::new));
  85         pb.redirectErrorStream(true);
  86         pb.redirectOutput(new File(GCLoggingGenerator.class.getName() + ".log"));
  87         Process process = pb.start();
  88         int result = process.waitFor();
  89         if (result != 0) {
  90             throw new Error("Unexpected exit code = " + result);
  91         }
  92         File[] logs = currentDirectory.listFiles(logFilter);
  93         int smallFilesNumber = 0;
  94         for (File log : logs) {
  95             if (log.length() < logFileSizeK * 1024) {
  96                 smallFilesNumber++;
  97             }
  98         }
  99         // Expect one more log file since the number-of-files doesn't include the active log file
 100         int expectedNumberOfFiles = numberOfFiles + 1;
 101         if (logs.length != expectedNumberOfFiles) {
 102             throw new Error("There are " + logs.length + " logs instead of the expected " + expectedNumberOfFiles);
 103         }
 104         if (smallFilesNumber > 1) {
< prev index next >