11package com .inqwise .async .compliance ;
22
3+ import static org .junit .jupiter .api .Assertions .assertEquals ;
4+ import static org .junit .jupiter .api .Assertions .assertFalse ;
5+ import static org .junit .jupiter .api .Assertions .assertTrue ;
6+
7+ import java .io .ByteArrayInputStream ;
8+ import java .io .ByteArrayOutputStream ;
9+ import java .io .IOException ;
10+ import java .io .InputStream ;
11+ import java .util .concurrent .CompletableFuture ;
12+ import java .util .concurrent .atomic .AtomicBoolean ;
13+ import java .util .concurrent .atomic .AtomicInteger ;
14+
15+ import org .apache .logging .log4j .LogManager ;
16+ import org .apache .logging .log4j .Logger ;
17+ import org .junit .jupiter .api .AfterEach ;
18+ import org .junit .jupiter .api .BeforeEach ;
19+ import org .junit .jupiter .api .Test ;
20+ import org .junit .jupiter .api .extension .ExtendWith ;
21+ import org .junit .jupiter .api .extension .RegisterExtension ;
22+
323import com .inqwise .async .stream .AsyncInputStream ;
4- import com .inqwise .async .stream .AsyncOutputStream ;
524import com .inqwise .async .stream .AsyncReadStream ;
625import com .inqwise .async .stream .AsyncWriteStream ;
26+
727import io .vertx .core .Handler ;
828import io .vertx .core .Vertx ;
929import io .vertx .core .buffer .Buffer ;
1030import io .vertx .core .streams .ReadStream ;
11- import io .vertx .core . streams . WriteStream ;
31+ import io .vertx .junit5 . RunTestOnContext ;
1232import io .vertx .junit5 .Timeout ;
1333import io .vertx .junit5 .VertxExtension ;
1434import io .vertx .junit5 .VertxTestContext ;
15- import org .junit .jupiter .api .Test ;
16- import org .junit .jupiter .api .extension .ExtendWith ;
17-
18- import java .io .*;
19- import java .util .concurrent .CompletableFuture ;
20- import java .util .concurrent .TimeUnit ;
21- import java .util .concurrent .atomic .AtomicBoolean ;
22- import java .util .concurrent .atomic .AtomicInteger ;
23-
24- import static org .junit .jupiter .api .Assertions .*;
2535
2636/**
2737 * RFC Compliance tests for Inqwise Async library.
3141@ ExtendWith (VertxExtension .class )
3242@ Timeout (10000 )
3343public class RFCComplianceTest {
34-
44+ private static final Logger logger = LogManager .getLogger (RFCComplianceTest .class );
45+
46+ @ RegisterExtension
47+ RunTestOnContext rtoc = new RunTestOnContext ();
48+ Vertx vertx ;
49+
50+ @ BeforeEach
51+ void prepare (VertxTestContext testContext ) {
52+ vertx = rtoc .vertx ();
53+ // Prepare something on a Vert.x event-loop thread
54+ // The thread changes with each test instance
55+ testContext .completeNow ();
56+ }
57+
58+ @ AfterEach
59+ void cleanUp (VertxTestContext testContext ) {
60+ // Clean things up on the same Vert.x event-loop thread
61+ // that called prepare and foo
62+ testContext .completeNow ();
63+ }
64+
3565 /**
3666 * RFC-001: Verify that blocking I/O operations do not block the Vert.x event loop
3767 */
3868 @ Test
39- public void testNonBlockingEventLoopCompliance (Vertx vertx , VertxTestContext testContext ) throws Exception {
69+ public void testNonBlockingEventLoopCompliance (VertxTestContext testContext ) throws Exception {
4070 String testData = "Event loop should not be blocked" ;
4171 ByteArrayInputStream inputStream = new ByteArrayInputStream (testData .getBytes ());
4272
@@ -45,7 +75,7 @@ public void testNonBlockingEventLoopCompliance(Vertx vertx, VertxTestContext tes
4575 AtomicInteger dataReceived = new AtomicInteger (0 );
4676
4777 // Schedule a task to run on the event loop while reading
48- vertx .setTimer (50 , id -> {
78+ vertx .setTimer (100 , id -> {
4979 if (Thread .currentThread ().getName ().contains ("eventloop" )) {
5080 eventLoopBlocked .set (false ); // Event loop is responsive
5181 }
@@ -54,6 +84,7 @@ public void testNonBlockingEventLoopCompliance(Vertx vertx, VertxTestContext tes
5484 asyncReadStream
5585 .exceptionHandler (testContext ::failNow )
5686 .handler (buffer -> {
87+ logger .debug ("handler" );
5788 dataReceived .addAndGet (buffer .length ());
5889 // Verify we're on the event loop thread
5990 assertTrue (Thread .currentThread ().getName ().contains ("eventloop" ),
@@ -70,7 +101,7 @@ public void testNonBlockingEventLoopCompliance(Vertx vertx, VertxTestContext tes
70101 * RFC-002: Verify proper resource cleanup and lifecycle management
71102 */
72103 @ Test
73- public void testResourceLifecycleCompliance (Vertx vertx , VertxTestContext testContext ) throws Exception {
104+ public void testResourceLifecycleCompliance (VertxTestContext testContext ) throws Exception {
74105 ByteArrayOutputStream outputStream = new ByteArrayOutputStream ();
75106 AsyncWriteStream asyncWriteStream = new AsyncWriteStream (vertx , outputStream );
76107
@@ -100,7 +131,7 @@ public void testResourceLifecycleCompliance(Vertx vertx, VertxTestContext testCo
100131 * RFC-003: Verify back-pressure handling in AsyncInputStream
101132 */
102133 @ Test
103- public void testBackPressureCompliance (Vertx vertx , VertxTestContext testContext ) throws Exception {
134+ public void testBackPressureCompliance (VertxTestContext testContext ) throws Exception {
104135 // Create a large buffer to trigger back-pressure
105136 byte [] largeData = new byte [64 * 1024 ]; // 64KB
106137 for (int i = 0 ; i < largeData .length ; i ++) {
@@ -195,7 +226,7 @@ private void end() {
195226 * RFC-004: Verify thread safety of stream operations
196227 */
197228 @ Test
198- public void testThreadSafetyCompliance (Vertx vertx , VertxTestContext testContext ) throws Exception {
229+ public void testThreadSafetyCompliance (VertxTestContext testContext ) throws Exception {
199230 ByteArrayOutputStream outputStream = new ByteArrayOutputStream ();
200231 AsyncWriteStream asyncWriteStream = new AsyncWriteStream (vertx , outputStream );
201232
@@ -240,7 +271,7 @@ public void testThreadSafetyCompliance(Vertx vertx, VertxTestContext testContext
240271 * RFC-005: Verify proper exception propagation and error handling
241272 */
242273 @ Test
243- public void testExceptionPropagationCompliance (Vertx vertx , VertxTestContext testContext ) {
274+ public void testExceptionPropagationCompliance (VertxTestContext testContext ) {
244275 InputStream faultyStream = new InputStream () {
245276 private boolean firstCall = true ;
246277
@@ -275,7 +306,7 @@ public int read() throws IOException {
275306 * RFC-006: Verify compliance with stream pause/resume semantics
276307 */
277308 @ Test
278- public void testStreamControlCompliance (Vertx vertx , VertxTestContext testContext ) throws Exception {
309+ public void testStreamControlCompliance (VertxTestContext testContext ) throws Exception {
279310 String testData = "Pause and resume test data that is longer than usual" ;
280311 ByteArrayInputStream inputStream = new ByteArrayInputStream (testData .getBytes ());
281312
0 commit comments