--- /dev/null 2015-01-17 02:57:05.640001672 +0300 +++ new/test/gc/logging/TestPrintGCDateStampsEnabled.java 2015-01-20 17:14:18.903416178 +0300 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.oracle.java.testlibrary.Asserts; + +/* + * @test TestPrintGCDateStampsEnabled + * @summary test checks -XX:+PrintGCDateStamps enables date stamps printing + * @key gc + * @library /testlibrary + * @run main/othervm -Xmx128M -Xloggc:PrintGCDateStampsEnabled.txt -XX:+PrintGC -XX:+PrintGCDateStamps GCTask + * @run main TestPrintGCDateStampsEnabled + */ +public class TestPrintGCDateStampsEnabled extends AbstractPrintGCTest { + + public void runTest() { + String content = getContent(); + // match an every line containing '[GC' and capture everything before the first + // colon followed by space + Pattern pattern = Pattern.compile("^(.+?): +?.*\\[GC", Pattern.MULTILINE); + Matcher matcher = pattern.matcher(content); + LocalDate gcLastDateStamp = LocalDate.MIN; + while (matcher.find()) { + String match = matcher.group(1); + try { + LocalDate dateStamp = LocalDate.parse( + match, DateTimeFormatter.ofPattern( + "yyyy-MM-dd'T'HH:mm:ss.SSSxxxx")); + Asserts.assertGreaterThanOrEqual(dateStamp, gcLastDateStamp, + "GC datestamps are inconsistent"); + } catch (DateTimeParseException e) { + Asserts.assertFalse(true, "The text '" + match + "' is not a valid GC's DateStamp"); + } + } + } + + public static void main(String[] args) { + new TestPrintGCDateStampsEnabled().runTest(); + } +}