Skip to content
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void truncateTop() throws IOException {

// Truncate all available data
stream.truncateTop(3);
assertThat(stream.size()).isEqualTo(0);
assertThat(stream).isEmpty();
assertThat(readString(temporaryFile)).isEqualTo("");

stream.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import static io.opentelemetry.semconv.incubating.HostIncubatingAttributes.HOST_NAME;
import static io.opentelemetry.semconv.incubating.HostIncubatingAttributes.HOST_TYPE;
import static io.opentelemetry.semconv.incubating.K8sIncubatingAttributes.K8S_CLUSTER_NAME;
import static org.junit.jupiter.api.Assertions.fail;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.verify;

import com.google.cloud.opentelemetry.detection.DetectedPlatform;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

package io.opentelemetry.contrib.jfr.connection;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
Expand All @@ -33,32 +33,32 @@ void assertCommercialFeaturesUnlocked() throws Exception {

@Test
void assertCommercialFeaturesLockedThrows() throws Exception {
assertThrows(
JfrConnectionException.class,
() -> {
ObjectName objectName = mock(ObjectName.class);
MBeanServerConnection mBeanServerConnection = mockMbeanServer(objectName, "locked");
FlightRecorderDiagnosticCommandConnection.assertCommercialFeaturesUnlocked(
mBeanServerConnection, objectName);
});
assertThatThrownBy(
() -> {
ObjectName objectName = mock(ObjectName.class);
MBeanServerConnection mBeanServerConnection = mockMbeanServer(objectName, "locked");
FlightRecorderDiagnosticCommandConnection.assertCommercialFeaturesUnlocked(
mBeanServerConnection, objectName);
})
.isInstanceOf(JfrConnectionException.class);
}

@Test
void closeRecording() throws Exception {
assertThrows(UnsupportedOperationException.class, () -> createconnection().closeRecording(1));
assertThatThrownBy(() -> createconnection().closeRecording(1))
.isInstanceOf(UnsupportedOperationException.class);
}

@Test
void testGetStream() throws Exception {
assertThrows(
UnsupportedOperationException.class,
() -> createconnection().getStream(1L, null, null, 0L));
assertThatThrownBy(() -> createconnection().getStream(1L, null, null, 0L))
.isInstanceOf(UnsupportedOperationException.class);
}

@Test
void testCloneRecording() throws Exception {
assertThrows(
UnsupportedOperationException.class, () -> createconnection().cloneRecording(1, false));
assertThatThrownBy(() -> createconnection().cloneRecording(1, false))
.isInstanceOf(UnsupportedOperationException.class);
}

@Test
Expand All @@ -73,7 +73,7 @@ void startRecordingParsesIdCorrectly() throws Exception {
long id =
connection.startRecording(
new RecordingOptions.Builder().build(), RecordingConfiguration.PROFILE_CONFIGURATION);
assertEquals(id, 99);
assertThat(id).isEqualTo(99);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package io.opentelemetry.contrib.jfr.connection;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

import java.lang.management.ManagementFactory;
import java.util.HashMap;
Expand Down Expand Up @@ -49,6 +49,6 @@ void makeOpenData() throws Exception {
mBeanServerConnection.invoke(
objectInstance.getObjectName(), "getRecordingSettings", args, argTypes);

assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

package io.opentelemetry.contrib.jfr.connection;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.fail;

import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -44,18 +43,20 @@ void tearDown() {

@Test
void nullConfigThrows() {
assertThrows(IllegalArgumentException.class, () -> new JfcFileConfiguration(null));
assertThatThrownBy(() -> new JfcFileConfiguration(null))
.isInstanceOf(IllegalArgumentException.class);
}

@Test
void brokenJfcConfigFileThrowsError() {
assertThrows(RuntimeMBeanException.class, () -> executeRecording("brokenJfcFile.jfc"));
assertThatThrownBy(() -> executeRecording("brokenJfcFile.jfc"))
.isInstanceOf(RuntimeMBeanException.class);
}

@Test
void jfcFileFromInputStreamCanBeRead() {
IItemCollection recordingContent = executeRecording("sampleJfcFile.jfc");
assertTrue(containsEvent(recordingContent, "jdk.ThreadAllocationStatistics"));
assertThat(containsEvent(recordingContent, "jdk.ThreadAllocationStatistics")).isTrue();
}

@Test
Expand All @@ -68,9 +69,9 @@ void mapConfiguration() {
RecordingConfiguration recordingConfiguration = new MapConfiguration(recordingConfigAsMap);

IItemCollection recordingContent = excecuteRecordingWithConfig(recordingConfiguration);
assertNotNull(recordingContent, "excecuteRecordingWithConfig returned null");
assertTrue(containsEvent(recordingContent, "jdk.ObjectAllocationInNewTLAB"));
assertTrue(containsEvent(recordingContent, "jdk.ObjectAllocationOutsideTLAB"));
assertThat(recordingContent).isNotNull();
assertThat(containsEvent(recordingContent, "jdk.ObjectAllocationInNewTLAB")).isTrue();
assertThat(containsEvent(recordingContent, "jdk.ObjectAllocationOutsideTLAB")).isTrue();
}

private static boolean containsEvent(IItemCollection recordingContent, String eventName) {
Expand Down Expand Up @@ -110,7 +111,7 @@ private IItemCollection excecuteRecordingWithConfig(RecordingConfiguration confi
}
recording.stop();
recording.dump(dumpFile.toString());
assertTrue(Files.exists(dumpFile));
assertThat(Files.exists(dumpFile)).isTrue();

try {
return JfrLoaderToolkit.loadEvents(dumpFile.toFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

package io.opentelemetry.contrib.jfr.connection;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.google.errorprone.annotations.Keep;
import java.util.HashMap;
Expand All @@ -33,14 +33,14 @@ private static Stream<Arguments> testGetName() {
@MethodSource
void testGetName(String testValue, String expected) {
RecordingOptions opts = new RecordingOptions.Builder().name(testValue).build();
assertEquals(expected, opts.getName());
assertThat(opts.getName()).isEqualTo(expected);
}

@Test
void testGetNameDefault() {
String expected = "";
RecordingOptions opts = new RecordingOptions.Builder().build();
assertEquals(expected, opts.getName());
assertThat(opts.getName()).isEqualTo(expected);
}

@Keep
Expand All @@ -64,14 +64,14 @@ static Stream<Arguments> testGetMaxAge() {
@MethodSource
void testGetMaxAge(String testValue, String expected) {
RecordingOptions opts = new RecordingOptions.Builder().maxAge(testValue).build();
assertEquals(expected, opts.getMaxAge());
assertThat(opts.getMaxAge()).isEqualTo(expected);
}

@Test
void testGetMaxAgeDefault() {
String expected = "0";
RecordingOptions opts = new RecordingOptions.Builder().build();
assertEquals(expected, opts.getMaxAge());
assertThat(opts.getMaxAge()).isEqualTo(expected);
}

@Keep
Expand All @@ -91,9 +91,8 @@ private static Stream<Arguments> testGetMaxAgeNegative() {
@ParameterizedTest
@MethodSource
void testGetMaxAgeNegative(String badValue) {
assertThrows(
IllegalArgumentException.class,
() -> new RecordingOptions.Builder().maxAge(badValue).build());
assertThatThrownBy(() -> new RecordingOptions.Builder().maxAge(badValue).build())
.isInstanceOf(IllegalArgumentException.class);
}

@Keep
Expand All @@ -113,14 +112,14 @@ private static Stream<Arguments> testGetMaxSize() {
@MethodSource
void testGetMaxSize(String testValue, String expected) {
RecordingOptions opts = new RecordingOptions.Builder().maxSize(testValue).build();
assertEquals(expected, opts.getMaxSize());
assertThat(opts.getMaxSize()).isEqualTo(expected);
}

@Test
void testGetMaxSizeDefault() {
String expected = "0";
RecordingOptions opts = new RecordingOptions.Builder().build();
assertEquals(expected, opts.getMaxSize());
assertThat(opts.getMaxSize()).isEqualTo(expected);
}

@Keep
Expand All @@ -135,30 +134,29 @@ private static Stream<Arguments> testGetMaxSizeNegative() {
@ParameterizedTest
@MethodSource
void testGetMaxSizeNegative(String badValue) {
assertThrows(
IllegalArgumentException.class,
() -> new RecordingOptions.Builder().maxSize(badValue).build());
assertThatThrownBy(() -> new RecordingOptions.Builder().maxSize(badValue).build())
.isInstanceOf(IllegalArgumentException.class);
}

@Test
void testGetDumpOnExit() {
String expected = "true";
RecordingOptions opts = new RecordingOptions.Builder().dumpOnExit(expected).build();
assertEquals(expected, opts.getDumpOnExit());
assertThat(opts.getDumpOnExit()).isEqualTo(expected);
}

@Test
void testGetDumpOnExitDefault() {
String expected = "false";
RecordingOptions opts = new RecordingOptions.Builder().build();
assertEquals(expected, opts.getDumpOnExit());
assertThat(opts.getDumpOnExit()).isEqualTo(expected);
}

@Test
void testGetDumpOnExitBadValue() {
String expected = "false";
RecordingOptions opts = new RecordingOptions.Builder().dumpOnExit("BAD_VALUE").build();
assertEquals(expected, opts.getDumpOnExit());
assertThat(opts.getDumpOnExit()).isEqualTo(expected);
}

@Keep
Expand All @@ -175,35 +173,35 @@ private static Stream<Arguments> testGetDestination() {
@MethodSource
void testGetDestination(String testValue, String expected) {
RecordingOptions opts = new RecordingOptions.Builder().destination(testValue).build();
assertEquals(expected, opts.getDestination());
assertThat(opts.getDestination()).isEqualTo(expected);
}

@Test
void testGetDestinationDefault() {
String expected = "";
RecordingOptions opts = new RecordingOptions.Builder().build();
assertEquals(expected, opts.getDestination());
assertThat(opts.getDestination()).isEqualTo(expected);
}

@Test
void testGetDisk() {
String expected = "true";
RecordingOptions opts = new RecordingOptions.Builder().disk(expected).build();
assertEquals(expected, opts.getDisk());
assertThat(opts.getDisk()).isEqualTo(expected);
}

@Test
void testGetDiskDefault() {
String expected = "false";
RecordingOptions opts = new RecordingOptions.Builder().build();
assertEquals(expected, opts.getDisk());
assertThat(opts.getDisk()).isEqualTo(expected);
}

@Test
void testGetDiskBadValue() {
String expected = "false";
RecordingOptions opts = new RecordingOptions.Builder().disk("BAD_VALUE").build();
assertEquals(expected, opts.getDisk());
assertThat(opts.getDisk()).isEqualTo(expected);
}

@Keep
Expand All @@ -227,14 +225,14 @@ private static Stream<Arguments> testGetDuration() {
@MethodSource
void testGetDuration(String testValue, String expected) {
RecordingOptions opts = new RecordingOptions.Builder().duration(testValue).build();
assertEquals(expected, opts.getDuration());
assertThat(opts.getDuration()).isEqualTo(expected);
}

@Test
void testGetDurationDefault() {
String expected = "0";
RecordingOptions opts = new RecordingOptions.Builder().build();
assertEquals(expected, opts.getDuration());
assertThat(opts.getDuration()).isEqualTo(expected);
}

@Keep
Expand All @@ -254,9 +252,8 @@ private static Stream<Arguments> testGetDurationNegative() {
@ParameterizedTest
@MethodSource
void testGetDurationNegative(String badValue) {
assertThrows(
IllegalArgumentException.class,
() -> new RecordingOptions.Builder().duration(badValue).build());
assertThatThrownBy(() -> new RecordingOptions.Builder().duration(badValue).build())
.isInstanceOf(IllegalArgumentException.class);
}

@Test
Expand All @@ -279,7 +276,7 @@ void testGetRecordingOptions() {
.disk("true")
.duration("120 s")
.build();
assertEquals(expected, opts.getRecordingOptions());
assertThat(opts.getRecordingOptions()).isEqualTo(expected);
}

@Test
Expand All @@ -289,6 +286,6 @@ void testGetRecordingOptionsDefaults() {
// to insure consistent behaviour.
expected.put("disk", "false");
RecordingOptions opts = new RecordingOptions.Builder().build();
assertEquals(expected, opts.getRecordingOptions());
assertThat(opts.getRecordingOptions()).isEqualTo(expected);
}
}
Loading
Loading