8378878: Refactor java/nio/channels/AsynchronousSocketChannel test to use JUnit

Reviewed-by: alanb
This commit is contained in:
Brian Burkhalter 2026-03-04 18:50:13 +00:00
parent 0fbf58d8ff
commit c52d7b7cbc

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/* @test
* @bug 8202252
* @run testng CompletionHandlerRelease
* @run junit CompletionHandlerRelease
* @summary Verify that reference to CompletionHandler is cleared after use
*/
@ -44,10 +44,12 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
public class CompletionHandlerRelease {
@Test
@ -132,16 +134,16 @@ public class CompletionHandlerRelease {
}
}
private AsynchronousChannelGroup GROUP;
private static AsynchronousChannelGroup GROUP;
@BeforeTest
void setup() throws IOException {
@BeforeAll
static void setup() throws IOException {
GROUP = AsynchronousChannelGroup.withFixedThreadPool(2,
Executors.defaultThreadFactory());
}
@AfterTest
void cleanup() throws IOException {
@AfterAll
static void cleanup() throws IOException {
GROUP.shutdownNow();
}
@ -199,13 +201,13 @@ public class CompletionHandlerRelease {
}
}
private void waitForRefToClear(Reference ref, ReferenceQueue queue)
private static void waitForRefToClear(Reference ref, ReferenceQueue queue)
throws InterruptedException {
Reference r;
while ((r = queue.remove(20)) == null) {
System.gc();
}
assertEquals(r, ref);
assertSame(ref, r);
assertNull(r.get());
}
}