16
16
package io .vertx .ext .web .client .tests ;
17
17
18
18
import io .netty .handler .codec .http .multipart .HttpPostRequestEncoder ;
19
- import io .vertx .core .Context ;
20
19
import io .vertx .core .Vertx ;
21
20
import io .vertx .core .buffer .Buffer ;
21
+ import io .vertx .core .internal .ContextInternal ;
22
+ import io .vertx .core .internal .VertxInternal ;
22
23
import io .vertx .ext .unit .Async ;
23
24
import io .vertx .ext .unit .TestContext ;
24
25
import io .vertx .ext .unit .junit .VertxUnitRunner ;
25
26
import io .vertx .ext .web .client .impl .MultipartFormUpload ;
26
27
import io .vertx .ext .web .multipart .MultipartForm ;
27
28
import io .vertx .test .core .TestUtils ;
28
- import org .junit .After ;
29
- import org .junit .Before ;
30
- import org .junit .ClassRule ;
31
- import org .junit .Test ;
29
+ import org .junit .*;
32
30
import org .junit .rules .TemporaryFolder ;
33
31
import org .junit .runner .RunWith ;
34
32
40
38
import java .util .concurrent .atomic .AtomicInteger ;
41
39
42
40
import static org .junit .Assert .assertEquals ;
41
+ import static org .junit .Assume .assumeTrue ;
43
42
44
43
@ RunWith (VertxUnitRunner .class )
45
44
public class MultipartFormUploadTest {
46
45
47
46
@ ClassRule
48
47
public static TemporaryFolder testFolder = new TemporaryFolder ();
49
48
50
- private Vertx vertx ;
49
+ private VertxInternal vertx ;
51
50
52
51
@ Before
53
52
public void setUp () throws Exception {
54
- vertx = Vertx .vertx ();
53
+ vertx = ( VertxInternal ) Vertx .vertx ();
55
54
}
56
55
57
56
@ After
@@ -63,7 +62,7 @@ public void tearDown(TestContext ctx) {
63
62
public void testSimpleAttribute (TestContext ctx ) throws Exception {
64
63
Async async = ctx .async ();
65
64
Buffer result = Buffer .buffer ();
66
- Context context = vertx .getOrCreateContext ();
65
+ ContextInternal context = vertx .getOrCreateContext ();
67
66
MultipartFormUpload upload = new MultipartFormUpload (context , MultipartForm .create ().attribute ("foo" , "bar" ), false , HttpPostRequestEncoder .EncoderMode .RFC1738 );
68
67
upload .endHandler (v -> {
69
68
assertEquals ("foo=bar" , result .toString ());
@@ -75,24 +74,45 @@ public void testSimpleAttribute(TestContext ctx) throws Exception {
75
74
}
76
75
77
76
@ Test
78
- public void testFileUpload (TestContext ctx ) throws Exception {
79
- testFileUpload (ctx , false );
77
+ public void testFileUploadEventLoopContext (TestContext ctx ) throws Exception {
78
+ testFileUpload (ctx , vertx . createEventLoopContext (), false );
80
79
}
81
80
82
81
@ Test
83
- public void testFileUploadPaused (TestContext ctx ) throws Exception {
84
- testFileUpload (ctx , true );
82
+ public void testFileUploadWorkerContext (TestContext ctx ) throws Exception {
83
+ testFileUpload (ctx , vertx . createWorkerContext (), false );
85
84
}
86
85
87
- private void testFileUpload (TestContext ctx , boolean paused ) throws Exception {
86
+ @ Test
87
+ public void testFileUploadVirtualThreadContext (TestContext ctx ) throws Exception {
88
+ assumeTrue (vertx .isVirtualThreadAvailable ());
89
+ testFileUpload (ctx , vertx .createVirtualThreadContext (), false );
90
+ }
91
+
92
+ @ Test
93
+ public void testFileUploadPausedEventLoopContext (TestContext ctx ) throws Exception {
94
+ testFileUpload (ctx , vertx .createEventLoopContext (), true );
95
+ }
96
+
97
+ @ Test
98
+ public void testFileUploadPausedWorkerContext (TestContext ctx ) throws Exception {
99
+ testFileUpload (ctx , vertx .createWorkerContext (), true );
100
+ }
101
+
102
+ @ Test
103
+ public void testFileUploadPausedVirtualThreadContext (TestContext ctx ) throws Exception {
104
+ assumeTrue (vertx .isVirtualThreadAvailable ());
105
+ testFileUpload (ctx , vertx .createVirtualThreadContext (), true );
106
+ }
107
+
108
+ private void testFileUpload (TestContext testContext , ContextInternal context , boolean paused ) throws Exception {
88
109
File file = testFolder .newFile ();
89
110
Files .write (file .toPath (), TestUtils .randomByteArray (32 * 1024 ));
90
111
91
112
String filename = file .getName ();
92
113
String pathname = file .getAbsolutePath ();
93
114
94
- Async async = ctx .async ();
95
- Context context = vertx .getOrCreateContext ();
115
+ Async async = testContext .async ();
96
116
context .runOnContext (v1 -> {
97
117
try {
98
118
MultipartFormUpload upload = new MultipartFormUpload (context , MultipartForm .create ().textFileUpload (
@@ -104,7 +124,7 @@ private void testFileUpload(TestContext ctx, boolean paused) throws Exception {
104
124
AtomicInteger end = new AtomicInteger ();
105
125
upload .endHandler (v2 -> {
106
126
assertEquals (0 , end .getAndIncrement ());
107
- ctx . assertTrue (buffers .size () > 0 );
127
+ testContext . assertFalse (buffers .isEmpty () );
108
128
async .complete ();
109
129
});
110
130
upload .handler (buffer -> {
@@ -119,7 +139,7 @@ private void testFileUpload(TestContext ctx, boolean paused) throws Exception {
119
139
context .runOnContext (v3 -> upload .resume ());
120
140
}
121
141
} catch (Exception e ) {
122
- ctx .fail (e );
142
+ testContext .fail (e );
123
143
throw new AssertionError (e );
124
144
}
125
145
});
0 commit comments