From ab52fb1bfbd65fb3c0a13874c264d636be98ae2f Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Sun, 5 Jan 2025 19:37:43 -0500 Subject: [PATCH 1/2] initial patch --- .../integration/DirtyDataIntegrationTest.java | 49 +++++++++++++++++++ .../gctoolkit/parser/GCLogParser.java | 4 ++ 2 files changed, 53 insertions(+) create mode 100644 IT/src/test/java/com/microsoft/gctoolkit/integration/DirtyDataIntegrationTest.java diff --git a/IT/src/test/java/com/microsoft/gctoolkit/integration/DirtyDataIntegrationTest.java b/IT/src/test/java/com/microsoft/gctoolkit/integration/DirtyDataIntegrationTest.java new file mode 100644 index 00000000..189b4db2 --- /dev/null +++ b/IT/src/test/java/com/microsoft/gctoolkit/integration/DirtyDataIntegrationTest.java @@ -0,0 +1,49 @@ +package com.microsoft.gctoolkit.integration; + +import com.microsoft.gctoolkit.GCToolKit; +import com.microsoft.gctoolkit.integration.aggregation.CollectionCycleCountsSummary; +import com.microsoft.gctoolkit.integration.io.TestLogFile; +import com.microsoft.gctoolkit.io.GCLogFile; +import com.microsoft.gctoolkit.io.SingleGCLogFile; +import com.microsoft.gctoolkit.parser.GenerationalHeapParser; +import com.microsoft.gctoolkit.vertx.VertxDataSourceChannel; +import com.microsoft.gctoolkit.vertx.VertxJVMEventChannel; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.nio.file.Path; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +@Tag("classPath") +public class DirtyDataIntegrationTest { + + /** + * Test a GC log file that contains only the header but no actual events + */ + @Test + public void testNoEventLog() { + Path path = new TestLogFile("streaming/gc_no_event.log").getFile().toPath(); + assertThrows(IllegalStateException.class, () -> analyze(path.toString())); + } + + @Test + public void testEmptyFile() { + Path path = new TestLogFile("streaming/gc_empty.log").getFile().toPath(); + assertThrows(IllegalStateException.class, () -> analyze(path.toString())); + } + + public void analyze(String gcLogFile) throws IOException { + GCLogFile logFile = new SingleGCLogFile(Path.of(gcLogFile)); + GCToolKit gcToolKit = new GCToolKit(); + + gcToolKit.loadDataSourceChannel(new VertxDataSourceChannel()); + gcToolKit.loadJVMEventChannel(new VertxJVMEventChannel()); + gcToolKit.loadDataSourceParser(new GenerationalHeapParser()); + + gcToolKit.loadAggregation(new CollectionCycleCountsSummary()); + + gcToolKit.analyze(logFile); + } +} diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/GCLogParser.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/GCLogParser.java index 6dcd1078..b2f5d7aa 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/GCLogParser.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/GCLogParser.java @@ -53,6 +53,10 @@ public GCLogParser() {} public void diary(Diary diary) { this.diary = diary; this.clock = diary.getTimeOfFirstEvent(); + if (this.clock == null) { + LOGGER.log(Level.SEVERE, "Time of first event is null, are there any events presented in the log file?"); + throw new IllegalStateException("Missing log events"); + } } /** From 9ee7fa33eca3b0309ca86ceb59bc667e0372e5de Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Sun, 5 Jan 2025 20:35:32 -0500 Subject: [PATCH 2/2] enhance test --- .../gctoolkit/integration/DirtyDataIntegrationTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/IT/src/test/java/com/microsoft/gctoolkit/integration/DirtyDataIntegrationTest.java b/IT/src/test/java/com/microsoft/gctoolkit/integration/DirtyDataIntegrationTest.java index 189b4db2..b6dc7ae0 100644 --- a/IT/src/test/java/com/microsoft/gctoolkit/integration/DirtyDataIntegrationTest.java +++ b/IT/src/test/java/com/microsoft/gctoolkit/integration/DirtyDataIntegrationTest.java @@ -28,6 +28,9 @@ public void testNoEventLog() { assertThrows(IllegalStateException.class, () -> analyze(path.toString())); } + /** + * Test an empty file that contains nothing + */ @Test public void testEmptyFile() { Path path = new TestLogFile("streaming/gc_empty.log").getFile().toPath();