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

test(recordings): Verify file contents from RecordingWorkflowIT #619

Merged
merged 3 commits into from
Aug 4, 2021
Merged
Changes from all commits
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
36 changes: 30 additions & 6 deletions src/test/java/itest/RecordingWorkflowIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
*/
package itest;

import java.io.File;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

Expand All @@ -46,8 +48,13 @@
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import itest.bases.StandardSelfTest;
import jdk.jfr.consumer.RecordedEvent;
import jdk.jfr.consumer.RecordingFile;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -196,7 +203,7 @@ public void testWorkflow() throws Exception {
MatcherAssert.assertThat(recordingInfo.getInteger("duration"), Matchers.equalTo(5_000));

// verify in-memory and saved recordings can be downloaded successfully and yield
// non-empty recording binaries (TODO: better verification of file content), and that
// non-empty recording binaries containing events, and that
// the fully completed in-memory recording is larger than the saved partial copy
String inMemoryDownloadUrl = recordingInfo.getString("downloadUrl");
Path inMemoryDownloadPath =
Expand All @@ -208,17 +215,34 @@ public void testWorkflow() throws Exception {
MatcherAssert.assertThat(
inMemoryDownloadPath.toFile().length(), Matchers.greaterThan(0L));
MatcherAssert.assertThat(savedDownloadPath.toFile().length(), Matchers.greaterThan(0L));

List<RecordedEvent> inMemoryEvents = RecordingFile.readAllEvents(inMemoryDownloadPath);
List<RecordedEvent> savedEvents = RecordingFile.readAllEvents(savedDownloadPath);

MatcherAssert.assertThat(
inMemoryDownloadPath.toFile().length(),
Matchers.greaterThan(savedDownloadPath.toFile().length()));
inMemoryEvents.size(), Matchers.greaterThan(savedEvents.size()));

// verify that reports can be downloaded successfully and yield non-empty HTML documents
// (TODO: verify response body is a valid HTML document)
String reportUrl = recordingInfo.getString("reportUrl");
Path reportPath =
downloadFileAbs(reportUrl, TEST_RECORDING_NAME + "_report", ".html")
.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
MatcherAssert.assertThat(reportPath.toFile().length(), Matchers.greaterThan(0L));
File reportFile = reportPath.toFile();
MatcherAssert.assertThat(reportFile.length(), Matchers.greaterThan(0L));
Document doc = Jsoup.parse(reportFile, "UTF-8");

Elements head = doc.getElementsByTag("head");
Elements titles = head.first().getElementsByTag("title");
Elements body = doc.getElementsByTag("body");
Elements script = head.first().getElementsByTag("script");

MatcherAssert.assertThat("Expected one <head>", head.size(), Matchers.equalTo(1));
MatcherAssert.assertThat(titles.size(), Matchers.equalTo(1));
MatcherAssert.assertThat("Expected one <body>", body.size(), Matchers.equalTo(1));
MatcherAssert.assertThat(
"Expected at least one <script>",
script.size(),
Matchers.greaterThanOrEqualTo(1));

} finally {
// Clean up what we created
CompletableFuture<Void> deleteRespFuture = new CompletableFuture<>();
Expand Down