Skip to content
Closed
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 @@ -109,6 +109,8 @@ public class TestPauseNotifications {

static final long HEAP_MB = 128; // adjust for test configuration above
static final long TARGET_MB = Long.getLong("target", 2_000); // 2 Gb allocation
static final long STEP_MS = 1000;
static final int SIZE = 100_000;

static volatile Object sink;

Expand Down Expand Up @@ -160,24 +162,21 @@ public void handleNotification(Notification n, Object o) {
((NotificationEmitter) bean).addNotificationListener(listener, null, null);
}

final int size = 100_000;
long count = TARGET_MB * 1024 * 1024 / (16 + 4 * size);

final long count = TARGET_MB * 1024 * 1024 / (16 + 4 * SIZE);
for (int c = 0; c < count; c++) {
sink = new int[size];
sink = new int[SIZE];
}

// Look at test timeout to figure out how long we can wait without breaking into timeout.
// Default to 1/4 of the remaining time in 1s steps.
final long STEP_MS = 1000;
long spentTimeNanos = System.nanoTime() - startTimeNanos;
long maxTries = (Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT) - (spentTimeNanos / 1_000_000L)) / STEP_MS / 4;
final long spentTimeNanos = System.nanoTime() - startTimeNanos;
final long maxTries = (Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT) - (spentTimeNanos / 1_000_000L)) / STEP_MS / 4;

long actualPauses = 0;
long actualCycles = 0;

// Wait until enough notifications are accrued to match minimum boundary.
long minExpected = 10;
final long minExpected = 10;

long tries = 0;
while (tries++ < maxTries) {
Expand All @@ -186,13 +185,20 @@ public void handleNotification(Notification n, Object o) {
if (minExpected <= actualPauses && minExpected <= actualCycles) {
// Wait a little bit to catch the lingering notifications.
Thread.sleep(5000);
actualPauses = pausesCount.get();
actualCycles = cyclesCount.get();
break;
}
Thread.sleep(STEP_MS);
}

for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
((NotificationEmitter) bean).removeNotificationListener(listener);
}

actualPauses = pausesCount.get();
actualCycles = cyclesCount.get();
long actualPauseDuration = pausesDuration.get();
long actualCycleDuration = cyclesDuration.get();

{
String msg = "Pauses expected = [" + minExpected + "; +inf], actual = " + actualPauses;
if (minExpected <= actualPauses) {
Expand All @@ -212,11 +218,7 @@ public void handleNotification(Notification n, Object o) {
}

{
long actualPauseDuration = pausesDuration.get();
long actualCycleDuration = cyclesDuration.get();

String msg = "Pauses duration (" + actualPauseDuration + ") is expected to be not larger than cycles duration (" + actualCycleDuration + ")";

if (actualPauseDuration <= actualCycleDuration) {
System.out.println(msg);
} else {
Expand Down