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..b6dc7ae0 --- /dev/null +++ b/IT/src/test/java/com/microsoft/gctoolkit/integration/DirtyDataIntegrationTest.java @@ -0,0 +1,52 @@ +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 an empty file that contains nothing + */ + @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"); + } } /**