1
1
package io .apicurio .registry .events ;
2
2
3
- import static org .junit .jupiter .api .Assertions .assertLinesMatch ;
4
-
5
- import java .io .InputStream ;
6
- import java .util .Arrays ;
7
- import java .util .List ;
8
- import java .util .concurrent .CopyOnWriteArrayList ;
9
- import java .util .concurrent .TimeUnit ;
10
- import java .util .concurrent .TimeoutException ;
11
-
12
- import org .junit .jupiter .api .Assertions ;
13
- import org .junit .jupiter .api .Test ;
14
- import org .junit .jupiter .api .Timeout ;
15
- import org .junit .jupiter .api .Disabled ;
16
-
17
3
import io .apicurio .registry .AbstractResourceTestBase ;
18
4
import io .apicurio .registry .events .dto .RegistryEventType ;
19
5
import io .apicurio .registry .types .ArtifactType ;
20
6
import io .apicurio .registry .utils .IoUtil ;
7
+ import io .apicurio .registry .utils .tests .ApicurioTestTags ;
21
8
import io .apicurio .registry .utils .tests .TestUtils ;
22
9
import io .quarkus .test .junit .QuarkusTest ;
23
10
import io .quarkus .test .junit .TestProfile ;
24
11
import io .vertx .core .Vertx ;
25
12
import io .vertx .core .http .HttpServer ;
26
13
import io .vertx .core .http .HttpServerOptions ;
14
+ import org .junit .jupiter .api .Assertions ;
15
+ import org .junit .jupiter .api .Tag ;
16
+ import org .junit .jupiter .api .Test ;
17
+ import org .junit .jupiter .api .Timeout ;
18
+
19
+ import java .io .InputStream ;
20
+ import java .time .Duration ;
21
+ import java .util .Arrays ;
22
+ import java .util .List ;
23
+ import java .util .concurrent .CompletableFuture ;
24
+ import java .util .concurrent .CopyOnWriteArrayList ;
25
+ import java .util .concurrent .TimeUnit ;
26
+ import java .util .concurrent .TimeoutException ;
27
+
28
+ import static org .junit .jupiter .api .Assertions .assertLinesMatch ;
27
29
28
30
@ QuarkusTest
29
31
@ TestProfile (HttpEventsProfile .class )
30
- @ Disabled
32
+ @ Tag ( ApicurioTestTags . SLOW )
31
33
public class HttpEventsTest extends AbstractResourceTestBase {
32
34
33
35
@ Test
34
36
@ Timeout (value = 65 , unit = TimeUnit .SECONDS )
35
37
public void testHttpEvents () throws TimeoutException {
36
38
37
- HttpServer server = null ;
38
- try {
39
- List <String > events = new CopyOnWriteArrayList <>();
40
- server = Vertx .vertx ().createHttpServer (new HttpServerOptions ().setPort (8888 ))
41
- .requestHandler (req -> {
42
- events .add (req .headers ().get ("ce-type" ));
43
- req .response ().setStatusCode (200 ).end ();
44
- }).listen (ar -> {
45
- if (ar .succeeded ()) {
39
+ CompletableFuture <HttpServer > serverFuture = new CompletableFuture <>();
40
+ List <String > events = new CopyOnWriteArrayList <>();
46
41
47
- InputStream jsonSchema = getClass ().getResourceAsStream ("/io/apicurio/registry/util/json-schema.json" );
48
- Assertions .assertNotNull (jsonSchema );
49
- String content = IoUtil .toString (jsonSchema );
42
+ HttpServer server = Vertx .vertx ().createHttpServer (new HttpServerOptions ()
43
+ .setPort (8976 ))
44
+ .requestHandler (req -> {
45
+ events .add (req .headers ().get ("ce-type" ));
46
+ req .response ().setStatusCode (200 ).end ();
47
+ })
48
+ .listen (createdServer -> {
49
+ if (createdServer .succeeded ()) {
50
+ serverFuture .complete (createdServer .result ());
51
+ } else {
52
+ serverFuture .completeExceptionally (createdServer .cause ());
53
+ }
54
+ });
50
55
51
- String artifactId = TestUtils . generateArtifactId ( );
56
+ TestUtils . waitFor ( "proxy is ready" , Duration . ofSeconds ( 1 ). toMillis (), Duration . ofSeconds ( 30 ). toMillis (), serverFuture :: isDone );
52
57
53
- try {
54
- createArtifact (artifactId , ArtifactType .JSON , content );
55
- createArtifactVersion (artifactId , ArtifactType .JSON , content );
56
- } catch ( Exception e ) {
57
- Assertions .fail (e );
58
- }
58
+ try {
59
+ InputStream jsonSchema = getClass ().getResourceAsStream ("/io/apicurio/registry/util/json-schema.json" );
60
+ Assertions .assertNotNull (jsonSchema );
61
+ String content = IoUtil .toString (jsonSchema );
59
62
60
- } else {
61
- Assertions .fail (ar .cause ());
62
- }
63
- });
63
+ String artifactId = TestUtils .generateArtifactId ();
64
64
65
- TestUtils .waitFor ("Events to be produced" , 200 , 60 * 1000 , () -> {
66
- return events .size () == 2 ;
67
- });
65
+ try {
66
+ createArtifact (artifactId , ArtifactType .JSON , content );
67
+ createArtifactVersion (artifactId , ArtifactType .JSON , content );
68
+ } catch (Exception e ) {
69
+ Assertions .fail (e );
70
+ }
71
+
72
+ TestUtils .waitFor ("Events to be produced" , 200 , 60 * 1000 , () -> events .size () == 2 );
68
73
69
74
assertLinesMatch (
70
75
Arrays .asList (RegistryEventType .ARTIFACT_CREATED .cloudEventType (), RegistryEventType .ARTIFACT_UPDATED .cloudEventType ()),
@@ -74,7 +79,5 @@ public void testHttpEvents() throws TimeoutException {
74
79
server .close ();
75
80
}
76
81
}
77
-
78
82
}
79
-
80
83
}
0 commit comments