Skip to content

Commit

Permalink
#4 Support for boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarmorling committed Dec 28, 2021
1 parent d231087 commit c51333c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/org/moditect/jfranalytics/JfrSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.lang.System.Logger.Level;
import java.nio.file.Path;
import java.sql.Timestamp;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -108,6 +109,9 @@ private static RelDataType getRelDataType(EventType eventType, ValueDescriptor f
case "int":
type = typeFactory.createJavaType(int.class);
break;
case "boolean":
type = typeFactory.createJavaType(boolean.class);
break;
case "long":
if ("jdk.jfr.Timestamp".equals(field.getContentType())) {
type = typeFactory.createJavaType(Timestamp.class);
Expand Down Expand Up @@ -178,7 +182,12 @@ else if (recordedClassLoader.getName() != null) {

// 3. further special cases
else if (field.getAnnotation(Timespan.class) != null) {
return event -> event.getDuration(field.getName()).toNanos();
return event -> {
Duration duration = event.getDuration(field.getName());
// Long.MIN_VALUE is used as a sentinel value for absent values e.g. for jdk.GCConfiguration.pauseTarget
// TODO: handle nanos value overflow
return duration.getSeconds() == Long.MIN_VALUE ? Long.MIN_VALUE : duration.toNanos();
};
}

// 4. default pass-through
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/org/moditect/jfranalytics/JfrSchemaFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,33 @@ public void canRunSimpleSelectFromClassLoad() throws Exception {
}
}

@Test
public void canRunSimpleSelectFromGcConfiguration() throws Exception {
try (Connection connection = getConnection("gc-configuration.jfr")) {
PreparedStatement statement = connection.prepareStatement("""
SELECT *
FROM "jfr"."jdk.GCConfiguration"
""");

try (ResultSet rs = statement.executeQuery()) {
assertThat(rs.next()).isTrue();

assertThat(rs.getTimestamp(1)).isEqualTo(Timestamp.from(ZonedDateTime.parse("2021-12-28T16:13:32.114000000+01:00").toInstant()));
assertThat(rs.getString(2)).isEqualTo("G1New");
assertThat(rs.getString(3)).isEqualTo("G1Old");
assertThat(rs.getInt(4)).isEqualTo(10);
assertThat(rs.getInt(5)).isEqualTo(3);
assertThat(rs.getBoolean(6)).isTrue();
assertThat(rs.getBoolean(7)).isFalse();
assertThat(rs.getBoolean(8)).isFalse();
assertThat(rs.getLong(9)).isEqualTo(Long.MIN_VALUE);
assertThat(rs.getInt(10)).isEqualTo(12);

assertThat(rs.next()).isFalse();
}
}
}

@Test
public void canUseGetClassNameFunction() throws Exception {
try (Connection connection = getConnection("class-loading.jfr")) {
Expand Down
Binary file added src/test/resources/gc-configuration.jfr
Binary file not shown.

0 comments on commit c51333c

Please sign in to comment.