-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathVertxTest.java
115 lines (100 loc) · 4.53 KB
/
VertxTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package resilience.vertx;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import com.arangodb.ArangoDB;
import com.arangodb.PackageVersion;
import com.arangodb.http.HttpConnection;
import com.arangodb.http.HttpProtocolConfig;
import io.vertx.core.Vertx;
import org.junit.jupiter.api.Test;
import resilience.SingleServerTest;
import java.util.Collections;
import java.util.concurrent.ExecutionException;
import static org.assertj.core.api.Assertions.assertThat;
public class VertxTest extends SingleServerTest {
public VertxTest() {
super(Collections.singletonMap(HttpConnection.class, Level.DEBUG));
}
@Test
void managedVertx() {
ArangoDB adb = new ArangoDB.Builder()
.host("172.28.0.1", 8529)
.password("test")
.build();
adb.getVersion();
adb.shutdown();
assertThat(logs.getLogs())
.filteredOn(it -> it.getLoggerName().equals("com.arangodb.http.HttpConnection"))
.filteredOn(it -> it.getLevel().equals(Level.DEBUG))
.map(ILoggingEvent::getFormattedMessage)
.anySatisfy(it -> assertThat(it).contains("Creating new Vert.x instance"))
.anySatisfy(it -> assertThat(it).contains("Closing Vert.x instance"));
}
@Test
void reuseVertx() {
Vertx vertx = Vertx.vertx();
ArangoDB adb = new ArangoDB.Builder()
.host("172.28.0.1", 8529)
.password("test")
.protocolConfig(HttpProtocolConfig.builder().vertx(vertx).build())
.build();
adb.getVersion();
adb.shutdown();
vertx.close();
assertThat(logs.getLogs())
.filteredOn(it -> it.getLoggerName().equals("com.arangodb.http.HttpConnection"))
.filteredOn(it -> it.getLevel().equals(Level.DEBUG))
.map(ILoggingEvent::getFormattedMessage)
.anySatisfy(it -> assertThat(it).contains("Reusing existing Vert.x instance"));
}
@Test
void reuseVertxFromVertxThread() throws ExecutionException, InterruptedException {
Vertx vertx = Vertx.vertx();
vertx.executeBlocking(() -> {
ArangoDB adb = new ArangoDB.Builder()
.host("172.28.0.1", 8529)
.password("test")
.protocolConfig(HttpProtocolConfig.builder().vertx(Vertx.currentContext().owner()).build())
.build();
adb.getVersion();
adb.shutdown();
return null;
}).toCompletionStage().toCompletableFuture().get();
vertx.close();
assertThat(logs.getLogs())
.filteredOn(it -> it.getLoggerName().equals("com.arangodb.http.HttpConnection"))
.filteredOn(it -> it.getLevel().equals(Level.DEBUG))
.map(ILoggingEvent::getFormattedMessage)
.anySatisfy(it -> assertThat(it).contains("Reusing existing Vert.x instance"));
}
@Test
void existingVertxNotUsed() throws ExecutionException, InterruptedException {
Vertx vertx = Vertx.vertx();
vertx.executeBlocking(() -> {
ArangoDB adb = new ArangoDB.Builder()
.host("172.28.0.1", 8529)
.password("test")
.build();
adb.getVersion();
adb.shutdown();
return null;
}).toCompletionStage().toCompletableFuture().get();
vertx.close();
if (!PackageVersion.SHADED) {
assertThat(logs.getLogs())
.filteredOn(it -> it.getLoggerName().equals("com.arangodb.http.HttpConnectionFactory"))
.filteredOn(it -> it.getLevel().equals(Level.WARN))
.map(ILoggingEvent::getFormattedMessage)
.anySatisfy(it -> assertThat(it)
.contains("Found an existing Vert.x instance, you can reuse it by setting:")
.contains(".protocolConfig(HttpProtocolConfig.builder().vertx(Vertx.currentContext().owner()).build())")
);
}
assertThat(logs.getLogs())
.filteredOn(it -> it.getLoggerName().equals("com.arangodb.http.HttpConnection"))
.filteredOn(it -> it.getLevel().equals(Level.DEBUG))
.map(ILoggingEvent::getFormattedMessage)
.anySatisfy(it -> assertThat(it).contains("Creating new Vert.x instance"))
.anySatisfy(it -> assertThat(it).contains("Closing Vert.x instance"));
}
}