1 /* 2 * Copyright (c) 2015, 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 import java.time.LocalDate; 25 import java.time.format.DateTimeFormatter; 26 import java.time.format.DateTimeParseException; 27 import java.util.regex.Matcher; 28 import java.util.regex.Pattern; 29 30 import com.oracle.java.testlibrary.Asserts; 31 32 /* 33 * @test TestPrintGCDateStampsEnabled 34 * @summary test checks -XX:+PrintGCDateStamps enables date stamps printing 35 * @key gc 36 * @library /testlibrary 37 * @run main/othervm -Xmx128M -Xloggc:PrintGCDateStampsEnabled.txt -XX:+PrintGC -XX:+PrintGCDateStamps GCTask 38 * @run main TestPrintGCDateStampsEnabled 39 */ 40 public class TestPrintGCDateStampsEnabled extends AbstractPrintGCTest { 41 42 public void runTest() { 43 String content = getContent(); 44 // match an every line containing '[GC' and capture everything before the first 45 // colon followed by space 46 Pattern pattern = Pattern.compile("^(.+?): +?.*\\[GC", Pattern.MULTILINE); 47 Matcher matcher = pattern.matcher(content); 48 LocalDate gcLastDateStamp = LocalDate.MIN; 49 while (matcher.find()) { 50 String match = matcher.group(1); 51 try { 52 LocalDate dateStamp = LocalDate.parse( 53 match, DateTimeFormatter.ofPattern( 54 "yyyy-MM-dd'T'HH:mm:ss.SSSxxxx")); 55 Asserts.assertGreaterThanOrEqual(dateStamp, gcLastDateStamp, 56 "GC datestamps are inconsistent"); 57 } catch (DateTimeParseException e) { 58 Asserts.assertFalse(true, "The text '" + match + "' is not a valid GC's DateStamp"); 59 } 60 } 61 } 62 63 public static void main(String[] args) { 64 new TestPrintGCDateStampsEnabled().runTest(); 65 } 66 }