Skip to content

Commit

Permalink
svm: minor clean-ups for contributed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zapster committed May 2, 2024
1 parent b6e213a commit 2167780
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 39 deletions.
Expand Up @@ -26,15 +26,17 @@

package com.oracle.svm.test.jfr;

import com.oracle.svm.core.jfr.JfrEvent;
import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordedEvent;
import org.junit.Test;
import static org.junit.Assert.assertTrue;

import java.time.Duration;
import java.util.List;

import static org.junit.Assert.assertTrue;
import org.junit.Test;

import com.oracle.svm.core.jfr.JfrEvent;

import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordedEvent;

public class TestFlightRecorderEvents extends JfrRecordingTest {
private static final long THRESHOLD = 12345678;
Expand All @@ -55,12 +57,13 @@ private static void validateEvents(List<RecordedEvent> events) {
boolean foundActiveRecording = false;
boolean foundActiveSetting = false;
for (RecordedEvent e : events) {
if (e.getEventType().getName().equals("jdk.ActiveSetting") &&
String name = e.getEventType().getName();
if (name.equals("jdk.ActiveSetting") &&
e.getLong("id") == JfrEvent.ThreadPark.getId() &&
e.getString("name").equals("threshold") &&
e.getString("value").equals(THRESHOLD + " ns")) {
foundActiveSetting = true;
} else if (e.getEventType().getName().equals("jdk.ActiveRecording") &&
} else if (name.equals("jdk.ActiveRecording") &&
e.getLong("maxSize") == MAX_SIZE) {
foundActiveRecording = true;
}
Expand Down
Expand Up @@ -69,20 +69,21 @@ private static void validateEvents(List<RecordedEvent> events) {
boolean foundContainerMemoryUsage = false;
boolean foundContainerConfiguration = false;
for (RecordedEvent e : events) {
if (e.getEventType().getName().equals("jdk.ContainerCPUThrottling")) {
String name = e.getEventType().getName();
if (name.equals("jdk.ContainerCPUThrottling")) {
foundContainerCPUThrottling = true;
} else if (e.getEventType().getName().equals("jdk.ContainerCPUUsage") &&
} else if (name.equals("jdk.ContainerCPUUsage") &&
e.getLong("cpuTime") > 0 &&
e.getLong("cpuSystemTime") > 0 &&
e.getLong("cpuUserTime") > 0) {
foundContainerCPUUsage = true;
} else if (e.getEventType().getName().equals("jdk.ContainerIOUsage")) {
} else if (name.equals("jdk.ContainerIOUsage")) {
foundContainerIOUsage = true;
} else if (e.getEventType().getName().equals("jdk.ContainerMemoryUsage") &&
} else if (name.equals("jdk.ContainerMemoryUsage") &&
e.getLong("memoryUsage") > 0 &&
e.getLong("swapMemoryUsage") > 0) {
foundContainerMemoryUsage = true;
} else if (e.getEventType().getName().equals("jdk.ContainerConfiguration") &&
} else if (name.equals("jdk.ContainerConfiguration") &&
e.getLong("effectiveCpuCount") > 0) {
/*
* It's also worth checking hostTotalMemory and hostTotalSwapMemory are > 0 or -1
Expand Down
Expand Up @@ -28,19 +28,18 @@

import static org.junit.Assert.assertTrue;

import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordedEvent;
import org.junit.Test;

import java.io.IOException;

import java.net.InetSocketAddress;

import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.List;

import org.junit.Test;

import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordedEvent;

public class TestSocketChannelEvents extends JfrRecordingTest {
public static final String MESSAGE = "hello server";
public static final int DEFAULT_SIZE = 1024;
Expand Down Expand Up @@ -73,9 +72,11 @@ private static void validateEvents(List<RecordedEvent> events) {
boolean foundSocketRead = false;
boolean foundSocketWrite = false;
for (RecordedEvent e : events) {
if (e.getString("host").equals(HOST) && e.getEventType().getName().equals("jdk.SocketRead") && e.getLong("bytesRead") == MESSAGE.getBytes().length) {
String name = e.getEventType().getName();
String host = e.getString("host");
if (host.equals(HOST) && name.equals("jdk.SocketRead") && e.getLong("bytesRead") == MESSAGE.getBytes().length) {
foundSocketRead = true;
} else if (e.getString("host").equals(HOST) && e.getEventType().getName().equals("jdk.SocketWrite") && e.getLong("bytesWritten") == MESSAGE.getBytes().length &&
} else if (host.equals(HOST) && name.equals("jdk.SocketWrite") && e.getLong("bytesWritten") == MESSAGE.getBytes().length &&
e.getLong("port") == PORT) {
foundSocketWrite = true;
}
Expand All @@ -88,12 +89,14 @@ static class GreetClient {
SocketChannel socketChannel;

public void startConnection(String ip, int port) throws InterruptedException {
try {
socketChannel = SocketChannel.open(new InetSocketAddress(ip, port));
} catch (Exception e) {
// Keep trying until server begins accepting connections.
Thread.sleep(100);
startConnection(ip, port);
while (true) {
try {
socketChannel = SocketChannel.open(new InetSocketAddress(ip, port));
break;
} catch (Exception e) {
// Keep trying until server begins accepting connections.
Thread.sleep(100);
}
}
}

Expand Down
Expand Up @@ -26,9 +26,7 @@

package com.oracle.svm.test.jfr;

import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordedEvent;
import org.junit.Test;
import static org.junit.Assert.assertTrue;

import java.io.BufferedReader;
import java.io.IOException;
Expand All @@ -38,11 +36,13 @@
import java.net.Socket;
import java.util.List;

import static org.junit.Assert.assertTrue;
import org.junit.Test;

import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordedEvent;

public class TestSocketEvents extends JfrRecordingTest {
public static final String MESSAGE = "hello server";
public static final int DEFAULT_SIZE = 1024;
public static int PORT = 9876;
public static String HOST = "127.0.0.1";

Expand Down Expand Up @@ -74,9 +74,11 @@ private static void validateEvents(List<RecordedEvent> events) {
boolean foundSocketRead = false;
boolean foundSocketWrite = false;
for (RecordedEvent e : events) {
if (e.getString("host").equals(HOST) && e.getEventType().getName().equals("jdk.SocketRead") && e.getLong("bytesRead") == MESSAGE.getBytes().length) {
String name = e.getEventType().getName();
String host = e.getString("host");
if (host.equals(HOST) && name.equals("jdk.SocketRead") && e.getLong("bytesRead") == MESSAGE.getBytes().length) {
foundSocketRead = true;
} else if (e.getString("host").equals(HOST) && e.getEventType().getName().equals("jdk.SocketWrite") && e.getLong("bytesWritten") == MESSAGE.getBytes().length &&
} else if (host.equals(HOST) && name.equals("jdk.SocketWrite") && e.getLong("bytesWritten") == MESSAGE.getBytes().length &&
e.getLong("port") == PORT) {
foundSocketWrite = true;
}
Expand All @@ -90,12 +92,14 @@ static class GreetClient {
private PrintWriter out;

public void startConnection(String ip, int port) throws IOException, InterruptedException {
try {
clientSocket = new Socket(ip, port);
} catch (Exception e) {
// Keep trying until server begins accepting connections.
Thread.sleep(100);
startConnection(ip, port);
while (true) {
try {
clientSocket = new Socket(ip, port);
break;
} catch (Exception e) {
// Keep trying until server begins accepting connections.
Thread.sleep(100);
}
}
out = new PrintWriter(clientSocket.getOutputStream(), true);
}
Expand Down

0 comments on commit 2167780

Please sign in to comment.