Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #359: fix NPE when parsing gc log file without any events #409

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
initial patch
Lmh-java committed Jan 6, 2025
commit ab52fb1bfbd65fb3c0a13874c264d636be98ae2f
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}

/**